python-zulip-api/tools/generate_zulip_bots_manifest.py
Eeshan Garg a28fcbbaa9 zulip_bots: Add script to generate zulip_bots/MANIFEST.in.
As a package maintainer, I have to exclude the test fixtures in
MANIFEST.in so that they aren't shipped with the package release.
But for the repo, we need to include fixtures, logos and docs so
that Travis can run the tests after running
`pip install ./zulip_bots`.

Also, since we are installing zulip_bots off of this repo in our
main repo, docs and logos should be included so that they can be
rendered alongside our webhooks/integrations documentation, so we
need to include them in MANIFEST.in as well.

To automate this process, I just wrote this handy little script
that future bot contributors can run instead of having to manually
specify what to include in MANIFEST.in in the repo.
2017-08-15 19:30:13 -07:00

64 lines
2 KiB
Python
Executable file

#!/usr/bin/env python
import os
import glob
def get_zulip_bots_test_fixtures():
# type: () -> List[str]
current_dir = os.path.abspath(os.path.dirname(__file__))
bots_dir = os.path.join(current_dir, '..', 'zulip_bots/zulip_bots/bots')
glob_pattern = os.path.join(bots_dir, '*/fixtures/*.json')
fixtures_paths = map(
lambda fp: os.path.join(*fp.split('/')[-5:]),
glob.glob(glob_pattern)
)
return fixtures_paths
def get_zulip_bots_logos():
# type: () -> List[str]
current_dir = os.path.abspath(os.path.dirname(__file__))
bots_dir = os.path.join(current_dir, '..', 'zulip_bots/zulip_bots/bots')
glob_pattern = os.path.join(bots_dir, '*/logo.*')
logo_paths = map(
lambda fp: os.path.join(*fp.split('/')[-4:]),
glob.glob(glob_pattern)
)
return logo_paths
def get_zulip_bots_docs():
# type: () -> List[str]
current_dir = os.path.abspath(os.path.dirname(__file__))
bots_dir = os.path.join(current_dir, '..', 'zulip_bots/zulip_bots/bots')
glob_pattern = os.path.join(bots_dir, '*/doc.md')
doc_paths = map(
lambda fp: os.path.join(*fp.split('/')[-4:]),
glob.glob(glob_pattern)
)
return doc_paths
def main():
# type: () -> None
current_dir = os.path.abspath(os.path.dirname(__file__))
manifest_path = os.path.join(current_dir, '..', 'zulip_bots/MANIFEST.in')
with open(manifest_path, 'w') as fp:
template = 'include {line}\n'
fixtures = map(lambda line: template.format(line=line),
get_zulip_bots_test_fixtures())
logos = map(lambda line: template.format(line=line),
get_zulip_bots_logos())
docs = map(lambda line: template.format(line=line),
get_zulip_bots_docs())
fp.writelines(fixtures)
fp.write('\n')
fp.writelines(logos)
fp.write('\n')
fp.writelines(docs)
fp.write('\n')
if __name__ == '__main__':
main()