Skip to content

Commit 2ceafc9

Browse files
authored
Merge pull request #1 from MITLibraries/create-repo-structure
Create basic repository structure
2 parents 6ba46c7 + 2ca44ca commit 2ceafc9

File tree

16 files changed

+324
-0
lines changed

16 files changed

+324
-0
lines changed

.github/dependabot.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
# Maintain dependencies for GitHub Actions
9+
- package-ecosystem: "github-actions"
10+
directory: "/"
11+
schedule:
12+
interval: "daily"
13+
14+
# Maintain dependencies for npm
15+
- package-ecosystem: "pipenv"
16+
directory: "/"
17+
schedule:
18+
interval: "daily"

.github/pull-request-template.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### What does this PR do?
2+
3+
Describe the overall purpose of the PR changes. Doesn't need to be as specific as the
4+
individual commits.
5+
6+
### Helpful background context
7+
8+
Describe any additional context beyond what the PR accomplishes if it is likely to be
9+
useful to a reviewer.
10+
11+
Delete this section if it isn't applicable to the PR.
12+
13+
### How can a reviewer manually see the effects of these changes?
14+
15+
Explain how to see the proposed changes in the application if possible.
16+
17+
Delete this section if it isn't applicable to the PR.
18+
19+
### Includes new or updated dependencies?
20+
21+
YES | NO
22+
23+
### What are the relevant tickets?
24+
25+
Include links to Jira Software and/or Jira Service Management tickets here.
26+
27+
### Developer
28+
29+
- [ ] All new ENV is documented in README (or there is none)
30+
- [ ] Stakeholder approval has been confirmed (or is not needed)
31+
32+
### Code Reviewer
33+
34+
- [ ] The commit message is clear and follows our guidelines
35+
(not just this pull request message)
36+
- [ ] There are appropriate tests covering any new functionality
37+
- [ ] The documentation has been updated or is unnecessary
38+
- [ ] The changes have been verified
39+
- [ ] New dependencies are appropriate or there were no changes

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: CI
2+
on: push
3+
jobs:
4+
test:
5+
uses: mitlibraries/.github/.github/workflows/python-shared-test.yml@main
6+
lint:
7+
uses: mitlibraries/.github/.github/workflows/python-shared-lint.yml@main

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10.3

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.10-slim as build
2+
WORKDIR /app
3+
COPY . .
4+
5+
RUN pip install --no-cache-dir --upgrade pip pipenv
6+
7+
RUN apt-get update && apt-get upgrade -y && apt-get install -y git
8+
9+
COPY Pipfile* /
10+
RUN pipenv install
11+
12+
ENTRYPOINT ["pipenv", "run", "app"]

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
SHELL=/bin/bash
2+
DATETIME:=$(shell date -u +%Y%m%dT%H%M%SZ)
3+
4+
### Dependency commands ###
5+
6+
install: ## Install dependencies and CLI app
7+
pipenv install --dev
8+
9+
update: install ## Update all Python dependencies
10+
pipenv clean
11+
pipenv update --dev
12+
13+
### Test commands ###
14+
15+
test: ## Run tests and print a coverage report
16+
pipenv run coverage run --source=app -m pytest -vv
17+
pipenv run coverage report -m
18+
19+
coveralls: test
20+
pipenv run coverage lcov -o ./coverage/lcov.info
21+
22+
### Code quality and safety commands ###
23+
24+
lint: bandit black mypy pylama safety ## Run linting, code quality, and safety checks
25+
26+
bandit:
27+
pipenv run bandit -r app
28+
29+
black:
30+
pipenv run black --check --diff .
31+
32+
mypy:
33+
pipenv run mypy app
34+
35+
pylama:
36+
pipenv run pylama --options setup.cfg
37+
38+
safety:
39+
pipenv check
40+
pipenv verify

Pipfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
click = "*"
8+
sentry-sdk = "*"
9+
10+
[dev-packages]
11+
bandit = "*"
12+
black = "*"
13+
coverage = "*"
14+
coveralls = "*"
15+
mypy = "*"
16+
pylama = {extras = ["all"], version = "*"}
17+
pytest = "*"
18+
19+
[requires]
20+
python_version = "3.10"
21+
22+
[scripts]
23+
app = "python -c \"from app.cli import main; main()\""

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# python-cli-template
2+
3+
A template repository for creating Python CLI applications.
4+
5+
## App setup (delete this section and above after initial application setup)
6+
7+
1. Rename "app" to the desired app name across the repo. (May be helpful to do a project-wide find-and-replace).
8+
2. Update Python version if needed.
9+
3. Install all dependencies with `make install` to create initial Pipfile.lock with latest dependency versions.
10+
4. Add initial app description to README and update initial required ENV variable documentation as needed.
11+
5. Update license if needed (check app-specific dependencies for licensing terms).
12+
6. Check Github repository settings:
13+
- Confirm repo branch protection settings are correct (see [dev docs](https://mitlibraries.github.io/guides/basics/github.html) for details)
14+
- Confirm that all of the following are enabled in the repo's code security and analysis settings:
15+
- Dependabot alerts
16+
- Dependabot security updates
17+
- Secret scanning
18+
7. Create a Sentry project for the app if needed (we want this for most apps):
19+
- Send initial exceptions to Sentry project for dev, stage, and prod environments to create them.
20+
- Create an alert for the prod environment only, with notifications sent to the appropriate team(s).
21+
- If *not* using Sentry, delete Sentry configuration from config.py and test_config.py, and remove sentry_sdk from project dependencies.
22+
23+
# app
24+
25+
Description of the app
26+
27+
## Development
28+
29+
- To install with dev dependencies: `make install`
30+
- To update dependencies: `make update`
31+
- To run unit tests: `make test`
32+
- To lint the repo: `make lint`
33+
- To run the app: `pipenv run app --help`
34+
35+
## Required ENV
36+
37+
- `SENTRY_DSN` = If set to a valid Sentry DSN, enables Sentry exception monitoring. This is not needed for local development.
38+
- `WORKSPACE` = Set to `dev` for local development, this will be set to `stage` and `prod` in those environments by Terraform.

app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""app package."""

app/cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import logging
2+
from datetime import timedelta
3+
from time import perf_counter
4+
5+
import click
6+
7+
from app.config import configure_logger, configure_sentry
8+
9+
logger = logging.getLogger(__name__)
10+
11+
12+
@click.command()
13+
@click.option(
14+
"-v", "--verbose", is_flag=True, help="Pass to log at debug level instead of info"
15+
)
16+
def main(verbose: bool) -> None:
17+
start_time = perf_counter()
18+
root_logger = logging.getLogger()
19+
logger.info(configure_logger(root_logger, verbose))
20+
logger.info(configure_sentry())
21+
logger.info("Running process")
22+
23+
# Do things here!
24+
25+
elapsed_time = perf_counter() - start_time
26+
logger.info(
27+
"Total time to complete process: %s", str(timedelta(seconds=elapsed_time))
28+
)

0 commit comments

Comments
 (0)