Skip to content

Commit 3a60787

Browse files
authored
Release 0.0.2 and transition to pytask 0.0.5. (#1)
1 parent fb16022 commit 3a60787

17 files changed

+98
-42
lines changed

.conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ requirements:
2020

2121
run:
2222
- python >=3.6
23-
- pytask >=0.0.4
23+
- pytask >=0.0.5
2424

2525
test:
2626
requires:

CHANGES.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ chronological order. Releases follow `semantic versioning <https://semver.org/>`
66
all releases are available on `Anaconda.org <https://anaconda.org/pytask/pytask-r>`_.
77

88

9+
0.0.2 - 2020-xx-xx
10+
------------------
11+
12+
- :gh:`1` includes some minor changes like fixing the missing version variable.
13+
14+
915
0.0.1 - 2020-07-22
1016
------------------
1117

12-
- :gh:`1` combined the whole effort which went into releasing v0.0.1.
18+
- Release v0.0.1.

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Or install install R from the official `R Project <https://www.r-project.org/>`_
5454
Usage
5555
-----
5656

57+
Similarly to normal task functions which execute Python code, you also define tasks to
58+
execute scripts written in R with Python functions. The difference is that the function
59+
body does not contain any logic, but the decorators tell pytask how to handle the task.
60+
5761
Here is an example where you want to run ``script.r``.
5862

5963
.. code-block:: python
@@ -79,6 +83,10 @@ dependencies it may look like this
7983
def task_run_r_script():
8084
pass
8185
86+
If you are wondering why the function body is empty, know that pytask-r replaces the
87+
body with an predefined internal function. See the section on implementation details for
88+
more information.
89+
8290

8391
Command Line Arguments
8492
~~~~~~~~~~~~~~~~~~~~~~
@@ -133,6 +141,8 @@ include the R decorator in the parametrization just like with
133141
pass
134142
135143
144+
.. _implementation_details:
145+
136146
Implementation Details
137147
----------------------
138148

@@ -147,6 +157,10 @@ The plugin is only a convenient wrapper around
147157
to which you can always resort to when the plugin does not deliver functionality you
148158
need.
149159

160+
It is not possible to enter a post-mortem debugger when an error happens in the R script
161+
or enter the debugger when starting the script. If there exists a solution for that,
162+
hints as well as contributions are highly appreciated.
163+
150164

151165
Changes
152166
-------

environment.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ channels:
44
- r
55
- pytask
66
dependencies:
7-
- python=3.7
7+
- python
88
- pip
99

1010
# Conda
@@ -13,10 +13,11 @@ dependencies:
1313
- conda-verify
1414

1515
# Package dependencies
16-
- pytask >= 0.0.4
16+
- pytask >= 0.0.5
1717
- r-base
1818

1919
# Misc
20+
- bumpversion
2021
- jupyterlab
2122
- pdbpp
2223
- pre-commit

setup.cfg

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
[bumpversion]
2-
current_version = 0.0.1
2+
current_version = 0.0.2
33
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))(\-?((dev)?(?P<dev>\d+))?)
4-
serialize =
5-
{major}.{minor}.{patch}dev{dev}
6-
{major}.{minor}.{patch}
4+
serialize =
5+
{major}.{minor}.{patch}dev{dev}
6+
{major}.{minor}.{patch}
77

88
[bumpversion:file:setup.py]
99

10-
[bumpversion:file:docs/conf.py]
11-
1210
[bumpversion:file:src/pytask_r/__init__.py]

setup.py

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

44
setup(
55
name="pytask-r",
6-
version="0.0.1",
6+
version="0.0.2",
77
packages=find_packages(where="src"),
88
package_dir={"": "src"},
99
entry_points={"pytask": ["pytask_r = pytask_r.plugin"]},

src/pytask_r/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.2"

src/pytask_r/collect.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
import copy
22
import functools
33
import subprocess
4+
from typing import Iterable
5+
from typing import Optional
6+
from typing import Union
47

5-
import pytask
6-
from pytask.mark import get_markers_from_task
7-
from pytask.mark import has_marker
8-
from pytask.nodes import PythonFunctionTask
9-
from pytask.parametrize import _copy_func
10-
from pytask.shared import to_list
8+
from _pytask.config import hookimpl
9+
from _pytask.mark import get_specific_markers_from_task
10+
from _pytask.mark import has_marker
11+
from _pytask.nodes import PythonFunctionTask
12+
from _pytask.parametrize import _copy_func
13+
from _pytask.shared import to_list
14+
15+
16+
def r(options: Optional[Union[str, Iterable[str]]] = None):
17+
"""Specify command line options for Rscript.
18+
19+
Parameters
20+
----------
21+
options : Optional[Union[str, Iterable[str]]]
22+
One or multiple command line options passed to Rscript.
23+
24+
"""
25+
if options is None:
26+
options = ["--vanilla"]
27+
elif isinstance(options, str):
28+
options = [options]
29+
return options
1130

1231

1332
def run_r_script(depends_on, r):
1433
script = to_list(depends_on)[0]
1534
subprocess.run(["Rscript", script.as_posix(), *r])
1635

1736

18-
@pytask.hookimpl
37+
@hookimpl
1938
def pytask_collect_task(session, path, name, obj):
2039
"""Collect a task which is a function.
2140
@@ -29,7 +48,7 @@ def pytask_collect_task(session, path, name, obj):
2948
path, name, obj, session
3049
)
3150
r_function = _copy_func(run_r_script)
32-
r_function.pytestmark = copy.deepcopy(task.function.pytestmark)
51+
r_function.pytaskmark = copy.deepcopy(task.function.pytaskmark)
3352

3453
args = _create_command_line_arguments(task)
3554
r_function = functools.partial(r_function, r=args)
@@ -46,10 +65,11 @@ def pytask_collect_task(session, path, name, obj):
4665

4766

4867
def _create_command_line_arguments(task):
49-
args = get_markers_from_task(task, "r")[0].args
50-
if args:
51-
out = list(args)
52-
else:
53-
out = ["--vanilla"]
68+
r_marks = get_specific_markers_from_task(task, "r")
69+
mark = r_marks[0]
70+
for mark_ in r_marks[1:]:
71+
mark = mark.combine_with(mark_)
72+
73+
options = r(*mark.args, **mark.kwargs)
5474

55-
return out
75+
return options

src/pytask_r/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from _pytask.config import hookimpl
2+
3+
4+
@hookimpl
5+
def pytask_parse_config(config):
6+
config["markers"]["r"] = "r: Tasks which are executed with Rscript."

src/pytask_r/execute.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import shutil
22

3-
import pytask
4-
from pytask.mark import get_markers_from_task
5-
from pytask.nodes import FilePathNode
3+
from _pytask.config import hookimpl
4+
from _pytask.mark import get_specific_markers_from_task
5+
from _pytask.nodes import FilePathNode
66

77

8-
@pytask.hookimpl
8+
@hookimpl
99
def pytask_execute_task_setup(task):
10-
if get_markers_from_task(task, "r"):
10+
if get_specific_markers_from_task(task, "r"):
1111
if shutil.which("Rscript") is None:
1212
raise RuntimeError(
1313
"Rscript is needed to run R scripts, but it is not found on your PATH."

0 commit comments

Comments
 (0)