From 13985510b1a7415e5be11fc29892f7088587919b Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Mon, 18 Dec 2017 21:06:01 -0330 Subject: [PATCH] tools/release-packages: Isolate the build and cleanup commands. This commit fixes a couple of things: * Removes the command line argument called release_version, now one doesn't have to supply a version number when running just running --cleanup, for instance. * Run --cleanup before building the wheels and sdists. This is so that outdated distributions are removed before generating new ones. * Set IS_PYPA_PACKAGE back to False at the end of the --build process so that we don't accidentally set it to True. This was a huge bug in the previous version of the script. --- tools/release-packages | 54 ++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/tools/release-packages b/tools/release-packages index 353992d..857cef0 100755 --- a/tools/release-packages +++ b/tools/release-packages @@ -67,18 +67,22 @@ def cleanup(package_dir): package_dir, '{}.egg-info'.format(os.path.basename(package_dir)) ) - version_symlink = os.path.join(package_dir, 'version.py') def _rm_if_it_exists(directory): if os.path.isdir(directory): print(crayons.green('Removing {}/*.'.format(directory), bold=True)) shutil.rmtree(directory) - map(_rm_if_it_exists, [build_dir, temp_dir, dist_dir, egg_info]) + if package_dir.endswith("zulip_bots"): + manifest_file = os.path.join(package_dir, 'MANIFEST.in') + if os.path.isfile(manifest_file): + print(crayons.green('Removing {}/*.'.format(manifest_file), bold=True)) + os.remove(manifest_file) - if os.path.islink(version_symlink): - print(crayons.green('Removing {}.'.format(version_symlink), bold=True)) - os.remove(version_symlink) + _rm_if_it_exists(build_dir) + _rm_if_it_exists(temp_dir) + _rm_if_it_exists(dist_dir) + _rm_if_it_exists(egg_info) def set_variable(fp, variable, value): fh, temp_abs_path = tempfile.mkstemp() @@ -258,18 +262,15 @@ The above command would accomplish the following (in order): """ parser = argparse.ArgumentParser(usage=usage) - parser.add_argument('release_version', - help='The new version number of the packages.') - parser.add_argument('--cleanup', '-c', action='store_true', default=False, help='Remove build directories (dist/, build/, egg-info/, etc).') parser.add_argument('--build', '-b', - action='store_true', - default=False, - help=('Build sdists and wheels for all packages.' + metavar='VERSION_NUM', + help=('Build sdists and wheels for all packages with the' + 'specified version number.' ' sdists and wheels are stored in /dist/*.')) parser.add_argument('--release', '-r', @@ -303,18 +304,27 @@ The above command would accomplish the following (in order): def main(): options = parse_args() - zulip_init = os.path.join(REPO_DIR, 'zulip', 'zulip', '__init__.py') - set_variable(zulip_init, '__version__', options.release_version) - bots_setup = os.path.join(REPO_DIR, 'zulip_bots', 'setup.py') - set_variable(bots_setup, 'ZULIP_BOTS_VERSION', options.release_version) - set_variable(bots_setup, 'IS_PYPA_PACKAGE', True) - botserver_setup = os.path.join(REPO_DIR, 'zulip_botserver', 'setup.py') - set_variable(botserver_setup, 'ZULIP_BOTSERVER_VERSION', options.release_version) - glob_pattern = os.path.join(REPO_DIR, '*', 'setup.py') setup_py_files = glob.glob(glob_pattern) + if options.cleanup: + package_dirs = map(os.path.dirname, setup_py_files) + for package_dir in package_dirs: + cleanup(package_dir) + + if options.build: + package_dirs = map(os.path.dirname, setup_py_files) + map(cleanup, package_dirs) + + zulip_init = os.path.join(REPO_DIR, 'zulip', 'zulip', '__init__.py') + set_variable(zulip_init, '__version__', options.build) + bots_setup = os.path.join(REPO_DIR, 'zulip_bots', 'setup.py') + set_variable(bots_setup, 'ZULIP_BOTS_VERSION', options.build) + set_variable(bots_setup, 'IS_PYPA_PACKAGE', True) + botserver_setup = os.path.join(REPO_DIR, 'zulip_botserver', 'setup.py') + set_variable(botserver_setup, 'ZULIP_BOTSERVER_VERSION', options.build) + for setup_file in setup_py_files: package_name = os.path.basename(os.path.dirname(setup_file)) if package_name == 'zulip_bots': @@ -324,6 +334,8 @@ def main(): generate_sdist(setup_file, package_name) generate_bdist_wheel_universal(setup_file, package_name) + set_variable(bots_setup, 'IS_PYPA_PACKAGE', False) + if options.release: dist_dirs = glob.glob(os.path.join(REPO_DIR, '*', 'dist', '*')) twine_upload(dist_dirs) @@ -354,9 +366,5 @@ def main(): commit_and_push_version_changes(options.release_version, init_files, options.push) - if options.cleanup: - package_dirs = map(os.path.dirname, setup_py_files) - map(cleanup, package_dirs) - if __name__ == '__main__': main()