Skip to content

Commit

Permalink
complete App setup steps in python-cli-template
Browse files Browse the repository at this point in the history
  • Loading branch information
adamshire123 committed Feb 16, 2023
1 parent e8397d2 commit d3e7af8
Show file tree
Hide file tree
Showing 12 changed files with 772 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10.3
3.11.2
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim as build
FROM python:3.11-slim as build
WORKDIR /app
COPY . .

Expand All @@ -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", "my_app"]
ENTRYPOINT ["pipenv", "run", "sapinvoices"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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=my_app -m pytest -vv
pipenv run coverage run --source=sapinvoices -m pytest -vv
pipenv run coverage report -m

coveralls: test
Expand All @@ -24,13 +24,13 @@ coveralls: test
lint: bandit black mypy pylama safety ## Run linting, code quality, and safety checks

bandit:
pipenv run bandit -r my_app
pipenv run bandit -r sapinvoices

black:
pipenv run black --check --diff .

mypy:
pipenv run mypy my_app
pipenv run mypy sapinvoices

pylama:
pipenv run pylama --options setup.cfg
Expand Down
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pylama = {extras = ["all"], version = "*"}
pytest = "*"

[requires]
python_version = "3.10"
python_version = "3.11"

[scripts]
my_app = "python -c \"from my_app.cli import main; main()\""
sapinvoices = "python -c \"from sapinvoices.cli import main; main()\""
746 changes: 746 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

38 changes: 13 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
# python-cli-template
# sapinvoices

A template repository for creating Python CLI applications.

## App setup (delete this section and above after initial application setup)

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.
5. Update license if needed (check app-specific dependencies for licensing terms).
6. Check Github repository settings:
- Confirm repo branch protection settings are correct (see [dev docs](https://mitlibraries.github.io/guides/basics/github.html) for details)
- Confirm that all of the following are enabled in the repo's code security and analysis settings:
- Dependabot alerts
- Dependabot security updates
- Secret scanning
7. Create a Sentry project for the app if needed (we want this for most apps):
- Send initial exceptions to Sentry project for dev, stage, and prod environments to create them.
- 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.

# my_app

Description of the app
Transmits ready-to-be-paid invoice data from Alma to MIT accounts payable department's SAP system
sets trasmitted invoice to paid in Alma

## Development

- To install with dev dependencies: `make install`
- To update dependencies: `make update`
- To run unit tests: `make test`
- To lint the repo: `make lint`
- To run the app: `pipenv run my_app --help`
- To run the app: `pipenv run sapinvoices --help`

## Required ENV

- `SENTRY_DSN` = If set to a valid Sentry DSN, enables Sentry exception monitoring. This is not needed for local development.
- `WORKSPACE` = Set to `dev` for local development, this will be set to `stage` and `prod` in those environments by Terraform.
- `ALMA_API_URL` = Base URL for making Alma API calls
- `ALMA_API_READ_WRITE_KEY` = API key for making Alma API calls
- `SAP_DROPBOX_CONNECTION` = JSON formatted connection information for accessing SAP dropbox
- `SAP_REPLY_TO_EMAIL`
- `SAP_FINAL_RECIPIENT_EMAIL` = moira list to recieves final run emails
- `SAP_REVIEW_RECIPIENT_EMAIL` = moira list to recieve review run emails
- `SES_SEND_FROM_EMAIL`
- `SSM_PATH`
- `LOG_LEVEL`
1 change: 0 additions & 1 deletion my_app/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions sapinvoices/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""sapinvoices package."""
2 changes: 1 addition & 1 deletion my_app/cli.py → sapinvoices/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import click

from my_app.config import configure_logger, configure_sentry
from sapinvoices.config import configure_logger, configure_sentry

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion my_app/config.py → sapinvoices/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("my_app"))
handler.addFilter(logging.Filter("sapinvoices"))
else:
logging.basicConfig(
format="%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from my_app.cli import main
from sapinvoices.cli import main


def test_cli_no_options(caplog, runner):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from my_app.config import configure_logger, configure_sentry
from sapinvoices.config import configure_logger, configure_sentry


def test_configure_logger_not_verbose():
Expand Down

0 comments on commit d3e7af8

Please sign in to comment.