pyupgrade: Reformat with --py36-plus.
This includes mainly fixes of string literals using f-strings or .format(...), as well as unpacking of list comprehensions.
This commit is contained in:
parent
e27ac0ddbe
commit
9ce7c52a10
78 changed files with 356 additions and 389 deletions
|
@ -13,7 +13,7 @@ whitespace_rules = [
|
|||
] # type: List[Rule]
|
||||
|
||||
markdown_whitespace_rules = list(
|
||||
[rule for rule in whitespace_rules if rule["pattern"] != r"\s+$"]
|
||||
rule for rule in whitespace_rules if rule["pattern"] != r"\s+$"
|
||||
) + [
|
||||
# Two spaces trailing a line with other content is okay--it's a markdown line break.
|
||||
# This rule finds one space trailing a non-space, three or more trailing spaces, and
|
||||
|
|
24
tools/deploy
24
tools/deploy
|
@ -31,14 +31,14 @@ def pack(options: argparse.Namespace) -> None:
|
|||
print("tools/deploy: No main bot file specified.")
|
||||
sys.exit(1)
|
||||
if not os.path.isfile(options.config):
|
||||
print("pack: Config file not found at path: {}.".format(options.config))
|
||||
print(f"pack: Config file not found at path: {options.config}.")
|
||||
sys.exit(1)
|
||||
if not os.path.isdir(options.path):
|
||||
print("pack: Bot folder not found at path: {}.".format(options.path))
|
||||
print(f"pack: Bot folder not found at path: {options.path}.")
|
||||
sys.exit(1)
|
||||
main_path = os.path.join(options.path, options.main)
|
||||
if not os.path.isfile(main_path):
|
||||
print("pack: Bot main file not found at path: {}.".format(main_path))
|
||||
print(f"pack: Bot main file not found at path: {main_path}.")
|
||||
sys.exit(1)
|
||||
|
||||
# Main logic for packing the bot.
|
||||
|
@ -65,7 +65,7 @@ def pack(options: argparse.Namespace) -> None:
|
|||
)
|
||||
zip_file.writestr("config.ini", bot_config)
|
||||
zip_file.close()
|
||||
print("pack: Created zip file at: {}.".format(zip_file_path))
|
||||
print(f"pack: Created zip file at: {zip_file_path}.")
|
||||
|
||||
|
||||
def check_common_options(options: argparse.Namespace) -> None:
|
||||
|
@ -83,7 +83,7 @@ def handle_common_response_without_data(
|
|||
return handle_common_response(
|
||||
response=response,
|
||||
operation=operation,
|
||||
success_handler=lambda r: print("{}: {}".format(operation, success_message)),
|
||||
success_handler=lambda r: print(f"{operation}: {success_message}"),
|
||||
)
|
||||
|
||||
|
||||
|
@ -99,12 +99,12 @@ def handle_common_response(
|
|||
print("{}: {}".format(operation, response_data["message"]))
|
||||
return False
|
||||
else:
|
||||
print("{}: Unexpected success response format".format(operation))
|
||||
print(f"{operation}: Unexpected success response format")
|
||||
return False
|
||||
if response.status_code == requests.codes.unauthorized:
|
||||
print("{}: Authentication error with the server. Aborting.".format(operation))
|
||||
print(f"{operation}: Authentication error with the server. Aborting.")
|
||||
else:
|
||||
print("{}: Error {}. Aborting.".format(operation, response.status_code))
|
||||
print(f"{operation}: Error {response.status_code}. Aborting.")
|
||||
return False
|
||||
|
||||
|
||||
|
@ -112,7 +112,7 @@ def upload(options: argparse.Namespace) -> None:
|
|||
check_common_options(options)
|
||||
file_path = os.path.join(bots_dir, options.botname + ".zip")
|
||||
if not os.path.exists(file_path):
|
||||
print("upload: Could not find bot package at {}.".format(file_path))
|
||||
print(f"upload: Could not find bot package at {file_path}.")
|
||||
sys.exit(1)
|
||||
files = {"file": open(file_path, "rb")}
|
||||
headers = {"key": options.token}
|
||||
|
@ -129,9 +129,9 @@ def clean(options: argparse.Namespace) -> None:
|
|||
file_path = os.path.join(bots_dir, options.botname + ".zip")
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
print("clean: Removed {}.".format(file_path))
|
||||
print(f"clean: Removed {file_path}.")
|
||||
else:
|
||||
print("clean: File '{}' not found.".format(file_path))
|
||||
print(f"clean: File '{file_path}' not found.")
|
||||
|
||||
|
||||
def process(options: argparse.Namespace) -> None:
|
||||
|
@ -341,7 +341,7 @@ To list user's bots, use:
|
|||
if options.command in commands:
|
||||
commands[options.command](options)
|
||||
else:
|
||||
print("tools/deploy: No command '{}' found.".format(options.command))
|
||||
print(f"tools/deploy: No command '{options.command}' found.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -41,7 +41,7 @@ the Python version this command is executed with."""
|
|||
# The output has the format "Python 1.2.3"
|
||||
py_version_list = py_version_output.split()[1].split(".")
|
||||
py_version = tuple(int(num) for num in py_version_list[0:2])
|
||||
venv_name = "zulip-api-py{}-venv".format(py_version[0])
|
||||
venv_name = f"zulip-api-py{py_version[0]}-venv"
|
||||
|
||||
if py_version <= (3, 1) and (not options.force):
|
||||
print(
|
||||
|
|
|
@ -62,11 +62,11 @@ 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)))
|
||||
egg_info = os.path.join(package_dir, f"{os.path.basename(package_dir)}.egg-info")
|
||||
|
||||
def _rm_if_it_exists(directory):
|
||||
if os.path.isdir(directory):
|
||||
print(crayons.green("Removing {}/*".format(directory), bold=True))
|
||||
print(crayons.green(f"Removing {directory}/*", bold=True))
|
||||
shutil.rmtree(directory)
|
||||
|
||||
_rm_if_it_exists(build_dir)
|
||||
|
@ -91,7 +91,7 @@ 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 = f"Set {variable} in {fp} to {value}."
|
||||
print(crayons.white(message, bold=True))
|
||||
|
||||
|
||||
|
@ -122,8 +122,8 @@ def update_requirements_in_zulip_repo(zulip_repo_dir, version, hash_or_tag):
|
|||
_edit_reqs_file(prod, zulip_bots_line, zulip_line)
|
||||
_edit_reqs_file(dev, zulip_bots_line, zulip_line)
|
||||
|
||||
editable_zulip = '-e "{}"\n'.format(url_zulip.rstrip())
|
||||
editable_zulip_bots = '-e "{}"\n'.format(url_zulip_bots.rstrip())
|
||||
editable_zulip = f'-e "{url_zulip.rstrip()}"\n'
|
||||
editable_zulip_bots = f'-e "{url_zulip_bots.rstrip()}"\n'
|
||||
|
||||
_edit_reqs_file(
|
||||
common,
|
||||
|
|
|
@ -35,7 +35,7 @@ def check_git_pristine() -> None:
|
|||
def ensure_on_clean_master() -> None:
|
||||
branch = get_git_branch()
|
||||
if branch != "master":
|
||||
exit("You are still on a feature branch: %s" % (branch,))
|
||||
exit(f"You are still on a feature branch: {branch}")
|
||||
check_git_pristine()
|
||||
run("git fetch upstream master")
|
||||
run("git rebase upstream/master")
|
||||
|
@ -43,7 +43,7 @@ def ensure_on_clean_master() -> None:
|
|||
|
||||
def create_pull_branch(pull_id: int) -> None:
|
||||
run("git fetch upstream pull/%d/head" % (pull_id,))
|
||||
run("git checkout -B review-%s FETCH_HEAD" % (pull_id,))
|
||||
run(f"git checkout -B review-{pull_id} FETCH_HEAD")
|
||||
run("git rebase upstream/master")
|
||||
run("git log upstream/master.. --oneline")
|
||||
run("git diff upstream/master.. --name-status")
|
||||
|
|
|
@ -207,7 +207,7 @@ if args.quick:
|
|||
# run mypy
|
||||
status = 0
|
||||
for repo, python_files in repo_python_files.items():
|
||||
print("Running mypy for `{}`.".format(repo), flush=True)
|
||||
print(f"Running mypy for `{repo}`.", flush=True)
|
||||
if python_files:
|
||||
result = subprocess.call([mypy_command] + extra_args + python_files)
|
||||
if result != 0:
|
||||
|
|
|
@ -11,7 +11,7 @@ os.chdir(os.path.dirname(TOOLS_DIR))
|
|||
|
||||
|
||||
def handle_input_and_run_tests_for_package(package_name, path_list):
|
||||
parser = argparse.ArgumentParser(description="Run tests for {}.".format(package_name))
|
||||
parser = argparse.ArgumentParser(description=f"Run tests for {package_name}.")
|
||||
parser.add_argument(
|
||||
"--coverage",
|
||||
nargs="?",
|
||||
|
@ -31,7 +31,7 @@ def handle_input_and_run_tests_for_package(package_name, path_list):
|
|||
)
|
||||
options = parser.parse_args()
|
||||
|
||||
test_session_title = " Running tests for {} ".format(package_name)
|
||||
test_session_title = f" Running tests for {package_name} "
|
||||
header = test_session_title.center(shutil.get_terminal_size().columns, "#")
|
||||
print(header)
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ def main():
|
|||
|
||||
if options.pytest:
|
||||
excluded_bots = ["merels"]
|
||||
pytest_bots_to_test = sorted([bot for bot in bots_to_test if bot not in excluded_bots])
|
||||
pytest_bots_to_test = sorted(bot for bot in bots_to_test if bot not in excluded_bots)
|
||||
pytest_options = [
|
||||
"-s", # show output from tests; this hides the progress bar though
|
||||
"-x", # stop on first test failure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue