Skip to content

Commit 94a9336

Browse files
authored
Name files of serialized arguments with uuid. (#33)
1 parent c573edb commit 94a9336

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask-julia) and
77

88
## 0.x.x - 2024-xx-xx
99

10-
- {pull}`32` uses trusted publishing for PyPI.
1110
- {pull}`31` uses pixi to provision Julia if possible.
11+
- {pull}`32` uses trusted publishing for PyPI.
12+
- {pull}`33` uses uuid4 to generate more robust file names for serialized arguments.
1213

1314
## 0.4.0 - 2023-10-08
1415

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ You also need to have Julia installed and `julia` on your command line. Test it
3131
typing the following on the command line
3232

3333
```console
34-
$ julia -h
34+
julia -h
3535
```
3636

3737
If an error is shown instead of a help page, you can install Julia on Unix systems with
3838

3939
```console
40-
$ conda install -c conda-forge julia
40+
conda install -c conda-forge julia
4141
```
4242

4343
or choose one of the installers on this [page](https://julialang.org/downloads/).
4444

4545
## Usage
4646

47-
To create a task which runs a Julia script, define a task function with the
47+
To create a task that runs a Julia script, define a task function with the
4848
`@pytask.mark.julia` decorator. The `script` keyword provides a path relative to the
4949
task module to the Julia script.
5050

@@ -111,11 +111,11 @@ config["number"] # Is 1.
111111
### Debugging
112112

113113
In case a task throws an error, you might want to execute the script independently from
114-
pytask. After a failed execution, you see the command which executed the Julia script in
114+
pytask. After a failed execution, you see the command that executed the Julia script in
115115
the report of the task. It looks roughly like this
116116

117117
```console
118-
$ julia <options> -- script.jl <path-to>/.pytask/task_py_task_example.json
118+
julia <options> -- script.jl <path-to>/.pytask/pytask-julia/<uuid>.json
119119
```
120120

121121
### Managing Julia environments
@@ -150,7 +150,7 @@ def task_run_jl_script():
150150

151151
### Command Line Options
152152

153-
Command line options can be pass via the `options` keyword argument.
153+
Command line options can be passed via the `options` keyword argument.
154154

155155
```python
156156
@task(kwargs={"path": Path("out.csv")})
@@ -159,7 +159,7 @@ def task_run_jl_script():
159159
pass
160160
```
161161

162-
This example will execute the script using to threads.
162+
This example will execute the script using threads.
163163

164164
### Repeating tasks with different scripts or inputs
165165

@@ -225,8 +225,8 @@ config = YAML.load_file(ARGS[1])
225225

226226
Note that the `YAML` package needs to be installed.
227227

228-
If you need a custom serializer, you can also provide any callable to `serializer` which
229-
transforms data to a string. Use `suffix` to set the correct file ending.
228+
If you need a custom serializer, you can also provide any callable for `serializer`
229+
which transforms data into a string. Use `suffix` to set the correct file ending.
230230

231231
Here is a replication of the JSON example.
232232

@@ -255,7 +255,7 @@ julia_serializer = "json"
255255
**`julia_suffix`**
256256

257257
Use this option to set the default suffix of the file which contains serialized paths to
258-
dependencies and products and more.
258+
dependencies, products and more.
259259

260260
```toml
261261
[tool.pytask.ini_options]

src/pytask_julia/serialization.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
from __future__ import annotations
44

55
import json
6+
import uuid
67
from pathlib import Path
78
from typing import Any
89
from typing import Callable
910

1011
from pytask import PTask
1112
from pytask import PTaskWithPath
1213

14+
__all__ = ["create_path_to_serialized", "serialize_keyword_arguments", "SERIALIZERS"]
15+
1316
_HIDDEN_FOLDER = ".pytask/pytask-julia"
1417

1518

@@ -28,25 +31,10 @@
2831

2932
def create_path_to_serialized(task: PTask, suffix: str) -> Path:
3033
"""Create path to serialized."""
31-
parent = task.path.parent if isinstance(task, PTaskWithPath) else Path.cwd()
32-
file_name = create_file_name(task, suffix)
33-
return parent.joinpath(_HIDDEN_FOLDER, file_name).with_suffix(suffix)
34-
35-
36-
def create_file_name(task: PTask, suffix: str) -> str:
37-
"""Create the file name of the file containing the serialized kwargs.
38-
39-
Some characters need to be escaped since they are not valid characters on file
40-
systems.
41-
42-
"""
4334
return (
44-
task.name.replace("[", "_")
45-
.replace("]", "_")
46-
.replace("::", "_")
47-
.replace(".", "_")
48-
.replace("/", "_")
49-
+ suffix
35+
(task.path.parent if isinstance(task, PTaskWithPath) else Path.cwd())
36+
.joinpath(_HIDDEN_FOLDER, str(uuid.uuid4()))
37+
.with_suffix(suffix)
5038
)
5139

5240

0 commit comments

Comments
 (0)