black: Reformat without skipping string normalization.
This commit is contained in:
		
							parent
							
								
									fba21bb00d
								
							
						
					
					
						commit
						6f3f9bf7e4
					
				
					 178 changed files with 5242 additions and 5242 deletions
				
			
		|  | @ -25,7 +25,7 @@ def cd(newdir): | |||
| 
 | ||||
| 
 | ||||
| def _generate_dist(dist_type, setup_file, package_name, setup_args): | ||||
|     message = 'Generating {dist_type} for {package_name}.'.format( | ||||
|     message = "Generating {dist_type} for {package_name}.".format( | ||||
|         dist_type=dist_type, | ||||
|         package_name=package_name, | ||||
|     ) | ||||
|  | @ -35,7 +35,7 @@ def _generate_dist(dist_type, setup_file, package_name, setup_args): | |||
|     with cd(setup_dir): | ||||
|         setuptools.sandbox.run_setup(setup_file, setup_args) | ||||
| 
 | ||||
|     message = '{dist_type} for {package_name} generated under {dir}.\n'.format( | ||||
|     message = "{dist_type} for {package_name} generated under {dir}.\n".format( | ||||
|         dist_type=dist_type, | ||||
|         package_name=package_name, | ||||
|         dir=setup_dir, | ||||
|  | @ -45,13 +45,13 @@ def _generate_dist(dist_type, setup_file, package_name, setup_args): | |||
| 
 | ||||
| def generate_bdist_wheel(setup_file, package_name, universal=False): | ||||
|     if universal: | ||||
|         _generate_dist('bdist_wheel', setup_file, package_name, ['bdist_wheel', '--universal']) | ||||
|         _generate_dist("bdist_wheel", setup_file, package_name, ["bdist_wheel", "--universal"]) | ||||
|     else: | ||||
|         _generate_dist('bdist_wheel', setup_file, package_name, ['bdist_wheel']) | ||||
|         _generate_dist("bdist_wheel", setup_file, package_name, ["bdist_wheel"]) | ||||
| 
 | ||||
| 
 | ||||
| def twine_upload(dist_dirs): | ||||
|     message = 'Uploading distributions under the following directories:' | ||||
|     message = "Uploading distributions under the following directories:" | ||||
|     print(crayons.green(message, bold=True)) | ||||
|     for dist_dir in dist_dirs: | ||||
|         print(crayons.yellow(dist_dir)) | ||||
|  | @ -59,14 +59,14 @@ def twine_upload(dist_dirs): | |||
| 
 | ||||
| 
 | ||||
| def cleanup(package_dir): | ||||
|     build_dir = os.path.join(package_dir, 'build') | ||||
|     temp_dir = os.path.join(package_dir, 'temp') | ||||
|     dist_dir = os.path.join(package_dir, 'dist') | ||||
|     egg_info = os.path.join(package_dir, '{}.egg-info'.format(os.path.basename(package_dir))) | ||||
|     build_dir = os.path.join(package_dir, "build") | ||||
|     temp_dir = os.path.join(package_dir, "temp") | ||||
|     dist_dir = os.path.join(package_dir, "dist") | ||||
|     egg_info = os.path.join(package_dir, "{}.egg-info".format(os.path.basename(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) | ||||
| 
 | ||||
|     _rm_if_it_exists(build_dir) | ||||
|  | @ -77,11 +77,11 @@ def cleanup(package_dir): | |||
| 
 | ||||
| def set_variable(fp, variable, value): | ||||
|     fh, temp_abs_path = tempfile.mkstemp() | ||||
|     with os.fdopen(fh, 'w') as new_file, open(fp) as old_file: | ||||
|     with os.fdopen(fh, "w") as new_file, open(fp) as old_file: | ||||
|         for line in old_file: | ||||
|             if line.startswith(variable): | ||||
|                 if isinstance(value, bool): | ||||
|                     template = '{variable} = {value}\n' | ||||
|                     template = "{variable} = {value}\n" | ||||
|                 else: | ||||
|                     template = '{variable} = "{value}"\n' | ||||
|                 new_file.write(template.format(variable=variable, value=value)) | ||||
|  | @ -91,22 +91,22 @@ def set_variable(fp, variable, value): | |||
|     os.remove(fp) | ||||
|     shutil.move(temp_abs_path, fp) | ||||
| 
 | ||||
|     message = 'Set {variable} in {fp} to {value}.'.format(fp=fp, variable=variable, value=value) | ||||
|     message = "Set {variable} in {fp} to {value}.".format(fp=fp, variable=variable, value=value) | ||||
|     print(crayons.white(message, bold=True)) | ||||
| 
 | ||||
| 
 | ||||
| def update_requirements_in_zulip_repo(zulip_repo_dir, version, hash_or_tag): | ||||
|     common = os.path.join(zulip_repo_dir, 'requirements', 'common.in') | ||||
|     prod = os.path.join(zulip_repo_dir, 'requirements', 'prod.txt') | ||||
|     dev = os.path.join(zulip_repo_dir, 'requirements', 'dev.txt') | ||||
|     common = os.path.join(zulip_repo_dir, "requirements", "common.in") | ||||
|     prod = os.path.join(zulip_repo_dir, "requirements", "prod.txt") | ||||
|     dev = os.path.join(zulip_repo_dir, "requirements", "dev.txt") | ||||
| 
 | ||||
|     def _edit_reqs_file(reqs, zulip_bots_line, zulip_line): | ||||
|         fh, temp_abs_path = tempfile.mkstemp() | ||||
|         with os.fdopen(fh, 'w') as new_file, open(reqs) as old_file: | ||||
|         with os.fdopen(fh, "w") as new_file, open(reqs) as old_file: | ||||
|             for line in old_file: | ||||
|                 if 'python-zulip-api' in line and 'zulip==' in line: | ||||
|                 if "python-zulip-api" in line and "zulip==" in line: | ||||
|                     new_file.write(zulip_line) | ||||
|                 elif 'python-zulip-api' in line and 'zulip_bots' in line: | ||||
|                 elif "python-zulip-api" in line and "zulip_bots" in line: | ||||
|                     new_file.write(zulip_bots_line) | ||||
|                 else: | ||||
|                     new_file.write(line) | ||||
|  | @ -114,10 +114,10 @@ def update_requirements_in_zulip_repo(zulip_repo_dir, version, hash_or_tag): | |||
|         os.remove(reqs) | ||||
|         shutil.move(temp_abs_path, reqs) | ||||
| 
 | ||||
|     url_zulip = 'git+https://github.com/zulip/python-zulip-api.git@{tag}#egg={name}=={version}_git&subdirectory={name}\n' | ||||
|     url_zulip_bots = 'git+https://github.com/zulip/python-zulip-api.git@{tag}#egg={name}=={version}+git&subdirectory={name}\n' | ||||
|     zulip_bots_line = url_zulip_bots.format(tag=hash_or_tag, name='zulip_bots', version=version) | ||||
|     zulip_line = url_zulip.format(tag=hash_or_tag, name='zulip', version=version) | ||||
|     url_zulip = "git+https://github.com/zulip/python-zulip-api.git@{tag}#egg={name}=={version}_git&subdirectory={name}\n" | ||||
|     url_zulip_bots = "git+https://github.com/zulip/python-zulip-api.git@{tag}#egg={name}=={version}+git&subdirectory={name}\n" | ||||
|     zulip_bots_line = url_zulip_bots.format(tag=hash_or_tag, name="zulip_bots", version=version) | ||||
|     zulip_line = url_zulip.format(tag=hash_or_tag, name="zulip", version=version) | ||||
| 
 | ||||
|     _edit_reqs_file(prod, zulip_bots_line, zulip_line) | ||||
|     _edit_reqs_file(dev, zulip_bots_line, zulip_line) | ||||
|  | @ -127,11 +127,11 @@ def update_requirements_in_zulip_repo(zulip_repo_dir, version, hash_or_tag): | |||
| 
 | ||||
|     _edit_reqs_file( | ||||
|         common, | ||||
|         editable_zulip_bots.format(tag=hash_or_tag, name='zulip_bots', version=version), | ||||
|         editable_zulip.format(tag=hash_or_tag, name='zulip', version=version), | ||||
|         editable_zulip_bots.format(tag=hash_or_tag, name="zulip_bots", version=version), | ||||
|         editable_zulip.format(tag=hash_or_tag, name="zulip", version=version), | ||||
|     ) | ||||
| 
 | ||||
|     message = 'Updated zulip API package requirements in the main repo.' | ||||
|     message = "Updated zulip API package requirements in the main repo." | ||||
|     print(crayons.white(message, bold=True)) | ||||
| 
 | ||||
| 
 | ||||
|  | @ -177,39 +177,39 @@ And you're done! Congrats! | |||
|     parser = argparse.ArgumentParser(usage=usage) | ||||
| 
 | ||||
|     parser.add_argument( | ||||
|         '--cleanup', | ||||
|         '-c', | ||||
|         action='store_true', | ||||
|         "--cleanup", | ||||
|         "-c", | ||||
|         action="store_true", | ||||
|         default=False, | ||||
|         help='Remove build directories (dist/, build/, egg-info/, etc).', | ||||
|         help="Remove build directories (dist/, build/, egg-info/, etc).", | ||||
|     ) | ||||
| 
 | ||||
|     parser.add_argument( | ||||
|         '--build', | ||||
|         '-b', | ||||
|         metavar='VERSION_NUM', | ||||
|         "--build", | ||||
|         "-b", | ||||
|         metavar="VERSION_NUM", | ||||
|         help=( | ||||
|             'Build sdists and wheels for all packages with the' | ||||
|             'specified version number.' | ||||
|             ' sdists and wheels are stored in <package_name>/dist/*.' | ||||
|             "Build sdists and wheels for all packages with the" | ||||
|             "specified version number." | ||||
|             " sdists and wheels are stored in <package_name>/dist/*." | ||||
|         ), | ||||
|     ) | ||||
| 
 | ||||
|     parser.add_argument( | ||||
|         '--release', | ||||
|         '-r', | ||||
|         action='store_true', | ||||
|         "--release", | ||||
|         "-r", | ||||
|         action="store_true", | ||||
|         default=False, | ||||
|         help='Upload the packages to PyPA using twine.', | ||||
|         help="Upload the packages to PyPA using twine.", | ||||
|     ) | ||||
| 
 | ||||
|     subparsers = parser.add_subparsers(dest='subcommand') | ||||
|     subparsers = parser.add_subparsers(dest="subcommand") | ||||
|     parser_main_repo = subparsers.add_parser( | ||||
|         'update-main-repo', help='Update the zulip/requirements/* in the main zulip repo.' | ||||
|         "update-main-repo", help="Update the zulip/requirements/* in the main zulip repo." | ||||
|     ) | ||||
|     parser_main_repo.add_argument('repo', metavar='PATH_TO_ZULIP_DIR') | ||||
|     parser_main_repo.add_argument('version', metavar='version number of the packages') | ||||
|     parser_main_repo.add_argument('--hash', metavar='COMMIT_HASH') | ||||
|     parser_main_repo.add_argument("repo", metavar="PATH_TO_ZULIP_DIR") | ||||
|     parser_main_repo.add_argument("version", metavar="version number of the packages") | ||||
|     parser_main_repo.add_argument("--hash", metavar="COMMIT_HASH") | ||||
| 
 | ||||
|     return parser.parse_args() | ||||
| 
 | ||||
|  | @ -217,7 +217,7 @@ And you're done! Congrats! | |||
| def main(): | ||||
|     options = parse_args() | ||||
| 
 | ||||
|     glob_pattern = os.path.join(REPO_DIR, '*', 'setup.py') | ||||
|     glob_pattern = os.path.join(REPO_DIR, "*", "setup.py") | ||||
|     setup_py_files = glob.glob(glob_pattern) | ||||
| 
 | ||||
|     if options.cleanup: | ||||
|  | @ -230,30 +230,30 @@ def main(): | |||
|         for package_dir in package_dirs: | ||||
|             cleanup(package_dir) | ||||
| 
 | ||||
|         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) | ||||
|         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)) | ||||
|             generate_bdist_wheel(setup_file, package_name) | ||||
| 
 | ||||
|         set_variable(bots_setup, 'IS_PYPA_PACKAGE', False) | ||||
|         set_variable(bots_setup, "IS_PYPA_PACKAGE", False) | ||||
| 
 | ||||
|     if options.release: | ||||
|         dist_dirs = glob.glob(os.path.join(REPO_DIR, '*', 'dist', '*')) | ||||
|         dist_dirs = glob.glob(os.path.join(REPO_DIR, "*", "dist", "*")) | ||||
|         twine_upload(dist_dirs) | ||||
| 
 | ||||
|     if options.subcommand == 'update-main-repo': | ||||
|     if options.subcommand == "update-main-repo": | ||||
|         if options.hash: | ||||
|             update_requirements_in_zulip_repo(options.repo, options.version, options.hash) | ||||
|         else: | ||||
|             update_requirements_in_zulip_repo(options.repo, options.version, options.version) | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
| if __name__ == "__main__": | ||||
|     main() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 PIG208
						PIG208