Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 0 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.



11 changes: 4 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ And in your ``script.jl``, you can intercept the value with

.. code-block:: Julia

FIXME FOR YOUR LANGUAGE
args <- commandArgs(trailingOnly=TRUE)
arg <- args[1] # holds ``"value"``
arg = ARGS[1] # holds ``"value"``


Parametrization
Expand All @@ -173,12 +171,11 @@ The following task executes two Julia scripts which produce different outputs.
def task_execute_julia_script():
pass

And the R script includes something like
And the Julia script includes something like

.. code-block:: r
.. code-block:: julia

args <- commandArgs(trailingOnly=TRUE)
produces <- args[1] # holds the path
produces = ARGS[1] # holds the path

If you want to pass different command line arguments to the same Julia script, you have to
include the ``@pytask.mark.julia`` decorator in the parametrization just like with
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
name = pytask-julia
name = pytask_julia
description = A Pytask plugin for Julia
long_description = file: README.rst
long_description_content_type = text/x-rst
Expand All @@ -18,7 +18,6 @@ classifiers =
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
project_urls =
Changelog = https://github.com/pytask-dev/pytask-julia/blob/main/CHANGES.rst
Documentation = https://github.com/pytask-dev/pytask-julia
Expand Down
4 changes: 1 addition & 3 deletions src/pytask_julia/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def pytask_collect_task_teardown(session, task):
"""Perform some checks."""
if get_specific_markers_from_task(task, "julia"):
source = _get_node_from_dictionary(task.depends_on, "source")
if isinstance(source, FilePathNode) and source.value.suffix not in [
".jl"
]:
if isinstance(source, FilePathNode) and source.value.suffix not in [".jl"]:
raise ValueError(
"The first dependency of a Julia task must be the script to be executed."
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from pytask_julia.collect import _get_node_from_dictionary
from pytask_julia.collect import _merge_all_markers
from pytask_julia.collect import _prepare_cmd_options
from pytask_julia.collect import julia
from pytask_julia.collect import pytask_collect_task
from pytask_julia.collect import pytask_collect_task_teardown
from pytask_julia.collect import julia


class DummyClass:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def task_run_jl_script():
and "source" not in depends_on
and 0 not in depends_on
):
tmp_path.joinpath("pytask.ini").write_text("[pytask]\njulia_source_key = script")
tmp_path.joinpath("pytask.ini").write_text(
"[pytask]\njulia_source_key = script"
)

os.chdir(tmp_path)
session = main({"paths": tmp_path})
Expand Down
23 changes: 11 additions & 12 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def task_execute_julia():
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(source))

julia_script = """FIXME FOR YOUR LANGUAGE
Sys.sleep(2)
saveRDS(1, file=paste0(1, ".csv"))
julia_script = """
sleep(0.5)
write("1.csv", "1")
"""
tmp_path.joinpath("script_1.jl").write_text(textwrap.dedent(julia_script))

r_script = """
Sys.sleep(2)
saveRDS(2, file=paste0(2, ".csv"))
julia_script = """
sleep(0.5)
write("2.csv", "2")
"""
tmp_path.joinpath("script_2.jl").write_text(textwrap.dedent(julia_script))

Expand Down Expand Up @@ -95,12 +95,11 @@ def task_execute_julia_script():
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(source))

julia_script = """FIXME FOR YOUR LANGUAGE
Sys.sleep(2)
args <- commandArgs(trailingOnly=TRUE)
number <- args[1]
produces <- args[2]
saveRDS(number, file=produces)
julia_script = """
number = ARGS[1]
produces = ARGS[2]
sleep(0.5)
write(produces, number)
"""
tmp_path.joinpath("script.jl").write_text(textwrap.dedent(julia_script))

Expand Down
46 changes: 22 additions & 24 deletions tests/test_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,28 @@

@needs_julia
@pytest.mark.end_to_end
def test_parametrized_execution_of_r_script(tmp_path):
def test_parametrized_execution_of_jl_script(tmp_path):
task_source = """
import pytask

@pytask.mark.julia
@pytask.mark.parametrize("depends_on, produces", [
("script_1.r", "0.txt"),
("script_2.r", "1.txt"),
("script_1.jl", "0.txt"),
("script_2.jl", "1.txt"),
])
def task_run_r_script():
def task_run_jl_script():
pass
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(task_source))

for name, content, out in [
("script_1.r", "Cities breaking down on a camel's back", "0.txt"),
("script_2.r", "They just have to go 'cause they don't know whack", "1.txt"),
("script_1.jl", "Cities breaking down on a camel's back", "0.txt"),
("script_2.jl", "They just have to go 'cause they don't know whack", "1.txt"),
]:
r_script = f"""
file_descr <- file("{out}")
writeLines(c("{content}"), file_descr)
close(file_descr)
julia_script = f"""
write("{out}", "{content}")
"""
tmp_path.joinpath(name).write_text(textwrap.dedent(r_script))
tmp_path.joinpath(name).write_text(textwrap.dedent(julia_script))

os.chdir(tmp_path)
session = main({"paths": tmp_path})
Expand All @@ -43,33 +41,33 @@ def task_run_r_script():

@needs_julia
@pytest.mark.end_to_end
def test_parametrize_r_options_and_product_paths(tmp_path):
def test_parametrize_jl_options_and_product_paths(tmp_path):
task_source = """
import pytask
from pathlib import Path

SRC = Path(__file__).parent

@pytask.mark.depends_on("script.r")
@pytask.mark.parametrize("produces, r", [
(SRC / "0.rds", (0, SRC / "0.rds")), (SRC / "1.rds", (1, SRC / "1.rds"))
@pytask.mark.depends_on("script.jl")
@pytask.mark.parametrize("produces, julia", [
(SRC / "0.csv", (0, SRC / "0.csv")), (SRC / "1.csv", (1, SRC / "1.csv"))
])
def task_execute_r_script():
def task_run_jl_script():
pass
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(task_source))

r_script = """
args <- commandArgs(trailingOnly=TRUE)
number <- args[1]
produces <- args[2]
saveRDS(number, file=produces)
julia_script = """
number = ARGS[1]
produces = ARGS[2]
write(produces, number)
"""
tmp_path.joinpath("script.r").write_text(textwrap.dedent(r_script))

tmp_path.joinpath("script.jl").write_text(textwrap.dedent(julia_script))

os.chdir(tmp_path)
session = main({"paths": tmp_path})

assert session.exit_code == 0
assert tmp_path.joinpath("0.rds").exists()
assert tmp_path.joinpath("1.rds").exists()
assert tmp_path.joinpath("0.csv").exists()
assert tmp_path.joinpath("1.csv").exists()