Skip to content

Commit 5858339

Browse files
committed
First commit
0 parents  commit 5858339

File tree

13 files changed

+215
-0
lines changed

13 files changed

+215
-0
lines changed

.coverage

52 KB
Binary file not shown.

.devcontainer/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3/.devcontainer/base.Dockerfile
2+
3+
# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
4+
ARG VARIANT="3.10-bullseye"
5+
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

.devcontainer/devcontainer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3
3+
{
4+
"name": "Python 3",
5+
"forwardPorts": [8000],
6+
"build": {
7+
"dockerfile": "Dockerfile",
8+
"context": "..",
9+
"args": {
10+
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
11+
// Append -bullseye or -buster to pin to an OS version.
12+
// Use -bullseye variants on local on arm64/Apple Silicon.
13+
"VARIANT": "3.10-bullseye"
14+
}
15+
},
16+
17+
// Configure tool-specific properties.
18+
"customizations": {
19+
// Configure properties specific to VS Code.
20+
"vscode": {
21+
// Set *default* container specific settings.json values on container create.
22+
"settings": {
23+
"python.defaultInterpreterPath": "/usr/local/bin/python",
24+
"python.linting.enabled": true,
25+
"python.linting.pylintEnabled": true,
26+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
27+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
28+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
29+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
30+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
31+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
32+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
33+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
34+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
35+
"python.testing.unittestEnabled": false,
36+
"python.testing.pytestEnabled": true
37+
},
38+
39+
// Add the IDs of extensions you want installed when the container is created.
40+
"extensions": [
41+
"ms-python.python",
42+
"ms-python.vscode-pylance"
43+
]
44+
}
45+
},
46+
47+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
48+
// "forwardPorts": [],
49+
50+
// Use 'postCreateCommand' to run commands after the container is created.
51+
"postCreateCommand": "pip3 install --user -r requirements-dev.txt && pre-commit install",
52+
53+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
54+
"remoteUser": "vscode"
55+
}

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
ignore = D203
3+
max-complexity = 10
4+
max-line-length = 100
5+
exclude = .venv

.github/workflows/python.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Python checks
2+
push:
3+
branches: [ main ]
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python 3
13+
uses: actions/setup-python@v3
14+
with:
15+
python-version: 3.9
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install -r requirements-dev.txt
20+
- name: Lint with flake8
21+
run: |
22+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
23+
- name: Check pyupgrade
24+
run: pyupgrade --py39-plus .
25+
- name: Check formatting with black
26+
uses: psf/black@stable
27+
with:
28+
src: ". tests/"
29+
options: "--check --verbose"
30+
- name: Check Python import sorting
31+
run: isort --check .
32+
- name: Run unit tests
33+
run: |
34+
pytest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.venv
2+
__pycache__

.pre-commit-config.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/psf/black
9+
rev: 22.3.0
10+
hooks:
11+
- id: black
12+
args: ['--config=./pyproject.toml']
13+
- repo: https://github.com/pycqa/isort
14+
rev: 5.10.1
15+
hooks:
16+
- id: isort
17+
name: isort (python)
18+
- repo: https://gitlab.com/pycqa/flake8
19+
rev: 4.0.1
20+
hooks:
21+
- id: flake8
22+
exclude: '.venv/'
23+
args: ['--config=.flake8']
24+
- repo: https://github.com/asottile/pyupgrade
25+
rev: v3.1.0
26+
hooks:
27+
- id: pyupgrade
28+
args: ['--py39-plus']

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Python project template
2+
3+
This is a template repository for any Python project that comes with the following dev tools:
4+
5+
* black: auto-formats code
6+
* isort: sorts the imports
7+
* flake8: looks for common errors
8+
* pyupgrade: upgrades Python syntax
9+
10+
All of those checks are run as pre-commit hooks using the `pre-commit` library.
11+
12+
It includes `pytest` for testing plus the `pytest-cov` plugin to measure coverage.
13+
14+
The checks and tests are all run using Github actions on every pull request and merge to main.
15+
16+
This repository is setup for Python 3.10. To customize that, change the `VARIANT` argument in `.devcontainer/devcontainer.json`, and change the flag passed into `pyupgrade` in `.precommit-config.yaml` and `.github/workflows/python.yaml`.
17+
18+
## Development instructions
19+
20+
## With devcontainer
21+
22+
This repository comes with a devcontainer (a Dockerized Python environment). If you open it in Codespaces, it should automatically initialize the devcontainer.
23+
24+
Locally, you can open it in VS Code with the Dev Containers extension installed.
25+
26+
## Without devcontainer
27+
28+
If you can't or don't want to use the devcontainer, then you should first create a virtual environment:
29+
30+
```
31+
python3 -m venv .venv
32+
source .venv/bin/activate
33+
```
34+
35+
Then install the dev tools and pre-commit hooks:
36+
37+
```
38+
pip3 install --user -r requirements-dev.txt
39+
pre-commit install
40+
```
41+
42+
## Adding code and tests
43+
44+
This repository starts with a very simple `main.py` and a test for it at `tests/main_test.py`.
45+
You'll want to replace that with your own code, and you'll probably want to add additional files
46+
as your code grows in complexity.
47+
48+
When you're ready to run tests, just run:
49+
50+
```
51+
pytest
52+
```
53+
54+
### 🔎 Found an issue or have an idea for improvement?
55+
56+
Help me make this template repository better by letting us know and opening an issue!

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def add_numbers(a, b):
2+
return a + b

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[tool.black]
2+
line-length = 100
3+
target-version = ['py39']
4+
5+
[tool.pytest.ini_options]
6+
addopts = "-ra --cov"
7+
testpaths = ["tests"]
8+
pythonpath = ['.']
9+
10+
[tool.pylint.messages_control]
11+
disable = "C0114,C0115,C0116"
12+
13+
[tool.isort]
14+
profile = "black"

0 commit comments

Comments
 (0)