Skip to content

Commit 225cb19

Browse files
authored
Modernize the package. (#119)
1 parent cc0b3bf commit 225cb19

18 files changed

+120
-138
lines changed

.github/workflows/main.yml

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ concurrency:
55
group: ${{ github.head_ref || github.run_id }}
66
cancel-in-progress: true
77

8-
env:
9-
CONDA_EXE: mamba
108

119
on:
1210
push:
@@ -25,13 +23,13 @@ jobs:
2523

2624
steps:
2725
- uses: actions/checkout@v4
28-
- uses: actions/setup-python@v5
26+
- uses: astral-sh/setup-uv@v6
2927
with:
30-
python-version-file: .python-version
31-
allow-prereleases: true
32-
cache: pip
33-
- run: pip install tox-uv
34-
- run: tox -e typing
28+
enable-cache: true
29+
- name: Install just
30+
uses: extractions/setup-just@v2
31+
- name: Run type checking
32+
run: just typing
3533

3634
run-tests:
3735

@@ -46,29 +44,14 @@ jobs:
4644

4745
steps:
4846
- uses: actions/checkout@v4
49-
- uses: actions/setup-python@v5
47+
- uses: astral-sh/setup-uv@v6
5048
with:
5149
python-version: ${{ matrix.python-version }}
52-
cache: pip
53-
allow-prereleases: true
54-
- run: pip install tox
50+
enable-cache: true
51+
- name: Install just
52+
uses: extractions/setup-just@v2
53+
- name: Run tests
54+
run: just test
5555

56-
# Unit, integration, and end-to-end tests.
57-
58-
- name: Run unit tests and doctests.
59-
shell: bash -l {0}
60-
run: tox -e test -- tests -m "unit or (not integration and not end_to_end)" --cov=src --cov=tests --cov-report=xml
61-
62-
- name: Upload unit test coverage reports to Codecov with GitHub Action
56+
- name: Upload test coverage reports to Codecov with GitHub Action
6357
uses: codecov/codecov-action@v5
64-
with:
65-
flags: unit
66-
67-
- name: Run end-to-end tests.
68-
shell: bash -l {0}
69-
run: tox -e test -- tests -m end_to_end --cov=src --cov=tests --cov-report=xml
70-
71-
- name: Upload end_to_end test coverage reports to Codecov with GitHub Action
72-
uses: codecov/codecov-action@v5
73-
with:
74-
flags: end_to_end

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ repos:
2727
hooks:
2828
- id: ruff
2929
- id: ruff-format
30-
- repo: https://github.com/dosisod/refurb
31-
rev: v2.1.0
32-
hooks:
33-
- id: refurb
3430
- repo: https://github.com/kynan/nbstripout
3531
rev: 0.8.1
3632
hooks:

.readthedocs.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
version: 2
22

33
build:
4-
os: ubuntu-22.04
4+
os: ubuntu-24.04
55
tools:
6-
python: "3.10"
6+
python: "3.12"
7+
jobs:
8+
create_environment:
9+
- asdf plugin add uv
10+
- asdf install uv latest
11+
- asdf global uv latest
12+
- UV_PROJECT_ENVIRONMENT=$READTHEDOCS_VIRTUALENV_PATH uv sync --group docs
13+
install:
14+
- "true"
715

816
sphinx:
917
configuration: docs/source/conf.py
1018
fail_on_warning: true
11-
12-
python:
13-
install:
14-
- method: pip
15-
path: .
16-
extra_requirements:
17-
- docs

docs/source/conf.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytask_parallel
1919

2020
if TYPE_CHECKING:
21-
import sphinx
21+
import sphinx # ty: ignore[unresolved-import]
2222

2323

2424
# -- Project information ---------------------------------------------------------------
@@ -30,7 +30,7 @@
3030
# The version, including alpha/beta/rc tags, but not commit hash and datestamps
3131
release = version("pytask_parallel")
3232
# The short X.Y version.
33-
version = ".".join(release.split(".")[:2])
33+
version = ".".join(release.split(".")[:2]) # ty: ignore[invalid-assignment]
3434

3535
# -- General configuration -------------------------------------------------------------
3636

@@ -100,7 +100,7 @@
100100

101101

102102
# Linkcode, based on numpy doc/source/conf.py
103-
def linkcode_resolve(domain: str, info: dict[str, str]) -> str: # noqa: C901
103+
def linkcode_resolve(domain: str, info: dict[str, str]) -> str | None: # noqa: C901
104104
"""Determine the URL corresponding to Python object."""
105105
if domain != "py":
106106
return None
@@ -123,10 +123,10 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> str: # noqa: C901
123123
return None
124124

125125
try:
126-
fn = inspect.getsourcefile(inspect.unwrap(obj))
126+
fn = inspect.getsourcefile(inspect.unwrap(obj)) # ty: ignore[invalid-argument-type]
127127
except TypeError:
128128
try: # property
129-
fn = inspect.getsourcefile(inspect.unwrap(obj.fget))
129+
fn = inspect.getsourcefile(inspect.unwrap(obj.fget)) # ty: ignore[possibly-unbound-attribute,invalid-argument-type]
130130
except (AttributeError, TypeError):
131131
fn = None
132132
if not fn:
@@ -136,7 +136,7 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> str: # noqa: C901
136136
source, lineno = inspect.getsourcelines(obj)
137137
except TypeError:
138138
try: # property
139-
source, lineno = inspect.getsourcelines(obj.fget)
139+
source, lineno = inspect.getsourcelines(obj.fget) # ty: ignore[possibly-unbound-attribute]
140140
except (AttributeError, TypeError):
141141
lineno = None
142142
except OSError:
@@ -202,7 +202,7 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> str: # noqa: C901
202202
}
203203

204204

205-
def setup(app: sphinx.application.Sphinx) -> None:
205+
def setup(app: sphinx.application.Sphinx) -> None: # ty: ignore[unresolved-attribute]
206206
"""Configure sphinx."""
207207
app.add_object_type(
208208
"confval",

docs_src/custom_executors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from concurrent.futures import Executor
22

3-
from my_project.executor import CustomExecutor
3+
from my_project.executor import CustomExecutor # ty: ignore[unresolved-import]
44

55
from pytask_parallel import ParallelBackend
66
from pytask_parallel import WorkerType

justfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Install all dependencies
2+
install:
3+
uv sync --all-groups
4+
5+
# Run tests
6+
test *args="":
7+
uv run --group test pytest --cov=src --cov=tests --cov-report=xml {{args}}
8+
9+
# Run tests with lowest dependency resolution
10+
test-lowest *args="":
11+
uv run --group test --resolution lowest-direct pytest {{args}}
12+
13+
# Run tests with highest dependency resolution
14+
test-highest *args="":
15+
uv run --group test --resolution highest pytest {{args}}
16+
17+
# Run type checking
18+
typing:
19+
uv run --group typing --group test --isolated ty check
20+
21+
# Run linting and formatting
22+
lint:
23+
uvx --with pre-commit-uv pre-commit run -a
24+
25+
# Build documentation
26+
docs:
27+
uv run --group docs sphinx-build docs/source docs/build
28+
29+
# Serve documentation with auto-reload
30+
docs-serve:
31+
uv run --group docs sphinx-autobuild docs/source docs/build
32+
33+
# Run all checks (format, lint, typing, test)
34+
check: lint typing test

pyproject.toml

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ classifiers = [
1111
requires-python = ">=3.9"
1212
dependencies = [
1313
"attrs>=21.3.0",
14-
"click",
14+
"click>=8.1.8,!=8.2.0",
1515
"cloudpickle",
1616
"loky",
1717
"pluggy>=1.0.0",
@@ -24,7 +24,7 @@ dynamic = ["version"]
2424
name = "Tobias Raabe"
2525
2626

27-
[project.optional-dependencies]
27+
[dependency-groups]
2828
coiled = ["coiled>=0.9.4"]
2929
dask = ["dask[complete]", "distributed"]
3030
docs = [
@@ -34,13 +34,26 @@ docs = [
3434
"myst-parser",
3535
"nbsphinx",
3636
"sphinx",
37+
"sphinx-autobuild",
3738
"sphinx-click",
3839
"sphinx-copybutton",
3940
"sphinx-design>=0.3",
4041
"sphinx-toolbox",
4142
"sphinxext-opengraph",
4243
]
43-
test = ["pytask-parallel[coiled,dask]", "nbmake", "pytest", "pytest-cov"]
44+
test = [
45+
"nbmake",
46+
"pytest>=8.4.0",
47+
"pytest-cov>=5.0.0",
48+
{include-group = "coiled"},
49+
{include-group = "dask"},
50+
]
51+
typing = [
52+
"pytask-parallel",
53+
"ty",
54+
{include-group = "coiled"},
55+
{include-group = "dask"},
56+
]
4457

4558
[project.readme]
4659
file = "README.md"
@@ -63,14 +76,6 @@ pytask_parallel = "pytask_parallel.plugin"
6376
requires = ["hatchling", "hatch_vcs"]
6477
build-backend = "hatchling.build"
6578

66-
[tool.rye]
67-
managed = true
68-
dev-dependencies = ["s3fs>=2024.3.1", "tox-uv>=1.7.0"]
69-
70-
[tool.rye.scripts]
71-
clean-docs = { cmd = "rm -rf docs/build" }
72-
build-docs = { cmd = "sphinx-build -b html docs/source docs/build" }
73-
7479
[tool.hatch.build.hooks.vcs]
7580
version-file = "src/pytask_parallel/_version.py"
7681

@@ -88,24 +93,7 @@ source = "vcs"
8893
[tool.hatch.metadata]
8994
allow-direct-references = true
9095

91-
[tool.mypy]
92-
files = ["src", "tests"]
93-
check_untyped_defs = true
94-
disallow_any_generics = true
95-
disallow_incomplete_defs = true
96-
disallow_untyped_defs = true
97-
no_implicit_optional = true
98-
warn_redundant_casts = true
99-
warn_unused_ignores = true
100-
ignore_missing_imports = true
101-
102-
[[tool.mypy.overrides]]
103-
module = "tests.*"
104-
disallow_untyped_defs = false
105-
ignore_errors = true
106-
10796
[tool.ruff]
108-
target-version = "py39"
10997
fix = true
11098
unsafe-fixes = true
11199

@@ -132,13 +120,6 @@ convention = "numpy"
132120
addopts = ["--nbmake"]
133121
# Do not add src since it messes with the loading of pytask-parallel as a plugin.
134122
testpaths = ["tests"]
135-
markers = [
136-
"wip: Tests that are work-in-progress.",
137-
"unit: Flag for unit tests which target mainly a single function.",
138-
"integration: Flag for integration tests which may comprise of multiple unit tests.",
139-
"end_to_end: Flag for tests that cover the whole program.",
140-
]
141-
norecursedirs = [".idea", ".tox"]
142123

143124
[tool.coverage.report]
144125
exclude_also = [

src/pytask_parallel/backends.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ def submit(
4747
def _get_dask_executor(n_workers: int) -> Executor:
4848
"""Get an executor from a dask client."""
4949
_rich_traceback_guard = True
50-
from pytask import import_optional_dependency # noqa: PLC0415
5150

52-
distributed = import_optional_dependency("distributed")
53-
assert distributed # noqa: S101
51+
try:
52+
import distributed # noqa: PLC0415
53+
except ImportError:
54+
msg = "The distributed package is not installed. Please install it."
55+
raise ImportError(msg) from None
56+
5457
try:
5558
client = distributed.Client.current()
5659
except ValueError:

src/pytask_parallel/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def pytask_execute_task(session: Session, task: PTask) -> Future[WrapperResult]:
209209
task_module = get_module(task.function, getattr(task, "path", None))
210210
cloudpickle.register_pickle_by_value(task_module)
211211

212-
return wrapper_func.submit(
212+
return wrapper_func.submit( # ty: ignore[possibly-unbound-attribute,invalid-return-type]
213213
task=task,
214214
console_options=console.options,
215215
kwargs=kwargs,

src/pytask_parallel/wrappers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def _patch_set_trace_and_breakpoint() -> None:
192192
import pdb # noqa: PLC0415, T100
193193
import sys # noqa: PLC0415
194194

195-
pdb.set_trace = _raise_exception_on_breakpoint
196-
sys.breakpointhook = _raise_exception_on_breakpoint
195+
pdb.set_trace = _raise_exception_on_breakpoint # ty: ignore[invalid-assignment]
196+
sys.breakpointhook = _raise_exception_on_breakpoint # ty: ignore[invalid-assignment]
197197

198198

199199
def _render_traceback_to_string(
@@ -205,7 +205,7 @@ def _render_traceback_to_string(
205205
traceback = Traceback(exc_info, show_locals=show_locals)
206206
segments = console.render(traceback, options=console_options)
207207
text = "".join(segment.text for segment in segments)
208-
return (*exc_info[:2], text)
208+
return (*exc_info[:2], text) # ty: ignore[invalid-return-type]
209209

210210

211211
def _handle_function_products(

0 commit comments

Comments
 (0)