zulip_bots: Use package_data instead of MANIFEST.in.

This commit removes generate_manifest.py and package data files
are now included using the package_data kwarg to setup().

This is because, in certain situations, MANIFEST.in is a bit
finicky. For instance installing a package using:

python setup.py install

doesn't include files specified in MANIFEST.in, while using

pip install ./zulip_bots

does. package_data doesn't pose this problem, ergo it's better
for us.
This commit is contained in:
Eeshan Garg 2018-01-08 18:16:10 -03:30
parent 2366b22405
commit e20b754498
5 changed files with 8 additions and 156 deletions

View file

@ -11,8 +11,6 @@ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
ZULIP_BOTS_DIR = os.path.join(CURRENT_DIR, '..', 'zulip_bots') ZULIP_BOTS_DIR = os.path.join(CURRENT_DIR, '..', 'zulip_bots')
sys.path.append(ZULIP_BOTS_DIR) sys.path.append(ZULIP_BOTS_DIR)
import generate_manifest
red = '\033[91m' red = '\033[91m'
green = '\033[92m' green = '\033[92m'
end_format = '\033[0m' end_format = '\033[0m'

View file

@ -235,10 +235,6 @@ def main():
for setup_file in setup_py_files: for setup_file in setup_py_files:
package_name = os.path.basename(os.path.dirname(setup_file)) package_name = os.path.basename(os.path.dirname(setup_file))
if package_name == 'zulip_bots':
setuptools.sandbox.run_setup(
setup_file, ['gen_manifest', '--release']
)
generate_sdist(setup_file, package_name) generate_sdist(setup_file, package_name)
generate_bdist_wheel_universal(setup_file, package_name) generate_bdist_wheel_universal(setup_file, package_name)

View file

@ -21,6 +21,5 @@ zulip_bots # This directory
│ ├───test_lib.py # Backbone for bot unit tests. │ ├───test_lib.py # Backbone for bot unit tests.
│ ├───test_run.py # Unit tests for run.py │ ├───test_run.py # Unit tests for run.py
│ └───terminal.py # Used to test bots in the command line. │ └───terminal.py # Used to test bots in the command line.
├───generate_manifest.py # Helper-script for packaging.
└───setup.py # Script for packaging. └───setup.py # Script for packaging.
``` ```

View file

@ -1,143 +0,0 @@
#!/usr/bin/env python3
import argparse
import os
import glob
import distutils.cmd
import distutils.log
if False:
from typing import IO, Iterator
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
BOTS_DIR = os.path.normpath(os.path.join(CURRENT_DIR, 'zulip_bots', 'bots'))
MANIFEST_PATH = os.path.join(CURRENT_DIR, 'MANIFEST.in')
class GenerateManifest(distutils.cmd.Command):
"""
A custom setup.py command to generate a MANIFEST.in
for the zulip_bots package.
"""
description = 'generate a MANIFEST.in for PyPA or for development'
user_options = [
('release', None, 'generate a MANIFEST for a PyPA release'),
]
def initialize_options(self):
# type: () -> None
self.release = False
def finalize_options(self):
# type: () -> None
pass
def run(self):
# type: () -> None
if self.release:
generate_release_manifest()
self.announce('Generating a MANIFEST for a PyPA release of zulip_bots.',
level=distutils.log.INFO)
else:
generate_dev_manifest()
self.announce('Generating a MANIFEST for zulip_bots\' development.',
level=distutils.log.INFO)
def get_test_fixtures():
# type: () -> Iterator[str]
glob_pattern = os.path.join(BOTS_DIR, '*', 'fixtures', '*.json')
fixtures_paths = map(
lambda fp: os.path.join(*fp.split(os.path.sep)[-5:]).replace(os.path.sep, '/'),
glob.glob(glob_pattern)
)
return fixtures_paths
def get_logos():
# type: () -> Iterator[str]
glob_pattern = os.path.join(BOTS_DIR, '*', 'logo.*')
logo_paths = map(
lambda fp: os.path.join(*fp.split(os.path.sep)[-4:]).replace(os.path.sep, '/'),
glob.glob(glob_pattern)
)
return logo_paths
def get_docs():
# type: () -> Iterator[str]
glob_pattern = os.path.join(BOTS_DIR, '*', 'doc.md')
doc_paths = map(
lambda fp: os.path.join(*fp.split(os.path.sep)[-4:]).replace(os.path.sep, '/'),
glob.glob(glob_pattern)
)
return doc_paths
def get_assets():
# type: () -> Iterator[str]
glob_pattern = os.path.join(BOTS_DIR, '*', 'assets', '*')
assets_files = map(
lambda fp: os.path.join(*fp.split(os.path.sep)[-5:]).replace(os.path.sep, '/'),
glob.glob(glob_pattern)
)
return assets_files
def get_config_templates():
# type: () -> Iterator[str]
glob_pattern = os.path.join(BOTS_DIR, '*', '*.conf',)
assets_files = map(
lambda fp: os.path.join(*fp.split(os.path.sep)[-4:]).replace(os.path.sep, '/'),
glob.glob(glob_pattern)
)
return assets_files
def generate_and_write(filepaths, file_obj):
# type: (Iterator[str], IO[str]) -> None
template = 'include {line}\n'
lines = map(lambda line: template.format(line=line), filepaths)
file_obj.writelines(lines)
file_obj.write('\n')
def generate_dev_manifest():
# type: () -> None
with open(MANIFEST_PATH, 'w') as fp:
generate_and_write(get_test_fixtures(), fp)
generate_and_write(get_logos(), fp)
generate_and_write(get_docs(), fp)
generate_and_write(get_assets(), fp)
generate_and_write(get_config_templates(), fp)
def generate_release_manifest():
# type: () -> None
with open(MANIFEST_PATH, 'w') as fp:
generate_and_write(get_docs(), fp)
generate_and_write(get_assets(), fp)
generate_and_write(get_config_templates(), fp)
def parse_args():
# type: () -> argparse.Namespace
usage = """
To generate a MANIFEST.in for a PyPA release, run:
./generate_manifest.py --release
To generate a MANIFEST.in for development, run without arguments:
./generate_manifest.py
"""
parser = argparse.ArgumentParser(usage=usage)
parser.add_argument('--release', '-r',
action='store_true',
default=False,
help='Generate MANIFEST.in for a PyPA release.')
return parser.parse_args()
def main():
# type: () -> None
options = parse_args()
if options.release:
generate_release_manifest()
else:
generate_dev_manifest()
if __name__ == '__main__':
main()

14
zulip_bots/setup.py Normal file → Executable file
View file

@ -10,15 +10,19 @@ import pip
if False: if False:
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
import generate_manifest
ZULIP_BOTS_VERSION = "0.4.0" ZULIP_BOTS_VERSION = "0.4.0"
IS_PYPA_PACKAGE = False IS_PYPA_PACKAGE = False
package_data = {
'': ['doc.md', '*.conf', 'assets/*']
}
# IS_PYPA_PACKAGE is set to True by tools/release-packages # IS_PYPA_PACKAGE is set to True by tools/release-packages
# before making a PyPA release. # before making a PyPA release.
if not IS_PYPA_PACKAGE: if not IS_PYPA_PACKAGE:
generate_manifest.generate_dev_manifest() package_data[''].append('fixtures/*.json')
package_data[''].append('logo.*')
# We should be installable with either setuptools or distutils. # We should be installable with either setuptools or distutils.
package_info = dict( package_info = dict(
@ -42,9 +46,6 @@ package_info = dict(
], ],
}, },
include_package_data=True, include_package_data=True,
cmdclass={
'gen_manifest': generate_manifest.GenerateManifest,
},
) # type: Dict[str, Any] ) # type: Dict[str, Any]
setuptools_info = dict( setuptools_info = dict(
@ -58,6 +59,7 @@ try:
from setuptools import setup, find_packages from setuptools import setup, find_packages
package_info.update(setuptools_info) package_info.update(setuptools_info)
package_info['packages'] = find_packages() package_info['packages'] = find_packages()
package_info['package_data'] = package_data
except ImportError: except ImportError:
from distutils.core import setup from distutils.core import setup