Skip to content

Commit 339e0bb

Browse files
authored
Merge pull request #385 from MC-kit/devel
Devel
2 parents 2c9899a + 77bd707 commit 339e0bb

19 files changed

+2312
-2247
lines changed

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ select=ANN,B,B9,BLK,C,D,DAR,E,F,I,N,PD,R,TC,TR,S,W
33
max-complexity=15
44
max-mccabe-complexity=6
55
max-cognitive-complexity=10
6+
max-expression-complexity=10
67
max-line-length=100
78
ignore=
89
# ANN001 Missing type annotation for function argument: doesn't allow to use functools dispatching

.github/constraints.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pip==23.3.1
2-
poetry==1.7.1
1+
pip==24.1.2
2+
poetry==1.8.3
33

.github/workflows/clean-workflow-logs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
# repo: ${{ github.event.repository.name }}
2323
# days_old: ${{ github.event.inputs.days_old }}
2424
- name: Clean workflow runs
25-
uses: dmvict/clean-workflow-runs@v1.2.1
25+
uses: dmvict/clean-workflow-runs@v1
2626
with:
2727
token: ${{ secrets.MCKIT_GITHUB_TOKEN }}
2828
save_period: 30

.github/workflows/tests.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ concurrency:
2929
cancel-in-progress: true
3030

3131
env:
32-
DEFAULT_PYTHON: "3.11"
32+
DEFAULT_PYTHON: "3.12"
3333

3434
jobs:
3535

@@ -130,12 +130,8 @@ jobs:
130130
strategy:
131131
fail-fast: false
132132
matrix:
133-
os: [ ubuntu-latest, macos-latest, windows-latest ]
133+
os: [ ubuntu-latest, windows-latest ]
134134
python-version: [ '3.10', '3.11', '3.12' ]
135-
# msgspec 0.18.6 fails on 3.9
136-
exclude:
137-
- os: macos-latest
138-
python-version: '3.12' # connectorx(>=0.3.2) (required by polars>=0.3.2) is not available
139135

140136
steps:
141137

.pre-commit-config.yaml

+19-15
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# https://github.com/pre-commit/pre-commit for more information
1616
# https://pre-commit.com/hooks.html for more hooks
1717
default_language_version:
18-
python: python3.11
18+
python: python3.12
1919

2020
repos:
2121

@@ -29,7 +29,7 @@ repos:
2929
- id: check-json
3030
- id: check-merge-conflict
3131
- id: check-shebang-scripts-are-executable
32-
exclude: notebooks
32+
exclude: notebooks # jupytext creates python scripts with shebangs but without permissions
3333
- id: check-symlinks
3434
- id: check-toml
3535
- id: check-yaml
@@ -65,34 +65,38 @@ repos:
6565
exclude: \.idea|\.cache|^notebooks|^extern
6666
entry: pyupgrade
6767
args:
68-
- --py39-plus
68+
- --py310-plus
6969
language: system
7070
types: [ python ]
71+
stages: [ manual ]
7172

72-
# Nicely sort imports
73-
- id: isort
74-
name: isort
75-
exclude: tools|\.idea|\.cache|^notebooks|^extern
76-
entry: isort
73+
# Security check
74+
- id: bandit
75+
name: bandit
76+
entry: bandit
77+
args: ["-c", "pyproject.toml"]
7778
language: system
7879
types: [ python ]
80+
exclude: ^notebooks|^extern
81+
stages: [ manual ]
7982

80-
# Black, the code formatter, natively supports pre-commit
81-
- id: black
82-
name: black
83-
entry: black
83+
# Lint and fix Python code (including import sort)
84+
- id: ruff
85+
name: ruff
86+
entry: ruff check --force-exclude --fix --config pyproject.toml
8487
language: system
8588
types: [ python ]
8689
exclude: ^notebooks|^extern
8790

88-
# Lint and fix Python code
91+
# Format Python code
8992
- id: ruff
90-
name: ruff
91-
entry: ruff --force-exclude --fix --config pyproject.toml
93+
name: ruff-format
94+
entry: ruff format --force-exclude --config pyproject.toml
9295
language: system
9396
types: [ python ]
9497
exclude: ^notebooks|^extern
9598

99+
96100
# Lint SQL code
97101
- id: sqlfluff-lint
98102
name: sqlfluff-lint

noxfile.py

+32-135
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ def find_my_name() -> str:
5757
raise ValueError(msg)
5858

5959

60-
package: Final = find_my_name()
61-
locations: Final = f"src/{package}", "tests", "./noxfile.py", "docs/source/conf.py"
60+
package: Final[str] = find_my_name()
61+
locations: Final[tuple[str, ...]] = f"src/{package}", "tests", "./noxfile.py", "docs/source/conf.py"
6262

63-
supported_pythons: Final = "3.10", "3.11", "3.12"
63+
supported_pythons: Final[tuple[str, ...]] = "3.10", "3.11", "3.12"
64+
default_python: Final[str] = "3.12"
6465

6566

6667
def _update_hook(hook: Path, virtualenv: str, s: Session) -> None:
@@ -77,7 +78,7 @@ def _update_hook(hook: Path, virtualenv: str, s: Session) -> None:
7778
{s.bin!r},
7879
os.environ.get("PATH", ""),
7980
))
80-
""",
81+
"""
8182
)
8283
lines.insert(1, header)
8384
hook.write_text("\n".join(lines))
@@ -102,23 +103,15 @@ def activate_virtualenv_in_precommit_hooks(s: Session) -> None:
102103
return
103104

104105
for hook in filter(
105-
lambda x: not x.name.endswith(".sample") and x.is_file(),
106-
hook_dir.iterdir(),
106+
lambda x: not x.name.endswith(".sample") and x.is_file(), hook_dir.iterdir()
107107
):
108108
_update_hook(hook, virtualenv, s)
109109

110110

111-
@session(name="pre-commit")
111+
@session(name="pre-commit", python=default_python)
112112
def precommit(s: Session) -> None:
113113
"""Lint using pre-commit."""
114-
s.run(
115-
"poetry",
116-
"install",
117-
"--no-root",
118-
"--only",
119-
"pre_commit,isort,black,ruff",
120-
external=True,
121-
)
114+
s.run("poetry", "install", "--no-root", "--only", "pre_commit,ruff", external=True)
122115
args = s.posargs or ["run", "--all-files", "--show-diff-on-failure"]
123116
s.run("pre-commit", *args)
124117
if args and args[0] == "install":
@@ -128,13 +121,7 @@ def precommit(s: Session) -> None:
128121
@session(python=supported_pythons)
129122
def tests(s: Session) -> None:
130123
"""Run the test suite."""
131-
s.run(
132-
"poetry",
133-
"install",
134-
"--only",
135-
"main,test,xdoctest,coverage",
136-
external=True,
137-
)
124+
s.run("poetry", "install", "--only", "main,test,xdoctest,coverage", external=True)
138125
try:
139126
s.run("coverage", "run", "--parallel", "-m", "pytest", *s.posargs)
140127
finally:
@@ -149,14 +136,7 @@ def coverage(s: Session) -> None:
149136
To obtain html report run
150137
nox -rs coverage -- html
151138
"""
152-
s.run(
153-
"poetry",
154-
"install",
155-
"--no-root",
156-
"--only",
157-
"coverage",
158-
external=True,
159-
)
139+
s.run("poetry", "install", "--no-root", "--only", "coverage", external=True)
160140

161141
if not s.posargs and any(Path().glob(".coverage.*")):
162142
s.run("coverage", "combine")
@@ -168,88 +148,22 @@ def coverage(s: Session) -> None:
168148
@session
169149
def typeguard(s: Session) -> None:
170150
"""Runtime type checking using Typeguard."""
171-
s.run(
172-
"poetry",
173-
"install",
174-
"--only",
175-
"main,test,typeguard",
176-
external=True,
177-
)
151+
s.run("poetry", "install", "--only", "main,test,typeguard", external=True)
178152
s.run("pytest", "--typeguard-packages=src", *s.posargs, external=True)
179153

180154

181-
@session
182-
def isort(s: Session) -> None:
183-
"""Organize imports."""
184-
search_patterns = [
185-
"*.py",
186-
f"src/{package}/*.py",
187-
"tests/*.py",
188-
"benchmarks/*.py",
189-
"profiles/*.py",
190-
"adhoc/*.py",
191-
]
192-
cwd = Path.cwd()
193-
files_to_process: list[str] = [str(x) for p in search_patterns for x in cwd.glob(p)]
194-
if files_to_process:
195-
s.run(
196-
"poetry",
197-
"install",
198-
"--no-root",
199-
"--only",
200-
"isort",
201-
external=True,
202-
)
203-
s.run(
204-
"isort",
205-
"--check",
206-
"--diff",
207-
*files_to_process,
208-
external=True,
209-
)
210-
211-
212-
@session
213-
def black(s: Session) -> None:
214-
"""Run black code formatter."""
215-
s.run(
216-
"poetry",
217-
"install",
218-
"--no-root",
219-
"--only",
220-
"black",
221-
external=True,
222-
)
223-
args = s.posargs or locations
224-
s.run("black", *args)
225-
226-
227155
@session
228156
def lint(s: Session) -> None:
229157
"""Lint using flake8."""
230-
s.run(
231-
"poetry",
232-
"install",
233-
"--no-root",
234-
"--only",
235-
"flake8",
236-
external=True,
237-
)
158+
s.run("poetry", "install", "--no-root", "--only", "flake8", external=True)
238159
args = s.posargs or locations
239160
s.run("flake8", *args)
240161

241162

242163
@session
243164
def mypy(s: Session) -> None:
244165
"""Type-check using mypy."""
245-
s.run(
246-
"poetry",
247-
"install",
248-
"--no-root",
249-
"--only",
250-
"main,mypy",
251-
external=True,
252-
)
166+
s.run("poetry", "install", "--no-root", "--only", "main,mypy", external=True)
253167
args = s.posargs or ["src", "docs/source/conf.py"]
254168
s.run("mypy", *args)
255169

@@ -258,46 +172,35 @@ def mypy(s: Session) -> None:
258172
s.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
259173

260174

261-
@session(python="3.11")
175+
@session(python=default_python)
262176
def xdoctest(s: Session) -> None:
263177
"""Run examples with xdoctest."""
264-
s.run(
265-
"poetry",
266-
"install",
267-
"--no-root",
268-
"--only",
269-
"main,xdoctest",
270-
external=True,
271-
)
272-
args = s.posargs or ["--quiet", "-m", f"src/{package}"]
178+
# Cannot use --no-root, because imports in __init__ require the package metadata
179+
s.run("poetry", "install", "--only", "main,xdoctest", external=True)
180+
args = s.posargs or ["--silent", "--style", "google", "-c", "all", "-m", f"src/{package}"]
273181
s.run("python", "-m", "xdoctest", *args)
274182

275183

276-
@session(python="3.11")
184+
@session(python=default_python)
277185
def ruff(s: Session) -> None:
278186
"""Run ruff linter."""
279-
s.run(
280-
"poetry",
281-
"install",
282-
"--no-root",
283-
"--only",
284-
"main,ruff",
285-
external=True,
286-
)
287-
args = s.posargs or ["src", "tests"]
187+
s.run("poetry", "install", "--no-root", "--only", "ruff", external=True)
188+
args = s.posargs or ["check", "src", "tests"]
189+
s.run("ruff", *args)
190+
191+
192+
@session(python=default_python, name="ruff-format")
193+
def ruff_format(s: Session) -> None:
194+
"""Run ruff formatter."""
195+
s.run("poetry", "install", "--no-root", "--only", "ruff", external=True)
196+
args = s.posargs or ["format", "src", "tests"]
288197
s.run("ruff", *args)
289198

290199

291-
@session(name="docs-build", python="3.11")
200+
@session(name="docs-build", python=default_python)
292201
def docs_build(s: Session) -> None:
293202
"""Build the documentation."""
294-
s.run(
295-
"poetry",
296-
"install",
297-
"--only",
298-
"main,docs",
299-
external=True,
300-
)
203+
s.run("poetry", "install", "--only", "main,docs", external=True)
301204
build_dir = Path("docs", "_build")
302205
if build_dir.exists():
303206
shutil.rmtree(build_dir)
@@ -306,16 +209,10 @@ def docs_build(s: Session) -> None:
306209
s.run("sphinx-build", *args)
307210

308211

309-
@session(python="3.11")
212+
@session(python=default_python)
310213
def docs(s: Session) -> None:
311214
"""Build and serve the documentation with live reloading on file changes."""
312-
s.run(
313-
"poetry",
314-
"install",
315-
"--only",
316-
"main,docs,docs_auto",
317-
external=True,
318-
)
215+
s.run("poetry", "install", "--only", "main,docs,docs_auto", external=True)
319216
_clean_docs_build_folder()
320217

321218
args = s.posargs or ["--open-browser", "docs/source", "docs/_build"]

0 commit comments

Comments
 (0)