summaryrefslogtreecommitdiffstats
path: root/pyproject.toml
blob: d718a33b6638f2545ec7a57bd4bf72125e461679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "gitlint"
dynamic = ["version", "dependencies", "urls"]
description = "Git commit message linter written in python, checks your commit messages for style."
readme = "README.md"

license = "MIT"
requires-python = ">=3.7"
authors = [{ name = "Joris Roovers" }]
keywords = [
    "git",
    "gitlint",
    "lint",    #
]
classifiers = [
    "Development Status :: 5 - Production/Stable",
    "Environment :: Console",
    "Intended Audience :: Developers",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
    "Programming Language :: Python",
    "Programming Language :: Python :: 3.7",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3.11",
    "Programming Language :: Python :: Implementation :: CPython",
    "Programming Language :: Python :: Implementation :: PyPy",
    "Topic :: Software Development :: Quality Assurance",
    "Topic :: Software Development :: Testing",
]

[tool.hatch.version]
source = "vcs"
raw-options = { version_scheme = "release-branch-semver" }

[tool.hatch.build]
exclude = ["*"]

[tool.hatch.metadata.hooks.vcs.urls]
Homepage = "https://jorisroovers.github.io/gitlint"
Documentation = "https://jorisroovers.github.io/gitlint"
Source = "https://github.com/jorisroovers/gitlint"
Changelog = "https://github.com/jorisroovers/gitlint/blob/main/CHANGELOG.md"
# TODO(jorisroovers): Temporary disable until fixed in hatch-vcs (see #460)
# 'Source Archive' = "https://github.com/jorisroovers/gitlint/archive/{commit_hash}.zip"
# 'Source Commit' = "https://github.com/jorisroovers/gitlint/tree/{commit_hash}"

# Use metadata hooks specified in 'hatch_build.py'
# (this line is critical when building wheels, when building sdist it seems optional)
[tool.hatch.metadata.hooks.custom]

# Environments #########################################################################################################
# NOTE: By default all environments inherit from the 'default' environment

# DEV
# Workaround for editable install:
# https://github.com/pypa/hatch/issues/588
[tool.hatch.envs.dev]
description = """
Dev environment (running gitlint itself from source)
"""
pre-install-commands = [
    "pip install -e ./gitlint-core", #
]

[tool.hatch.envs.dev.scripts]
fullclean = [
    "rm .coverage .coverage.lcov",
    "rm -rf site dist .pytest_cache",
    "rm -rf gitlint-core/dist gitlint-core/build gitlint-core/.pytest_cache",
    "rm -rf qa/__pycache__ qa/.pytest_cache",
]

# TEST
[tool.hatch.envs.test]
description = """
Test environment (unit tests, formatting, lint)
"""
skip-install = true
dependencies = [
    "gitlint-core[trusted-deps] @ {root:uri}/gitlint-core",
    "black==23.1.0",
    "pytest==7.2.1",
    "pytest-cov==4.0.0",
    "python-coveralls==2.9.3",
    "ruff==0.0.252",
    "radon==5.1.0",
    "pdbr==0.8.2; sys_platform != \"win32\"",
    "mypy==1.1.1",
    "types-python-dateutil==2.8.19.12",
]

[tool.hatch.envs.test.scripts]
unit-tests = [
    "pytest --cov=gitlint-core --cov-report=term --cov-report=lcov:.coverage.lcov -rw -s {args:gitlint-core}",
]
u = "unit-tests"
unit-tests-no-cov = "pytest -rw -s {args:gitlint-core}"
format = "black --check --diff {args:.}"
lint = "ruff {args:gitlint-core/gitlint qa}"
type-check = "mypy {args}"
autoformat = "black {args:.}"
autofix = [
    "- ruff --fix {args:gitlint-core/gitlint qa}",
    "autoformat",                                  #
]

all = [
    "unit-tests",
    "format",
    "lint",
    "type-check", #
]
stats = ["./tools/stats.sh"]

# QA
[tool.hatch.envs.qa]
description = """
Integration test environment.
Run a set of integration tests against any gitlint binary (not just the one from local source).
"""
detached = true
dependencies = [
    "pytest==7.2.1",
    "arrow==1.2.3",
    "sh==1.14.3; sys_platform != \"win32\"",
    "pdbr==0.8.2; sys_platform != \"win32\"",
]

[tool.hatch.envs.qa.scripts]
# The integration tests can be ran against any gitlint binary, e.g. one installed from pypi (for post-release testing)
# This is why by default we don't install the local dev version of gitlint in the qa environment
# To run integration tests against the dev version of gitlint, use install-local first
install-local = "pip install -e ./gitlint-core[trusted-deps]"
integration-tests = "pytest -rw -s {args:qa}"
i = "integration-tests"


# DOCS
[tool.hatch.envs.docs]
description = """
Documentation environment. Run docs build and serve commands.
"""
detached = true
dependencies = [
    "mkdocs-material==9.1.9",  #
    "mkdocs-redirects==1.2.0",
    # https://github.com/jimporter/mike/issues/130
    "mike @ https://github.com/jimporter/mike/archive/300593c338b18f61f604d18457c351e166318020.zip",
    "linkchecker==10.2.1",
]

[tool.hatch.envs.docs.scripts]
build = "mkdocs build --clean --strict"
serve = "mkdocs serve"
# Note: `mike serve` will add the doc version selector but doesn't do auto-reload

validate = [
    "build", #
    # Check all links in the docs
    # Ignore 404.html and sitemap.xml since those contain absolute URLs to the site, 
    # which are missing the /gitlint prefix that is automatically added when hosting on github pages.
    # Also: don't bombard github.com with requests (will lead to 429 errors)
    """
    linkchecker --check-extern --ignore sitemap.xml --ignore 404.html \
        --ignore-url https://github.com/jorisroovers/gitlint/ site
    """,
]

# Tool config ##########################################################################################################

[tool.black]
target_version = ['py37', 'py38', 'py39', 'py310']
line-length = 120
# extend-exclude: keep excluding files from .gitignore in addition to the ones specified
extend-exclude = "gitlint-core/gitlint/tests/samples/user_rules/import_exception/invalid_python.py"

[tool.ruff]
target-version = "py37"
extend-exclude = [
    "gitlint-core/gitlint/tests/samples/user_rules/import_exception/invalid_python.py",
]

ignore = [
    "E501",    # Never enforce `E501` (line length violations) - taken care of by black
    "SIM108",  # Use ternary operator instead of if-else-block
    "PLR0913", # Too many arguments to function call
]

select = [
    "F",   # PyFlakes
    "E",   # Pycodestyle
    "W",   # Pycodestyle
    "I",   # isort (import order)
    "YTT", # flake8-2020 (misuse of sys.version)
    "S",   # flake8-bandit (security)
    "B",   # flake8-bugbear
    "C4",  # flake8-comprehensions (correct use of comprehensions)
    "T10", # flake8-debugger (no debug statements)
    "T20", # flake8-print (no print statements)
    "SIM", # flake8-simplify (use simple code)
    "TID", # flake8-tidy-imports (correct import syntax)
    "ARG", # flake8-unused-arguments (no unused function arguments)
    "DTZ", # flake8-datetimez (correct datetime usage)
    "ERA", # eradicate (no commented out code)
    "UP",  # pyupgrade (modern python syntax)
    "PLC", # pylint 
    "PLE", # pylint
    "PLR", # pylint
    "PLW", # pylint
    "PIE", # flake8-pie
    "RUF", # ruff specific
]

[tool.coverage.run]
branch = true # measure branch coverage in addition to statement coverage

[tool.coverage.report]
fail_under = 97
show_missing = true

[tool.mypy]
# Selectively enable strictness options
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
no_implicit_optional = true
strict_equality = true
strict_concatenate = true
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_any_generics = true
warn_return_any = true
disallow_untyped_calls = true
disallow_incomplete_defs = true

# The following options are disabled because they're too strict for now
# check_untyped_defs = true
# disallow_untyped_defs = true
# no_implicit_reexport = true

# Allow not explicitly returning when the function return type includes None
no_warn_no_return = true

exclude = [
    "hatch_build.py",
    "tools/*",
    "gitlint-core/gitlint/tests/samples/user_rules/import_exception/invalid_python.py",
]
files = ["."]
# Minimum supported python version by gitlint is 3.7, so enforce 3.7 typing semantics
python_version = "3.7"

[[tool.mypy.overrides]]
# Ignore "Dataclass attribute may only be overridden by another attribute" errors in git.py
module = "gitlint.git"
disable_error_code = "misc"

[[tool.mypy.overrides]]
# Ignore in gitlint/__init__.py:
# -  Cannot find implementation or library stub for module named "importlib_metadata" [import]
# -  Call to untyped function "version" in typed context  [no-untyped-call]" (Python 3.7)
module = "gitlint"
disable_error_code = ["import", "no-untyped-call"]

[[tool.mypy.overrides]]
# Ignore all errors in qa/shell.py (excluding this file isn't working because mypy include/exclude semantics
# are unintuitive, so we ignore all errors instead)
module = "qa.shell"
ignore_errors = true