Skip to content

Commit 144032e

Browse files
authored
Add pre-commit Support (#1)
* Add pre-commit * Update devcontainer * Update code naming convention * Update pyproject * Add random docs
1 parent 8db8f53 commit 144032e

File tree

14 files changed

+121
-123
lines changed

14 files changed

+121
-123
lines changed

.devcontainer/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN apt-get install -y --no-install-recommends \
1414
make \
1515
git \
1616
wget \
17-
curl
17+
curl
1818

1919
RUN apt-get install -y --no-install-recommends \
2020
python3 \
@@ -35,11 +35,11 @@ FROM debian as poetry
3535

3636
ENV PATH="/home/vscode/.local/bin:${PATH}"
3737

38-
ARG PYTHON_VIRTUALENV_HOME=/home/vscode/${PROJECT_NAME}-py-env \
38+
ARG PYTHON_VIRTUALENV_HOME=/home/vscode/project-py-env \
3939
POETRY_VERSION=1.8.2
4040

4141
ENV POETRY_VIRTUALENVS_IN_PROJECT=false \
42-
POETRY_NO_INTERACTION=true
42+
POETRY_NO_INTERACTION=true
4343

4444
RUN python3 -m venv ${PYTHON_VIRTUALENV_HOME} && \
4545
$PYTHON_VIRTUALENV_HOME/bin/pip install --upgrade pip wheel && \
@@ -56,8 +56,8 @@ FROM poetry as project-dev
5656

5757
COPY --chown=vscode:vscode pyproject.toml poetry.lock* ./
5858

59-
RUN poetry install --no-root --with dev
59+
RUN poetry install --no-root --with dev --with docs
6060

6161
WORKDIR /workspaces/${PROJECT_NAME}
6262

63-
CMD ["/bin/bash"]
63+
CMD ["/bin/bash"]

.devcontainer/devcontainer.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"context": "..",
66
"dockerFile": "./Dockerfile",
77
"runArgs": [
8-
"--cpus=1.0",
9-
"--memory=1g",
10-
"--ipc=host",
11-
"--privileged",
12-
"--net=host"
8+
// "--cpus=1.0",
9+
// "--memory=1g",
10+
// "--ipc=host",
11+
// "--privileged",
12+
// "--net=host"
1313
],
1414
"mounts": [
1515
// {
@@ -20,7 +20,7 @@
2020
],
2121
"customizations": {
2222
"vscode": {
23-
"extensions": [
23+
"extensions": [
2424
"ms-python.python",
2525
"ms-azuretools.vscode-docker",
2626
"njpwerner.autodocstring",
@@ -37,10 +37,9 @@
3737
"redhat.vscode-yaml"
3838
],
3939
"settings": {
40-
"python.defaultInterpreterPath": "/home/vscode/python-project-template-py-env/bin/python"
40+
"python.defaultInterpreterPath": "/home/vscode/project-py-env/bin/python"
4141
}
4242
}
43-
4443
},
4544

4645
// Features to add to the dev container. More info: https://containers.dev/features.
@@ -61,4 +60,4 @@
6160
"PROJECT_NAME": "python-project-template"
6261
}
6362
}
64-
}
63+
}

.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
ENV="dev"
2-
OTHER_VAR="OIHER VAR"
2+
OTHER_VAR="OIHER VAR"

.pre-commit-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: no-commit-to-branch
6+
- id: check-added-large-files
7+
- id: check-yaml
8+
args: ['--unsafe']
9+
- id: check-toml
10+
- id: check-ast
11+
- id: end-of-file-fixer
12+
- id: trailing-whitespace
13+
- id: check-case-conflict
14+
- id: check-docstring-first
15+
- id: name-tests-test
16+
- id: detect-private-key
17+
18+
- repo: https://github.com/codespell-project/codespell
19+
rev: v2.2.6
20+
hooks:
21+
- id: codespell
22+
entry: codespell
23+
args:
24+
[
25+
"--ignore-words-list=py,",
26+
"--quiet-level=2",
27+
"--skip=./**/tests/**,./**/_test*.py,.git,*.ipynb,*.json,*.lock,*.txt,*.yaml",
28+
]
29+
30+
- repo: https://github.com/astral-sh/ruff-pre-commit
31+
rev: v0.3.3
32+
hooks:
33+
- id: ruff
34+
types_or: [ python, pyi, jupyter ]
35+
args: [ --fix ]
36+
- id: ruff-format
37+
types_or: [ python, pyi, jupyter ]
38+
39+
- repo: local
40+
hooks:
41+
- id: mypy
42+
name: check typing
43+
description: ""
44+
entry: mypy
45+
language: python
46+
types_or: [python, pyi]
47+
args: ["--ignore-missing-imports"]
48+
require_serial: true
49+
50+
- repo: local
51+
hooks:
52+
- id: pytest
53+
name: run tests
54+
description: ""
55+
entry: poetry run pytest tests
56+
pass_filenames: false
57+
language: python
58+
types_or: [python, pyi]
59+
args: []
60+
require_serial: true

docs/getting_started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Installation steps.
1+
# Installation steps.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Introduction
1+
# Introduction

poetry.lock

Lines changed: 5 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ version = "0.0.1"
44
description = "Description."
55
license = "MIT"
66
authors = ["Author <[email protected]>"]
7+
maintainers = ["Author <[email protected]>"]
8+
repository = "https://github.com/ross-tsenov/python-project-template"
9+
documentation = "https://github.com/ross-tsenov/python-project-template/tree/main/docs/"
710
readme = "README.md"
11+
include = [
12+
"src",
13+
]
814
exclude = [
915
"docs/*",
1016
"tests/*",
1117
]
1218

1319

1420
[tool.poetry.dependencies]
15-
python = ">=3.10.1,<4.0"
21+
python = "^3.10.1"
1622
python-dotenv = "^1.0.0"
1723
pydantic-settings = "^2.2.1"
1824

@@ -21,7 +27,6 @@ pydantic-settings = "^2.2.1"
2127
ruff = "^0.0.285"
2228
mypy = "^1.8.0"
2329
pytest = "^7.4.4"
24-
pytest-cov = "^4.1.0"
2530
pre-commit = "^3.6.2"
2631

2732

@@ -44,14 +49,20 @@ line-length = 122
4449
target-version = "py310"
4550
# All options here: https://github.com/charliermarsh/ruff#supported-rules
4651
select = [
52+
"A",
53+
"B",
4754
"E",
48-
"W",
4955
"F",
56+
"G",
57+
"I",
58+
"N",
59+
"W",
5060
"Q",
5161
"S",
5262
"UP",
53-
"I",
54-
"N",
63+
"C9",
64+
"PT",
65+
"ANN",
5566
"PLC",
5667
"PLE",
5768
"PLR",
@@ -98,17 +109,24 @@ pretty = true
98109
follow_imports="silent"
99110
ignore_missing_imports = true
100111
show_error_codes = true
112+
exclude = [
113+
"__init__.py",
114+
]
101115

102116

103117
[tool.pytest.ini_options]
104118
minversion = "6.0"
105-
addopts = "-ra -q"
119+
addopts = """
120+
-ra \
121+
-q \
122+
--verbose \
123+
--maxfail=1 \
124+
--color=yes """
106125
testpaths = ["tests/"]
126+
python_files = ["*_test.py"]
127+
python_functions = ["test_*"]
128+
render_collapsed = true
107129
filterwarnings = [
108130
"ignore",
109131
"default:::mymodule",
110132
]
111-
112-
113-
[tool.coverage.paths]
114-
source = ["cendiant_inspection/"]
File renamed without changes.
File renamed without changes.
File renamed without changes.

python_project_template/settings.py renamed to src/settings.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
from typing import Literal
1+
from enum import StrEnum
22

33
from dotenv import load_dotenv
44
from pydantic_settings import BaseSettings
55

66

7+
class Environment(StrEnum):
8+
DEV = "dev"
9+
PROD = "prod"
10+
11+
712
class Settings(BaseSettings):
813
"""Global application settings loaded from the .env file."""
914

10-
env: Literal["dev", "prod"] = "dev"
15+
env: Environment = Environment.DEV
1116
other_var: str = "other"
1217

1318

tests/settings_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from src.settings import Environment, settings
2+
3+
4+
def test_settings() -> None:
5+
assert settings.env in [Environment.DEV, Environment.PROD]

tests/test_sample.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)