Skip to content

Commit 2ac3147

Browse files
committed
Fix.
1 parent 43d0764 commit 2ac3147

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ classifiers = [
1515
"Programming Language :: Python :: 3 :: Only",
1616
]
1717
requires-python = ">=3.8"
18-
dependencies = ["click", "pytask>=0.3,<0.4"]
18+
dependencies = ["click", "pytask>=0.4"]
1919
dynamic = ["version"]
2020

2121
[project.readme]
@@ -38,6 +38,9 @@ pytask = { pytask_stata = "pytask_stata.plugin" }
3838

3939
[tool.rye]
4040
managed = true
41+
dev-dependencies = [
42+
"tox-uv>=1.8.2",
43+
]
4144

4245
[tool.hatch.build.targets.sdist]
4346
exclude = ["tests"]

src/pytask_stata/collect.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import functools
56
import subprocess
67
import warnings
78
from pathlib import Path
@@ -121,7 +122,7 @@ def pytask_collect_task(
121122
node_info=NodeInfo(
122123
arg_name="_cwd",
123124
path=(),
124-
value=path.parent,
125+
value=path.parent.as_posix(),
125126
task_path=path,
126127
task_name=name,
127128
),
@@ -140,13 +141,14 @@ def pytask_collect_task(
140141
dependencies["_cwd"] = cwd_node
141142
dependencies["_executable"] = executable_node
142143

144+
partialed = functools.partial(run_stata_script, _cwd=path.parent)
143145
markers = obj.pytask_meta.markers if hasattr(obj, "pytask_meta") else []
144146

145147
task: PTask
146148
if path is None:
147149
task = TaskWithoutPath(
148150
name=name,
149-
function=run_stata_script,
151+
function=partialed,
150152
depends_on=dependencies,
151153
produces=products,
152154
markers=markers,
@@ -155,7 +157,7 @@ def pytask_collect_task(
155157
task = Task(
156158
base_name=name,
157159
path=path,
158-
function=run_stata_script,
160+
function=partialed,
159161
depends_on=dependencies,
160162
produces=products,
161163
markers=markers,

src/pytask_stata/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
def stata(
4848
*,
49-
script: str | Path | None = None,
49+
script: str | Path,
5050
options: str | Iterable[str] | None = None,
5151
) -> tuple[str | Path | None, str | Iterable[str] | None]:
5252
"""Specify command line options for Stata.

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99
from click.testing import CliRunner
10+
from pytask import storage
1011
from pytask_stata.config import STATA_COMMANDS
1112

1213
needs_stata = pytest.mark.skipif(
@@ -72,6 +73,7 @@ def _restore_sys_path_and_module_after_test_execution():
7273
class CustomCliRunner(CliRunner):
7374
def invoke(self, *args, **kwargs):
7475
"""Restore sys.path and sys.modules after an invocation."""
76+
storage.create()
7577
with restore_sys_path_and_module_after_test_execution():
7678
return super().invoke(*args, **kwargs)
7779

tests/test_execute.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def run_do_file():
105105
@pytest.mark.end_to_end()
106106
def test_raise_error_if_stata_is_not_found(tmp_path, monkeypatch):
107107
task_source = """
108-
import pytask
108+
from pytask import mark, task
109109
110-
@pytask.mark.stata(script="script.do")
111-
@pytask.mark.produces("out.dta")
110+
@task(kwargs={"produces": "out.dta"})
111+
@mark.stata(script="script.do")
112112
def task_run_do_file():
113113
pass
114114
"""
@@ -150,6 +150,7 @@ def task_run_do_file():
150150
result = runner.invoke(cli, [tmp_path.as_posix()])
151151

152152
assert result.exit_code == ExitCode.OK
153+
assert tmp_path.joinpath("out.dta").exists()
153154

154155

155156
@needs_stata

tests/test_normal_execution_w_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import textwrap
66

77
import pytest
8+
from pytask import ExitCode
89
from pytask import cli
910

1011

@@ -36,4 +37,4 @@ def task_example(depends_on, produces):
3637
tmp_path.joinpath(dependency).touch()
3738

3839
result = runner.invoke(cli, [tmp_path.as_posix()])
39-
assert result.exit_code == 0
40+
assert result.exit_code == ExitCode.OK

0 commit comments

Comments
 (0)