From ba85f8581ecd2f034aa35d3f6ce7c0734c6c05fb Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Tue, 19 Jul 2022 15:51:45 -0400 Subject: [PATCH 1/4] Update initial app name across the repo Why these changes are being introduced: "app" was too generic a term to use as the initial app name. It meant a find-and-replace across the repo would change many more things than the actual app name (for example, documentation including the words "app" or "application"). A better initial name is one that is not part of other words and would *only* be used in places where the app name matters in the code, making it easy to find and replace. How this addresses that need: * Replaces the app name "app" with "my_app" across the repo to ensure future users of this template can easily update the app name when first creating it. --- Dockerfile | 2 +- Makefile | 6 +++--- Pipfile | 2 +- README.md | 6 +++--- app/__init__.py | 1 - my_app/__init__.py | 1 + {app => my_app}/cli.py | 2 +- {app => my_app}/config.py | 2 +- tests/test_cli.py | 2 +- tests/test_config.py | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 app/__init__.py create mode 100644 my_app/__init__.py rename {app => my_app}/cli.py (91%) rename {app => my_app}/config.py (94%) diff --git a/Dockerfile b/Dockerfile index de5553f..b9420a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,4 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y git COPY Pipfile* / RUN pipenv install -ENTRYPOINT ["pipenv", "run", "app"] +ENTRYPOINT ["pipenv", "run", "my_app"] diff --git a/Makefile b/Makefile index c1348f9..fa0a50f 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ update: install ## Update all Python dependencies ### Test commands ### test: ## Run tests and print a coverage report - pipenv run coverage run --source=app -m pytest -vv + pipenv run coverage run --source=my_app -m pytest -vv pipenv run coverage report -m coveralls: test @@ -24,13 +24,13 @@ coveralls: test lint: bandit black mypy pylama safety ## Run linting, code quality, and safety checks bandit: - pipenv run bandit -r app + pipenv run bandit -r my_app black: pipenv run black --check --diff . mypy: - pipenv run mypy app + pipenv run mypy my_app pylama: pipenv run pylama --options setup.cfg diff --git a/Pipfile b/Pipfile index 3cba513..9247e67 100644 --- a/Pipfile +++ b/Pipfile @@ -20,4 +20,4 @@ pytest = "*" python_version = "3.10" [scripts] -app = "python -c \"from app.cli import main; main()\"" +my_app = "python -c \"from my_app.cli import main; main()\"" diff --git a/README.md b/README.md index 721dc37..00cfdbc 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A template repository for creating Python CLI applications. ## App setup (delete this section and above after initial application setup) -1. Rename "app" to the desired app name across the repo. (May be helpful to do a project-wide find-and-replace). +1. Rename "my_app" to the desired app name across the repo. (May be helpful to do a project-wide find-and-replace). 2. Update Python version if needed. 3. Install all dependencies with `make install` to create initial Pipfile.lock with latest dependency versions. 4. Add initial app description to README and update initial required ENV variable documentation as needed. @@ -20,7 +20,7 @@ A template repository for creating Python CLI applications. - Create an alert for the prod environment only, with notifications sent to the appropriate team(s). - If *not* using Sentry, delete Sentry configuration from config.py and test_config.py, and remove sentry_sdk from project dependencies. -# app +# my_app Description of the app @@ -30,7 +30,7 @@ Description of the app - To update dependencies: `make update` - To run unit tests: `make test` - To lint the repo: `make lint` -- To run the app: `pipenv run app --help` +- To run the app: `pipenv run my_app --help` ## Required ENV diff --git a/app/__init__.py b/app/__init__.py deleted file mode 100644 index d2a0a87..0000000 --- a/app/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""app package.""" diff --git a/my_app/__init__.py b/my_app/__init__.py new file mode 100644 index 0000000..470cdfb --- /dev/null +++ b/my_app/__init__.py @@ -0,0 +1 @@ +"""my_app package.""" diff --git a/app/cli.py b/my_app/cli.py similarity index 91% rename from app/cli.py rename to my_app/cli.py index 1d06d48..55e54a5 100644 --- a/app/cli.py +++ b/my_app/cli.py @@ -4,7 +4,7 @@ import click -from app.config import configure_logger, configure_sentry +from my_app.config import configure_logger, configure_sentry logger = logging.getLogger(__name__) diff --git a/app/config.py b/my_app/config.py similarity index 94% rename from app/config.py rename to my_app/config.py index 61bec1d..533df61 100644 --- a/app/config.py +++ b/my_app/config.py @@ -12,7 +12,7 @@ def configure_logger(logger: logging.Logger, verbose: bool) -> str: ) logger.setLevel(logging.DEBUG) for handler in logging.root.handlers: - handler.addFilter(logging.Filter("app")) + handler.addFilter(logging.Filter("my_app")) else: logging.basicConfig( format="%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s" diff --git a/tests/test_cli.py b/tests/test_cli.py index 6c40eed..9975759 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,4 @@ -from app.cli import main +from my_app.cli import main def test_cli_no_options(caplog, runner): diff --git a/tests/test_config.py b/tests/test_config.py index 8de42cb..69f28d1 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,6 +1,6 @@ import logging -from app.config import configure_logger, configure_sentry +from my_app.config import configure_logger, configure_sentry def test_configure_logger_not_verbose(): From c9451233de88c4df0fd8195568b54512b4c20e2c Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Fri, 5 Aug 2022 16:15:47 -0400 Subject: [PATCH 2/4] Add pydocstyle config --- setup.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.cfg b/setup.cfg index 1a2a98f..d127443 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,6 +11,9 @@ ignore = C0114,C0116,D100,D103,W0012 linters = eradicate,isort,mccabe,pycodestyle,pydocstyle,pyflakes,pylint max_line_length = 90 +[pylama:pydocstyle] +convention = pep257 + [tool:pytest] log_level = DEBUG From 9d3f7e58a9333bed5e5a04eecdbec3b48dcd5497 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Fri, 5 Aug 2022 16:17:23 -0400 Subject: [PATCH 3/4] Add isort configuration --- setup.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.cfg b/setup.cfg index d127443..cc8b645 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,6 +11,9 @@ ignore = C0114,C0116,D100,D103,W0012 linters = eradicate,isort,mccabe,pycodestyle,pydocstyle,pyflakes,pylint max_line_length = 90 +[pylama:isort] +profile = black + [pylama:pydocstyle] convention = pep257 From a7916116f4731f380450fdb20f506cf426a5e438 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Fri, 5 Aug 2022 16:31:57 -0400 Subject: [PATCH 4/4] Pin pyflakes version until pylama fixes bug with 2.5.0 --- Pipfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Pipfile b/Pipfile index 9247e67..66b2156 100644 --- a/Pipfile +++ b/Pipfile @@ -15,6 +15,7 @@ coveralls = "*" mypy = "*" pylama = {extras = ["all"], version = "*"} pytest = "*" +pyflakes = "==2.4.0" [requires] python_version = "3.10"