From 902c49c734070c696fdd0d3aa4b64b72a4a022ee Mon Sep 17 00:00:00 2001 From: James Curtin Date: Sun, 3 Nov 2019 08:40:31 -0500 Subject: [PATCH] Update format strings to f strings --- Dockerfile | 2 +- cookiecutter-docker.sh | 2 -- cookiecutter.json | 20 +++++++++---------- hooks/pre_gen_project.py | 2 +- {{cookiecutter.app_name}}/tests/factories.py | 4 ++-- .../{{cookiecutter.app_name}}/app.py | 2 +- .../{{cookiecutter.app_name}}/commands.py | 2 +- .../{{cookiecutter.app_name}}/database.py | 4 ++-- .../{{cookiecutter.app_name}}/user/models.py | 6 +++--- .../{{cookiecutter.app_name}}/utils.py | 2 +- 10 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index eb71044..21e7fe2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-slim-buster +FROM python:3.8-slim-buster RUN pip install \ cookiecutter==1.6.0 diff --git a/cookiecutter-docker.sh b/cookiecutter-docker.sh index b223bd4..2880946 100755 --- a/cookiecutter-docker.sh +++ b/cookiecutter-docker.sh @@ -62,5 +62,3 @@ run_cookiecutter() { process_args "$@" run_cookiecutter - -exit 0 diff --git a/cookiecutter.json b/cookiecutter.json index 075e5e5..50dac8c 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -1,12 +1,12 @@ { - "full_name": "Steven Loria", - "email": "sloria1@gmail.com", - "github_username": "sloria", - "project_name": "My Flask App", - "app_name": "{{cookiecutter.project_name.lower().replace('-', '_').replace(' ', '_')}}", - "project_short_description": "A flasky app.", - "use_pipenv": ["no", "yes"], - "python_version": ["3.7", "3.6"], - "node_version": ["12", "10", "8"], - "use_heroku": ["no", "yes"] + "full_name": "Steven Loria", + "email": "sloria1@gmail.com", + "github_username": "sloria", + "project_name": "My Flask App", + "app_name": "{{cookiecutter.project_name.lower().replace('-', '_').replace(' ', '_')}}", + "project_short_description": "A flasky app.", + "use_pipenv": ["no", "yes"], + "python_version": ["3.8", "3.7", "3.6"], + "node_version": ["12", "10"], + "use_heroku": ["no", "yes"] } diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index 26c1340..57b2630 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -31,7 +31,7 @@ def validate_python_module_name(): module_name = "{{ cookiecutter.app_name }}" if not re.match(MODULE_REGEX, module_name): log_warning(module_name) - raise ValueError + sys.exit(1) if __name__ == "__main__": diff --git a/{{cookiecutter.app_name}}/tests/factories.py b/{{cookiecutter.app_name}}/tests/factories.py index 17d0203..40160d3 100644 --- a/{{cookiecutter.app_name}}/tests/factories.py +++ b/{{cookiecutter.app_name}}/tests/factories.py @@ -20,8 +20,8 @@ class BaseFactory(SQLAlchemyModelFactory): class UserFactory(BaseFactory): """User factory.""" - username = Sequence(lambda n: "user{0}".format(n)) - email = Sequence(lambda n: "user{0}@example.com".format(n)) + username = Sequence(lambda n: f"user{n}") + email = Sequence(lambda n: f"user{n}@example.com") password = PostGenerationMethodCall("set_password", "example") active = True diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py index e6eaaa6..dd05cc5 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py @@ -61,7 +61,7 @@ def register_errorhandlers(app): """Render error template.""" # If a HTTPException, pull the `code` attribute; default to 500 error_code = getattr(error, "code", 500) - return render_template("{0}.html".format(error_code)), error_code + return render_template(f"{error_code}.html"), error_code for errcode in [401, 404, 500]: app.errorhandler(errcode)(render_error) diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/commands.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/commands.py index 9049219..65b168b 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/commands.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/commands.py @@ -49,7 +49,7 @@ def lint(fix_imports, check): def execute_tool(description, *args): """Execute a checking tool with its arguments.""" command_line = list(args) + files_and_directories - click.echo("{}: {}".format(description, " ".join(command_line))) + click.echo(f"{description}: {' '.join(command_line)}") rv = call(command_line) if rv != 0: exit(rv) diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py index 17c612d..435f955 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py @@ -78,7 +78,7 @@ def reference_col( column_kwargs = column_kwargs or {} return Column( - db.ForeignKey("{0}.{1}".format(tablename, pk_name), **foreign_key_kwargs), + db.ForeignKey(f"{tablename}.{pk_name}", **foreign_key_kwargs), nullable=nullable, - **column_kwargs + **column_kwargs, ) diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/user/models.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/user/models.py index 6ee97c0..e9746c3 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/user/models.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/user/models.py @@ -29,7 +29,7 @@ class Role(SurrogatePK, Model): def __repr__(self): """Represent instance as a unique string.""" - return "".format(name=self.name) + return f"" class User(UserMixin, SurrogatePK, Model): @@ -65,8 +65,8 @@ class User(UserMixin, SurrogatePK, Model): @property def full_name(self): """Full user name.""" - return "{0} {1}".format(self.first_name, self.last_name) + return f"{self.first_name} {self.last_name}" def __repr__(self): """Represent instance as a unique string.""" - return "".format(username=self.username) + return f"" diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/utils.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/utils.py index 5e93055..6c91dd0 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/utils.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/utils.py @@ -7,4 +7,4 @@ def flash_errors(form, category="warning"): """Flash all errors for a form.""" for field, errors in form.errors.items(): for error in errors: - flash("{0} - {1}".format(getattr(form, field).label.text, error), category) + flash(f"{getattr(form, field).label.text} - {error}", category)