Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version-file: .python-version
allow-prereleases: true
cache: pip
- run: pip install tox-uv
- run: tox -e typing
enable-cache: true
- name: Install just
uses: extractions/setup-just@v2
- run: just typing

run-tests:

Expand All @@ -39,33 +39,30 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
allow-prereleases: true
- run: pip install tox-uv
enable-cache: true
- name: Install just
uses: extractions/setup-just@v2
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

# Unit, integration, and end-to-end tests.

- name: Run unit tests and doctests.
- name: Run tests
shell: bash -l {0}
run: tox -e test -- -m "unit or (not integration and not end_to_end)" --cov=./ --cov-report=xml -n auto
run: just test

- name: Upload unit test coverage reports to Codecov with GitHub Action
- name: Upload test coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v4
with:
flags: unit

- name: Run end-to-end tests.
shell: bash -l {0}
run: tox -e test -- -m end_to_end --cov=./ --cov-report=xml -n auto
- name: Run tests with lowest resolution
if: matrix.python-version == '3.9' && matrix.os == 'ubuntu-latest'
run: just test-lowest

- name: Upload end_to_end test coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v4
with:
flags: end_to_end
- name: Run tests with highest resolution
if: matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest'
run: just test-highest
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ repos:
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/dosisod/refurb
rev: v2.1.0
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.8.3
hooks:
- id: refurb
- id: uv-lock
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.22
hooks:
Expand Down
6 changes: 4 additions & 2 deletions CHANGES.md → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
releases are available on [PyPI](https://pypi.org/project/pytask-stata) and
[Anaconda.org](https://anaconda.org/conda-forge/pytask-stata).

## 0.4.1 - 2024-xx-xx
## 0.5.0 - 2025-07-26

- {pull}`37` updates the CI.
- {pull}`38` updates tests for pytask v0.5.
- {pull}`38` updates tests for pytask v0.5.0.
- {pull}`41` use uv, use ty, update tests and CI, raise minimum python version to 3.9
and support Python 3.13.

## 0.4.0 - 2024-03-19

Expand Down
26 changes: 26 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Install all dependencies
install:
uv sync --all-groups

# Run tests
test:
uv run --group test pytest --cov=src --cov=tests --cov-report=xml

# Run type checking
typing:
uv run --group typing --group test ty check

# Run linting and formatting
lint:
uvx --with pre-commit-uv pre-commit run -a

# Run all checks (format, lint, typing, test)
check: lint typing test

# Run tests with lowest dependency resolution
test-lowest:
uv run --group test --resolution lowest-direct pytest

# Run tests with highest dependency resolution
test-highest:
uv run --group test --resolution highest pytest
39 changes: 8 additions & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
]
requires-python = ">=3.8"
dependencies = ["click", "pytask>=0.4"]
requires-python = ">=3.9"
dependencies = ["click>=8.1.8,!=8.2.0", "pytask>=0.5.2"]
dynamic = ["version"]

[project.readme]
file = "README.md"
content-type = "text/markdown"

[project.optional-dependencies]
test = ["pytest", "pytest-cov", "pytest-xdist"]
typing = ["mypy"]

[project.urls]
Homepage = "https://github.com/pytask-dev/pytask-stata"
Documentation = "https://github.com/pytask-dev/pytask-stata"
Expand All @@ -36,11 +32,13 @@ Changelog = "https://github.com/pytask-dev/pytask-stata/blob/main/CHANGES.md"
[project.entry-points]
pytask = { pytask_stata = "pytask_stata.plugin" }

[tool.rye]
managed = true
dev-dependencies = [
"tox-uv>=1.8.2",
[dependency-groups]
test = [
"pytest>=8.4.0",
"pytest-cov>=5.0.0",
"pytest-xdist>=3.6.1",
]
typing = ["pytask-parallel>=0.5.1", "ty"]

[tool.hatch.build.hooks.vcs]
version-file = "src/pytask_stata/_version.py"
Expand All @@ -59,31 +57,13 @@ source = "vcs"
[tool.hatch.metadata]
allow-direct-references = true

[tool.mypy]
files = ["src", "tests"]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = false
ignore_errors = true

[tool.ruff]
target-version = "py38"
fix = true
unsafe-fixes = true

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN101",
"ANN102",
"ANN401", # flake8-annotate typing.Any
"COM812", # Comply with ruff-format.
"ISC001", # Comply with ruff-format.
Expand All @@ -104,8 +84,5 @@ convention = "numpy"
testpaths = ["tests"]
markers = [
"wip: Tests that are work-in-progress.",
"unit: Flag for unit tests which target mainly a single function.",
"integration: Flag for integration tests which may comprise of multiple unit tests.",
"end_to_end: Flag for tests that cover the whole program.",
]
norecursedirs = [".idea", ".tox"]
8 changes: 4 additions & 4 deletions src/pytask_stata/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def pytask_collect_task(
raise ValueError(msg)

mark = _parse_stata_mark(mark=marks[0])
script, options = stata(**marks[0].kwargs)
obj.pytask_meta.markers.append(mark)
script, options = stata(**marks[0].kwargs) # ty: ignore[missing-argument]
obj.pytask_meta.markers.append(mark) # ty: ignore[possibly-unbound-attribute]

# Collect the nodes in @pytask.mark.julia and validate them.
path_nodes = Path.cwd() if path is None else path.parent
Expand Down Expand Up @@ -141,7 +141,7 @@ def pytask_collect_task(
dependencies["_executable"] = executable_node

partialed = functools.partial(run_stata_script, _cwd=path.parent)
markers = obj.pytask_meta.markers if hasattr(obj, "pytask_meta") else []
markers = obj.pytask_meta.markers if hasattr(obj, "pytask_meta") else [] # ty: ignore[unresolved-attribute]

task: PTask
if path is None:
Expand Down Expand Up @@ -187,6 +187,6 @@ def pytask_collect_task(

def _parse_stata_mark(mark: Mark) -> Mark:
"""Parse a Stata mark."""
script, options = stata(**mark.kwargs)
script, options = stata(**mark.kwargs) # ty: ignore[missing-argument]
parsed_kwargs = {"script": script or None, "options": options or []}
return Mark("stata", (), parsed_kwargs)
6 changes: 3 additions & 3 deletions src/pytask_stata/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def pytask_execute_task_teardown(session: Session, task: PTask) -> None:
"""
if has_mark(task, "stata"):
if session.config["platform"] == "win32":
log_name = task.depends_on["_log_name"].load()
log_name = task.depends_on["_log_name"].load() # ty: ignore[call-non-callable]
if isinstance(task, PTaskWithPath):
path_to_log = task.path.with_name(log_name).with_suffix(".log")
else:
path_to_log = Path.cwd(log_name).with_name(log_name).with_suffix(".log")
path_to_log = Path.cwd() / f"{log_name}.log"
else:
node = task.depends_on["_script"]
path_to_log = node.path.with_suffix(".log")
path_to_log = node.path.with_suffix(".log") # ty: ignore[call-non-callable,possibly-unbound-attribute]

n_lines = session.config["stata_check_log_lines"]

Expand Down
4 changes: 2 additions & 2 deletions src/pytask_stata/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from __future__ import annotations

import sys
from collections.abc import Iterable
from collections.abc import Sequence
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterable
from typing import Sequence

if TYPE_CHECKING:
from pathlib import Path
Expand Down
4 changes: 1 addition & 3 deletions tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pytask_stata.collect import stata


@pytest.mark.unit
@pytest.mark.parametrize(
("args", "kwargs", "expectation", "expected"),
[
Expand All @@ -29,11 +28,10 @@
)
def test_stata(args, kwargs, expectation, expected):
with expectation:
options = stata(*args, **kwargs)
options = stata(*args, **kwargs) # ty: ignore[missing-argument]
assert options == expected


@pytest.mark.unit
@pytest.mark.parametrize(
("mark", "expectation", "expected"),
[
Expand Down
2 changes: 0 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from __future__ import annotations

import pytest
from pytask import build


@pytest.mark.end_to_end
def test_marker_is_configured(tmp_path):
session = build(paths=tmp_path)

Expand Down
12 changes: 2 additions & 10 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from tests.conftest import needs_stata


@pytest.mark.unit
@pytest.mark.parametrize(
("stata", "expectation"),
[(executable, does_not_raise()) for executable in STATA_COMMANDS]
Expand All @@ -31,7 +30,7 @@ def test_pytask_execute_task_setup_raise_error(stata, platform, expectation):
task = Task(
base_name="task_example",
path=Path(),
function=None,
function=lambda: None, # ty: ignore[invalid-argument-type]
markers=[Mark("stata", (), {})],
)

Expand All @@ -42,7 +41,6 @@ def test_pytask_execute_task_setup_raise_error(stata, platform, expectation):


@needs_stata
@pytest.mark.end_to_end
def test_run_do_file(runner, tmp_path):
task_source = """
import pytask
Expand Down Expand Up @@ -72,7 +70,6 @@ def task_run_do_file():


@needs_stata
@pytest.mark.end_to_end
def test_run_do_file_w_task_decorator(runner, tmp_path):
task_source = """
import pytask
Expand Down Expand Up @@ -102,7 +99,6 @@ def run_do_file():
assert tmp_path.joinpath("script.log").exists()


@pytest.mark.end_to_end
def test_raise_error_if_stata_is_not_found(tmp_path, monkeypatch):
task_source = """
from pytask import mark, task
Expand All @@ -124,11 +120,10 @@ def task_run_do_file():
session = build(paths=tmp_path)

assert session.exit_code == ExitCode.FAILED
assert isinstance(session.execution_reports[0].exc_info[1], RuntimeError)
assert isinstance(session.execution_reports[0].exc_info[1], RuntimeError) # ty: ignore[non-subscriptable]


@needs_stata
@pytest.mark.end_to_end
def test_run_do_file_w_wrong_cmd_option(runner, tmp_path):
"""Apparently, Stata simply discards wrong cmd options."""
task_source = """
Expand All @@ -154,7 +149,6 @@ def task_run_do_file():


@needs_stata
@pytest.mark.end_to_end
def test_run_do_file_by_passing_path(runner, tmp_path):
"""Replicates example under "Command Line Arguments" in Readme."""
task_source = """
Expand All @@ -180,7 +174,6 @@ def task_run_do_file():


@needs_stata
@pytest.mark.end_to_end
def test_run_do_file_fails_with_multiple_marks(runner, tmp_path):
task_source = """
import pytask
Expand All @@ -201,7 +194,6 @@ def task_run_do_file():


@needs_stata
@pytest.mark.end_to_end
def test_with_task_without_path(runner, tmp_path):
task_source = """
import pytask
Expand Down
1 change: 0 additions & 1 deletion tests/test_normal_execution_w_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pytask import cli


@pytest.mark.end_to_end
@pytest.mark.parametrize(
"dependencies",
[(), ("in.txt",), ("in_1.txt", "in_2.txt")],
Expand Down
2 changes: 0 additions & 2 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


@needs_stata
@pytest.mark.end_to_end
def test_parallel_parametrization_over_source_files_w_loop(runner, tmp_path):
source = """
import pytask
Expand Down Expand Up @@ -56,7 +55,6 @@ def task_execute_do_file():


@needs_stata
@pytest.mark.end_to_end
def test_parallel_parametrization_over_source_file_w_loop(runner, tmp_path):
source = """
import pytask
Expand Down
Loading
Loading