Skip to content

Commit 392b407

Browse files
committed
Upgrade to Astral UV and ruff.
1 parent 424ec4f commit 392b407

File tree

14 files changed

+615
-893
lines changed

14 files changed

+615
-893
lines changed

.github/workflows/compreq.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ jobs:
2121
- uses: actions/setup-python@v4
2222
with:
2323
python-version: "3.10"
24-
- run: curl -sSL https://install.python-poetry.org | python3 -
25-
- run: poetry install --all-extras
26-
- run: ./compreq.sh
24+
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
25+
- run: uv run --locked --no-editable ./compreq.sh

.github/workflows/test_release.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ jobs:
1818
- uses: actions/setup-python@v4
1919
with:
2020
python-version: ${{ matrix.python }}
21-
- run: curl -sSL https://install.python-poetry.org | python3 -
22-
- run: poetry install --all-extras
23-
- run: poetry run task test
21+
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
22+
- run: uv run --python python${{ matrix.python }} --locked --no-editable task test
2423

2524
test-install:
2625
runs-on: ubuntu-latest
@@ -34,9 +33,8 @@ jobs:
3433
- uses: actions/setup-python@v4
3534
with:
3635
python-version: ${{ matrix.python }}
37-
- run: curl -sSL https://install.python-poetry.org | python3 -
38-
- run: poetry install --only main
39-
- run: poetry run python -c "import dropstackframe"
36+
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
37+
- run: uv run --python python${{ matrix.python }} --locked --no-editable --no-dev python -c "import dropstackframe"
4038

4139
all-tests:
4240
needs: [tests, test-install]
@@ -58,8 +56,7 @@ jobs:
5856
- uses: actions/setup-python@v4
5957
with:
6058
python-version: "3.10"
61-
- run: curl -sSL https://install.python-poetry.org | python3 -
62-
- run: poetry install
63-
- run: poetry run python set_version.py "${{github.ref_name}}"
64-
- run: poetry build
59+
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
60+
- run: uv run --locked --no-editable python set_version.py "${{github.ref_name}}"
61+
- run: uv build
6562
- uses: pypa/gh-action-pypi-publish@release/v1

.python-version

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

compreq.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#!/bin/env bash
22

3-
branch=compreq
4-
53
set -xe
64

5+
branch=compreq
6+
77
git fetch origin main
88
git checkout main
99
git pull --rebase origin main
1010
if ! git checkout -b ${branch}; then
1111
git branch -D ${branch}
1212
git checkout -b ${branch}
1313
fi
14-
poetry run python -m requirements
14+
uv run python -m requirements
15+
uv run task format
1516
if [[ $(git status --porcelain) ]]; then
16-
poetry update
17+
uv lock --upgrade
1718
git \
1819
-c "user.name=Update requirements bot" \
1920
-c "user.email=none" \

dropstackframe/dropstackframe.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
Code for dropping stack frames from stack traces.
33
"""
44

5-
from contextlib import contextmanager
6-
from typing import ContextManager, Iterator
5+
from collections.abc import Iterator
6+
from contextlib import AbstractContextManager, contextmanager
77

88
_enabled = True
99

1010

11-
def set_enable_drop_stack_frame(enabled: bool) -> ContextManager[None]:
11+
def set_enable_drop_stack_frame(enabled: bool) -> AbstractContextManager[None]:
1212
"""Sets whether `drop_stack_frame` is enabled or not.
1313
1414
If `set_enable_drop_stack_frame(False)` then `drop_stack_frame()` has no effect. This can be
@@ -80,9 +80,8 @@ def f() -> None:
8080
try:
8181
# pylint: disable=function-redefined
8282

83-
import sys
84-
8583
import _testcapi
84+
import sys
8685

8786
DROP_STACK_FRAME_SUPPORTED = True
8887

poetry.lock

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

poetry.toml

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

pyproject.toml

Lines changed: 78 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
[tool.poetry]
1+
[project]
22
name = "dropstackframe"
3+
requires-python = "<4,>=3.10"
34
version = "0.1.0"
45
description = "A python package for removing stack frames from stack traces."
5-
authors = ["Jesper Nielsen <[email protected]>"]
6+
authors = [
7+
{ name = "Jesper Nielsen", email = "[email protected]" }
8+
]
69
license = "MIT"
710
readme = "README.md"
8-
911
homepage = "https://github.com/jesnie/dropstackframe"
1012
repository = "https://github.com/jesnie/dropstackframe"
1113

@@ -20,89 +22,110 @@ classifiers = [
2022
"Programming Language :: Python :: 3.13",
2123
]
2224

23-
[tool.poetry.dependencies]
24-
python = "<4,>=3.10"
25-
26-
27-
[tool.poetry.group.dev.dependencies]
28-
black = "<25.2,>=25.1"
29-
compreq = "<0.3.2,>=0.3.1"
30-
isort = "<6.1,>=6.0"
31-
mypy = "<1.16,>=1.15"
32-
pylint = "<3.4,>=3.3"
33-
pytest = "<8.4,>=8.3"
34-
taskipy = "<1.15,>=1.14"
35-
tomlkit = "<0.13.3,>=0.13.2"
25+
[dependency-groups]
26+
dev = [
27+
"compreq<0.3.4,>=0.3.3",
28+
"mypy<1.18,>=1.17",
29+
"pytest<8.5,>=8.4",
30+
"ruff<0.12.6,>=0.12.5",
31+
"taskipy<1.15,>=1.14",
32+
"tomlkit<0.13.4,>=0.13.3",
33+
]
3634

3735
[build-system]
38-
requires = ["poetry-core"]
39-
build-backend = "poetry.core.masonry.api"
36+
requires = ["hatchling"]
37+
build-backend = "hatchling.build"
4038

39+
[tool.ruff]
40+
line-length = 100
41+
indent-width = 4
4142

42-
[tool.isort]
43-
py_version = 310
44-
profile = "black"
43+
[tool.ruff.lint]
44+
select = ["ALL"]
45+
ignore = [
46+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
47+
"ARG", # Unused arguments...
48+
"ARG002", # Unused method argument: `context`
49+
"C901", # `get_lazy_release_set` is too complex
50+
"COM812", # Not recommended with formatting
51+
"D", # DocStrings
52+
"E501", # Line too long
53+
"EM101", # Exception must not use a string literal, assign to variable first
54+
"EM102", # Exception must not use an f-string literal, assign to variable first
55+
"FBT", # Boolean value in call
56+
"PLR0912", # Too many branches
57+
"PLR0913", # Too many arguments in function definition (7 > 5)
58+
"PLR0915", # Too many statements (62 > 50)
59+
"PLR2004", # Magic value used in comparison, consider replacing `2` with a constant variable
60+
"PLW0603", # Using the global statement to update `_enabled` is discouraged
61+
"PLW2901", # `for` loop variable `name` overwritten by assignment target
62+
"PT006", # Wrong type passed to first argument of `pytest.mark.parametrize`; expected `tuple`
63+
"PT011", # `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
64+
"PT013", # Incorrect import of `pytest`; use `import pytest` instead
65+
"PT018", # Assertion should be broken down into multiple parts
66+
"PTH123", # `open()` should be replaced by `Path.open()`
67+
"PYI025", # Use `from collections.abc import Set as AbstractSet` to avoid confusion with the `set` builtin
68+
"RET505", # Unnecessary `else` after `return` statement
69+
"S101", # Use of `assert` detected
70+
"S610", # Use of Django `extra` can lead to SQL injection vulnerabilities
71+
"SIM114", # Combine `if` branches using logical `or` operator
72+
"SLF001", # Private member accessed: `_path`
73+
"T201", # `print` found
74+
"TC001", # Move application import `compreq.contexts.DistributionContext` into a type-checking block
75+
"TC002", # Move third-party import `packaging.version.Version` into a type-checking block
76+
"TC003", # Move standard library import `collections.abc.Iterator` into a type-checking block
77+
"TRY003", # Avoid specifying long messages outside the exception class
78+
"TRY301", # Abstract `raise` to an inner functio
79+
"UP015", # Unnecessary modes
80+
]
4581

46-
[tool.black]
47-
target-version = ["py310"]
48-
line-length = 100
82+
[tool.ruff.lint.per-file-ignores]
83+
"tests/**/*.py" = [
84+
"DTZ001", # `datetime.datetime()` called without a `tzinfo` argument
85+
]
4986

5087
[tool.mypy]
5188
python_version = "3.10"
5289
show_error_codes = true
90+
# First we turn on *all the checks*, and then we turn off those that are too annoying.
5391
strict = true
92+
disallow_untyped_decorators = false
5493

5594
[[tool.mypy.overrides]]
5695
module = [
5796
"_testcapi.*",
5897
]
5998
ignore_missing_imports = true
6099

61-
[tool.pylint.messages_control]
62-
max-line-length = 100
63-
disable = [
64-
"c-extension-no-member",
65-
"global-statement",
66-
"invalid-name",
67-
"missing-function-docstring",
68-
"missing-module-docstring",
69-
"no-member",
70-
]
71-
72-
73100
[tool.taskipy.tasks]
74-
isort = """
75-
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX isort XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
76-
isort dropstackframe tests set_version.py requirements.py
101+
ruff_fmt = """
102+
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ruff format XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
103+
ruff format dropstackframe tests set_version.py requirements.py
77104
"""
78-
isort_check = """
79-
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX isort XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
80-
isort --check-only dropstackframe tests set_version.py requirements.py
105+
ruff_fmt_check = """
106+
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ruff format XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
107+
ruff format --check dropstackframe tests set_version.py requirements.py
81108
"""
82-
black = """
83-
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX black XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
84-
black dropstackframe tests set_version.py requirements.py
109+
ruff_lint = """
110+
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ruff lint XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
111+
ruff check --fix-only dropstackframe tests set_version.py requirements.py
85112
"""
86-
black_check = """
87-
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX black XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
88-
black --check dropstackframe tests set_version.py requirements.py
113+
ruff_lint_check = """
114+
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ruff lint XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
115+
ruff check dropstackframe tests set_version.py requirements.py
89116
"""
90117
mypy = """
91118
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX mypy XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
92119
mypy dropstackframe tests set_version.py requirements.py
93120
"""
94-
pylint = """
95-
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX pylint XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
96-
pylint dropstackframe tests set_version.py requirements.py
97-
"""
98121
pytest = """
99122
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX pytest XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
100123
pytest tests
101124
"""
102125

103-
format = "task isort && task black"
104-
format_check = "task isort_check && task black_check"
105-
lint = "task format_check && task mypy && task pylint"
126+
format = "task ruff_fmt && task ruff_lint"
127+
format_check = "task ruff_fmt_check"
128+
lint = "task format_check && task mypy && task ruff_lint_check"
106129
test = "task lint && task pytest"
107130
format_and_lint = "task format && task lint"
108131
format_and_test = "task format && task test"

requirements.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def set_python_version_in_github_actions(comp_req: cr.CompReq) -> None:
77
python_release_set = comp_req.resolve_release_set("python", cr.python_specifier())
88
minor_versions = sorted(
9-
set(cr.floor(cr.MINOR, r.version, keep_trailing_zeros=False) for r in python_release_set)
9+
{cr.floor(cr.MINOR, r.version, keep_trailing_zeros=False) for r in python_release_set},
1010
)
1111
default_version = min(minor_versions)
1212
minor_versions_str = ", ".join(f'"{v}"' for v in minor_versions)
@@ -17,52 +17,44 @@ def set_python_version_in_github_actions(comp_req: cr.CompReq) -> None:
1717
ref.sub(r"(^ +python-version: \")\d+\.\d+(\")$", rf"\g<1>{default_version_str}\g<2>")
1818
ref.sub(r"(^ +matrix:\s^ +python: \[).*(\]$)", rf"\g<1>{minor_versions_str}\g<2>")
1919

20+
Path(".python-version").write_text(default_version_str)
2021

21-
def set_python_version(comp_req: cr.CompReq, pyproject: cr.PoetryPyprojectFile) -> cr.CompReq:
22+
23+
def set_python_version(comp_req: cr.CompReq, pyproject: cr.PyprojectFile) -> cr.CompReq:
2224
comp_req = comp_req.for_python(
2325
cr.version("<", cr.ceil_ver(cr.MAJOR, cr.max_ver()))
24-
& cr.version(">=", cr.floor_ver(cr.MINOR, cr.max_ver(cr.min_age(years=5))))
26+
& cr.version(">=", cr.floor_ver(cr.MINOR, cr.max_ver(cr.min_age(years=3)))),
2527
)
2628

29+
pyproject.set_requires_python(comp_req, cr.python_specifier())
2730
pyproject.set_python_classifiers(comp_req)
2831
set_python_version_in_github_actions(comp_req)
2932
version = comp_req.resolve_version("python", cr.default_python())
3033

3134
tool = pyproject.toml["tool"]
32-
tool["isort"]["py_version"] = int(f"{version.major}{version.minor}")
33-
tool["black"]["target-version"] = [f"py{version.major}{version.minor}"]
3435
tool["mypy"]["python_version"] = f"{version.major}.{version.minor}"
3536

3637
return comp_req
3738

3839

3940
def main() -> None:
40-
with cr.PoetryPyprojectFile.open() as pyproject:
41-
prev_python_specifier = cr.get_bounds(
42-
pyproject.get_requirements()["python"].specifier
43-
).lower_specifier_set()
41+
with cr.PyprojectFile.open() as pyproject:
42+
prev_python_specifier = cr.get_bounds(pyproject.get_requires_python()).lower_specifier_set()
4443
comp_req = cr.CompReq(python_specifier=prev_python_specifier)
4544
comp_req = set_python_version(comp_req, pyproject)
4645

4746
dev_range = cr.version(">=", cr.floor_ver(cr.REL_MINOR, cr.max_ver())) & cr.version(
48-
"<", cr.ceil_ver(cr.REL_MINOR, cr.max_ver())
47+
"<",
48+
cr.ceil_ver(cr.REL_MINOR, cr.max_ver()),
4949
)
5050

5151
pyproject.set_requirements(
5252
comp_req,
5353
[
54-
cr.dist("python") & cr.python_specifier(),
55-
],
56-
)
57-
pyproject.set_requirements(
58-
comp_req,
59-
[
60-
cr.dist("black") & dev_range,
6154
cr.dist("compreq") & dev_range,
62-
cr.dist("isort") & dev_range,
6355
cr.dist("mypy") & dev_range,
64-
cr.dist("pylint") & dev_range,
6556
cr.dist("pytest") & dev_range,
57+
cr.dist("ruff") & dev_range,
6658
cr.dist("taskipy") & dev_range,
6759
cr.dist("tomlkit") & dev_range,
6860
],

set_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def set_pyproject_version(version: Version) -> None:
1414
with open(PYPROJECT_FILE, "rt", encoding="utf-8") as fin:
1515
config: Any = tomlkit.load(fin)
1616

17-
config["tool"]["poetry"]["version"] = str(version)
17+
config["project"]["version"] = str(version)
1818

1919
with open(PYPROJECT_FILE, "wt", encoding="utf-8") as fout:
2020
tomlkit.dump(config, fout)

0 commit comments

Comments
 (0)