diff --git a/requirements.txt b/requirements.txt index 024e594..941600c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ crayons twine -gitpython coverage>=4.4.1 pycodestyle==2.3.1 -e ./zulip diff --git a/tools/release-packages b/tools/release-packages index 857cef0..b4ece7b 100755 --- a/tools/release-packages +++ b/tools/release-packages @@ -9,14 +9,11 @@ import glob import shutil import tempfile -from git import Repo import crayons import twine.commands.upload import setuptools.sandbox REPO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -repo = Repo(REPO_DIR) -git = repo.git @contextmanager def cd(newdir): @@ -70,13 +67,13 @@ def cleanup(package_dir): def _rm_if_it_exists(directory): if os.path.isdir(directory): - print(crayons.green('Removing {}/*.'.format(directory), bold=True)) + print(crayons.green('Removing {}/*'.format(directory), bold=True)) shutil.rmtree(directory) 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)) + print(crayons.green('Removing {}'.format(manifest_file), bold=True)) os.remove(manifest_file) _rm_if_it_exists(build_dir) @@ -104,38 +101,10 @@ def set_variable(fp, variable, value): fp=fp, variable=variable, value=value) print(crayons.white(message, bold=True)) -def push_release_tag(version, upstream_or_origin): - print(crayons.yellow('Pushing release tag {}...'.format(version), bold=True)) - git.tag(version) - git.push(upstream_or_origin, version) - -def commit_and_push_version_changes(version, init_files, upstream_or_origin): - message = 'Committing version number changes...{}'.format(version) - print(crayons.yellow(message, bold=True)) - - if upstream_or_origin == 'origin': - branch = 'release-{}'.format(version) - git.checkout('-b', branch) - else: - branch = 'master' - git.checkout(branch) - - print(crayons.yellow('Diff:')) - print(git.diff()) - - git.add(*init_files) - commit_msg = 'python-zulip-api: Upgrade package versions to {}.'.format( - version) - print(crayons.yellow('Commit message: {}'.format(commit_msg), bold=True)) - git.commit('-m', commit_msg) - - git.push(upstream_or_origin, branch) - def update_requirements_in_zulip_repo(zulip_repo_dir, version, hash_or_tag): common = os.path.join(zulip_repo_dir, 'requirements', 'common.txt') prod_lock = os.path.join(zulip_repo_dir, 'requirements', 'prod_lock.txt') dev_lock = os.path.join(zulip_repo_dir, 'requirements', 'dev_lock.txt') - version_py = os.path.join(zulip_repo_dir, 'version.py') def _edit_reqs_file(reqs, zulip_bots_line, zulip_line): fh, temp_abs_path = tempfile.mkstemp() @@ -176,59 +145,6 @@ def update_requirements_in_zulip_repo(zulip_repo_dir, version, hash_or_tag): message = 'Updated zulip API package requirements in the main repo.' print(crayons.white(message, bold=True)) - fh, temp_abs_path = tempfile.mkstemp() - with os.fdopen(fh, 'w') as new_file, open(version_py) as old_file: - variable_exists = False - for line in old_file: - if line.startswith('PROVISION_VERSION'): - variable_exists = True - version_num = float(line.split('=')[-1].strip().replace("'", '')) - version_num = version_num + 0.01 - new_file.write("PROVISION_VERSION = '{}'\n".format(version_num)) - else: - new_file.write(line) - - if not variable_exists: - raise Exception('There is no variable named PROVISION_VERSION in {}'.format(version_py)) - - os.remove(version_py) - shutil.move(temp_abs_path, version_py) - - message = 'Incremented PROVISION_VERSION in the main repo.' - print(crayons.white(message, bold=True)) - -def commit_and_push_requirements_changes(version, upstream_or_origin, - zulip_repo_dir): - zulip_repo_dir = os.path.abspath(zulip_repo_dir) - common = os.path.join(zulip_repo_dir, 'requirements', 'common.txt') - prod_lock = os.path.join(zulip_repo_dir, 'requirements', 'prod_lock.txt') - dev_lock = os.path.join(zulip_repo_dir, 'requirements', 'dev_lock.txt') - version_py = os.path.join(zulip_repo_dir, 'version.py') - - with cd(zulip_repo_dir): - zulip_git = Repo(zulip_repo_dir).git - - message = 'Committing requirements changes...{}'.format(version) - print(crayons.yellow(message, bold=True)) - - if upstream_or_origin == 'origin': - branch = 'upgrade-zulip-packages-{}'.format(version) - zulip_git.checkout('-b', branch) - else: - branch = 'master' - zulip_git.checkout(branch) - - print(crayons.yellow('Diff:')) - print(zulip_git.diff()) - - zulip_git.add(common, prod_lock, dev_lock, version_py) - - commit_msg = 'requirements: Upgrade to version {} of the Zulip API packages.'.format(version) - print(crayons.yellow('Commit message: {}'.format(commit_msg), bold=True)) - zulip_git.commit('-m', commit_msg) - - zulip_git.push(upstream_or_origin, branch) - def parse_args(): usage = """ Script to automate the PyPA release of the zulip, zulip_bots and @@ -278,27 +194,11 @@ The above command would accomplish the following (in order): default=False, help='Upload the packages to PyPA using twine.') - parser.add_argument('--push', - metavar='origin or upstream', - help=('Commit and push a commit changing package versions' - ' (can be either "origin" or "upstream"). If "origin' - ' is specified, a new branch named release- is' - ' checked out before committing and pushing. If' - ' "upstream" is supplied, then master is checked out' - ' before committing and pushing. The process is the' - ' same for changes made to both repos.')) - parser.add_argument('--update-zulip-main-repo', metavar='PATH_TO_ZULIP_DIR', help='Update requirements/* in the main zulip repo and' ' increment PROVISION_VERSION.') - parser.add_argument('--hash', - help=('Commit hash to install off of in the main zulip' - ' repo (used in conjunction with' - ' --update-requirements). If not supplied,' - ' release_version is used as a tag.')) - return parser.parse_args() def main(): @@ -340,31 +240,5 @@ def main(): dist_dirs = glob.glob(os.path.join(REPO_DIR, '*', 'dist', '*')) twine_upload(dist_dirs) - if options.update_zulip_main_repo: - if options.hash: - update_requirements_in_zulip_repo( - options.update_zulip_main_repo, - options.release_version, - options.hash - ) - else: - update_requirements_in_zulip_repo( - options.update_zulip_main_repo, - options.release_version, - options.release_version - ) - - if options.push: - set_variable(zulip_bots_init, 'IS_PYPA_PACKAGE', False) - if options.update_zulip_main_repo: - commit_and_push_requirements_changes( - options.release_version, - options.push, - options.update_zulip_main_repo, - ) - push_release_tag(options.release_version, options.push) - commit_and_push_version_changes(options.release_version, - init_files, options.push) - if __name__ == '__main__': main()