From 37da8d8bacf2b02fa21971848629852bc22c4d94 Mon Sep 17 00:00:00 2001 From: Andrey Shpak Date: Wed, 8 Jun 2022 12:52:19 +0300 Subject: [PATCH 1/5] Convert 'format' usage to f-strings (cli.py) --- cookiecutter/cli.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cookiecutter/cli.py b/cookiecutter/cli.py index 4d92de749..ebc8dd0db 100644 --- a/cookiecutter/cli.py +++ b/cookiecutter/cli.py @@ -27,17 +27,16 @@ def version_msg(): """Return the Cookiecutter version, location and Python powering it.""" python_version = sys.version location = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - message = 'Cookiecutter %(version)s from {} (Python {})' - return message.format(location, python_version) + return f"Cookiecutter {__version__} from {location} (Python {python_version})" def validate_extra_context(ctx, param, value): """Validate extra context.""" - for s in value: - if '=' not in s: + for string in value: + if '=' not in string: raise click.BadParameter( - 'EXTRA_CONTEXT should contain items of the form key=value; ' - "'{}' doesn't match that form".format(s) + f"EXTRA_CONTEXT should contain items of the form key=value; " + f"'{string}' doesn't match that form" ) # Convert tuple -- e.g.: ('program_name=foobar', 'startsecs=66') @@ -51,8 +50,8 @@ def list_installed_templates(default_config, passed_config_file): cookiecutter_folder = config.get('cookiecutters_dir') if not os.path.exists(cookiecutter_folder): click.echo( - 'Error: Cannot list installed templates. Folder does not exist: ' - '{}'.format(cookiecutter_folder) + f"Error: Cannot list installed templates. " + f"Folder does not exist: {cookiecutter_folder}" ) sys.exit(-1) From 164caa4b03d1887676f6cf1a78faac8302d6c932 Mon Sep 17 00:00:00 2001 From: Andrey Shpak Date: Wed, 8 Jun 2022 12:53:03 +0300 Subject: [PATCH 2/5] Convert 'format' usage to f-strings (generate.py) --- cookiecutter/generate.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cookiecutter/generate.py b/cookiecutter/generate.py index 01cbcf8a0..f71aba261 100644 --- a/cookiecutter/generate.py +++ b/cookiecutter/generate.py @@ -65,8 +65,8 @@ def apply_overwrites_to_context(context, overwrite_context): context_value.insert(0, overwrite) else: raise ValueError( - "{} provided for choice variable {}, but the " - "choices are {}.".format(overwrite, variable, context_value) + f"{overwrite} provided for choice variable {variable}, " + f"but the choices are {context_value}." ) elif isinstance(context_value, dict) and isinstance(overwrite, dict): # Partially overwrite some keys in original dict @@ -100,8 +100,8 @@ def generate_context( full_fpath = os.path.abspath(context_file) json_exc_message = str(e) our_exc_message = ( - 'JSON decoding error while loading "{}". Decoding' - ' error details: "{}"'.format(full_fpath, json_exc_message) + f"JSON decoding error while loading '{full_fpath}'. " + f"Decoding error details: '{json_exc_message}'" ) raise ContextDecodingException(our_exc_message) @@ -115,8 +115,8 @@ def generate_context( if default_context: try: apply_overwrites_to_context(obj, default_context) - except ValueError as ex: - warnings.warn("Invalid default received: " + str(ex)) + except ValueError as error: + warnings.warn(f"Invalid default received: {error}") if extra_context: apply_overwrites_to_context(obj, extra_context) From a1d48684c0a797a2b8ade2cadf99a67121917278 Mon Sep 17 00:00:00 2001 From: Andrey Shpak Date: Wed, 8 Jun 2022 12:53:42 +0300 Subject: [PATCH 3/5] Convert 'format' usage to f-strings (prompt.py) --- cookiecutter/prompt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cookiecutter/prompt.py b/cookiecutter/prompt.py index d27481f7b..d556528e1 100644 --- a/cookiecutter/prompt.py +++ b/cookiecutter/prompt.py @@ -66,9 +66,9 @@ def read_user_choice(var_name, options): choice_lines = ['{} - {}'.format(*c) for c in choice_map.items()] prompt = '\n'.join( ( - f'Select {var_name}:', - '\n'.join(choice_lines), - 'Choose from {}'.format(', '.join(choices)), + f"Select {var_name}:", + "\n".join(choice_lines), + f"Choose from {', '.join(choices)}", ) ) From f4996f24fcf5215932859e24fcc23789c7c9b64e Mon Sep 17 00:00:00 2001 From: Andrey Shpak Date: Wed, 8 Jun 2022 12:53:56 +0300 Subject: [PATCH 4/5] Convert 'format' usage to f-strings (utils.py) --- cookiecutter/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cookiecutter/utils.py b/cookiecutter/utils.py index 4750a2663..6796849fb 100644 --- a/cookiecutter/utils.py +++ b/cookiecutter/utils.py @@ -86,8 +86,8 @@ def prompt_and_delete(path, no_input=False): ok_to_delete = True else: question = ( - "You've downloaded {} before. Is it okay to delete and re-download it?" - ).format(path) + f"You've downloaded {path} before. Is it okay to delete and re-download it?" + ) ok_to_delete = read_user_yes_no(question, 'yes') From 282cf585d708fdc5f980b45edf70d644fcda936b Mon Sep 17 00:00:00 2001 From: Andrey Shpak Date: Wed, 8 Jun 2022 12:54:09 +0300 Subject: [PATCH 5/5] Convert 'format' usage to f-strings (zipfile.py) --- cookiecutter/zipfile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cookiecutter/zipfile.py b/cookiecutter/zipfile.py index 0342f1d71..241944e62 100644 --- a/cookiecutter/zipfile.py +++ b/cookiecutter/zipfile.py @@ -63,8 +63,7 @@ def unzip(zip_uri, is_url, clone_to_dir='.', no_input=False, password=None): first_filename = zip_file.namelist()[0] if not first_filename.endswith('/'): raise InvalidZipRepository( - 'Zip repository {} does not include ' - 'a top-level directory'.format(zip_uri) + f"Zip repository {zip_uri} does not include a top-level directory" ) # Construct the final target directory