Skip to content

Commit 9e996a5

Browse files
authoredNov 2, 2023
Move .pytask.sqlite3 to .pytask/. (#470)
1 parent 32e02f8 commit 9e996a5

18 files changed

+41
-31
lines changed
 

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ _generated
1414
*.egg-info
1515
.eggs
1616

17-
.pytask.sqlite3
1817
.pytask
1918

2019
build

‎docs/source/changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
2020
- {pull}`464` improves pinned dependencies.
2121
- {pull}`465` adds test to ensure internal tracebacks are removed by reports.
2222
- {pull}`466` implements hashing for files instead of modification timestamps.
23+
- {pull}`470` moves `.pytask.sqlite3` to `.pytask`.
2324
- {pull}`472` adds `is_product` to {meth}`PNode.load`.
2425

2526
## 0.4.1 - 2023-10-11

‎docs/source/how_to_guides/bp_scaling_tasks.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ my_project
4242
4343
├───setup.py
4444
45-
├───.pytask.sqlite3
45+
├───.pytask
46+
│ └────...
4647
4748
└───bld
4849
```

‎docs/source/how_to_guides/functional_interface.ipynb

+2-2
Large diffs are not rendered by default.

‎docs/source/reference_guides/configuration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ are welcome to also support macOS.
4646
4747
pytask uses a database to keep track of tasks, products, and dependencies over runs. By
4848
default, it will create an SQLite database in the project's root directory called
49-
`.pytask.sqlite3`. If you want to use a different name or a different dialect
49+
`.pytask/pytask.sqlite3`. If you want to use a different name or a different dialect
5050
[supported by sqlalchemy](https://docs.sqlalchemy.org/en/latest/core/engines.html#backend-specific-urls),
5151
use either {option}`pytask build --database-url` or `database_url` in the config.
5252
5353
```toml
54-
database_url = "sqlite:///.pytask.sqlite3"
54+
database_url = "sqlite:///.pytask/pytask.sqlite3"
5555
```
5656
5757
Relative paths for SQLite databases are interpreted as either relative to the

‎docs/source/tutorials/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pytask can be configured via the command-line interface or permanently with a
44
`pyproject.toml` file.
55

66
The file also indicates the root of your project where pytask stores information in a
7-
`.pytask.sqlite3` database.
7+
`.pytask` folder.
88

99
## The configuration file
1010

‎docs/source/tutorials/defining_dependencies_products.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ my_project
3333
3434
├───setup.py
3535
36-
├───.pytask.sqlite3
36+
├───.pytask
37+
│ └────...
3738
3839
└───bld
3940
├────data.pkl

‎docs/source/tutorials/set_up_a_project.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ my_project
2424
2525
├───pyproject.toml
2626
27-
├───.pytask.sqlite3
27+
├───.pytask
28+
│ └────...
2829
2930
└───bld
3031
└────...
@@ -42,8 +43,8 @@ paths = "src/my_project"
4243

4344
You do not have to add configuration values, but you need the
4445
`[tool.pytask.ini_options]` header. The header alone will signal pytask that this is the
45-
project's root. pytask will store the information it needs across executions in a
46-
`.pytask.sqlite3` database next to the configuration file.
46+
project's root. pytask will store the information it needs across executions in the
47+
`.pytask` folder.
4748

4849
`paths` allows you to set the location of tasks when you do not pass them explicitly via
4950
the CLI.

‎docs/source/tutorials/using_a_data_catalog.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ The project structure is the same as in the previous example with the exception
2121

2222
```text
2323
my_project
24-
├───.pytask
2524
2625
├───pyproject.toml
2726
@@ -33,7 +32,8 @@ my_project
3332
3433
├───setup.py
3534
36-
├───.pytask.sqlite3
35+
├───.pytask
36+
│ └────...
3737
3838
└───bld
3939
└────plot.png
@@ -166,7 +166,6 @@ Let's add `file.csv` to the data catalog.
166166

167167
```text
168168
my_project
169-
├───.pytask
170169
171170
├───pyproject.toml
172171
@@ -179,7 +178,8 @@ my_project
179178
180179
├───setup.py
181180
182-
├───.pytask.sqlite3
181+
├───.pytask
182+
│ └────...
183183
184184
└───bld
185185
├────file.pkl

‎docs/source/tutorials/write_a_task.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ automatically discovers them.
1212

1313
```text
1414
my_project
15+
1516
├───pyproject.toml
1617
1718
├───src
@@ -21,7 +22,8 @@ my_project
2122
2223
├───setup.py
2324
24-
├───.pytask.sqlite3
25+
├───.pytask
26+
│ └────...
2527
2628
└───bld
2729
└────data.pkl

‎src/_pytask/build.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import json
55
import sys
6+
from contextlib import suppress
67
from pathlib import Path
78
from typing import Any
89
from typing import Callable
@@ -45,22 +46,19 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
4546
@hookimpl
4647
def pytask_post_parse(config: dict[str, Any]) -> None:
4748
"""Fill cache of file hashes with stored hashes."""
48-
try:
49+
with suppress(Exception):
4950
path = config["root"] / ".pytask" / "file_hashes.json"
5051
cache = json.loads(path.read_text())
51-
except Exception: # noqa: BLE001
52-
cache = {}
5352

54-
for key, value in cache.items():
55-
HashPathCache.add(key, value)
53+
for key, value in cache.items():
54+
HashPathCache.add(key, value)
5655

5756

5857
@hookimpl
5958
def pytask_unconfigure(session: Session) -> None:
6059
"""Save calculated file hashes to file."""
61-
path = session.config["root"] / ".pytask"
62-
path.mkdir(exist_ok=True, parents=True)
63-
path.joinpath("file_hashes.json").write_text(json.dumps(HashPathCache._cache))
60+
path = session.config["root"] / ".pytask" / "file_hashes.json"
61+
path.write_text(json.dumps(HashPathCache._cache))
6462

6563

6664
def build( # noqa: C901, PLR0912, PLR0913

‎src/_pytask/config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def pytask_configure(
6868
config["markers"] = parse_markers(config["markers"])
6969

7070
pm.hook.pytask_parse_config(config=config)
71-
7271
pm.hook.pytask_post_parse(config=config)
7372

7473
return config
@@ -77,6 +76,8 @@ def pytask_configure(
7776
@hookimpl
7877
def pytask_parse_config(config: dict[str, Any]) -> None:
7978
"""Parse the configuration."""
79+
config["root"].joinpath(".pytask").mkdir(exist_ok=True, parents=True)
80+
8081
config["paths"] = parse_paths(config["paths"])
8182

8283
config["markers"] = {

‎src/_pytask/database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
1515
# Set default.
1616
if not config["database_url"]:
1717
config["database_url"] = make_url(
18-
f"sqlite:///{config['root'].as_posix()}/.pytask.sqlite3"
18+
f"sqlite:///{config['root'].joinpath('.pytask').as_posix()}/pytask.sqlite3"
1919
)
2020

2121
if (

‎src/_pytask/parameters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _database_url_callback(
9191
type=str,
9292
help=("Url to the database."),
9393
default=None,
94-
show_default="sqlite:///.../.pytask.sqlite3",
94+
show_default="sqlite:///.../.pytask/pytask.sqlite3",
9595
callback=_database_url_callback,
9696
)
9797

‎tests/test_clean.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_clean_database_ignored(project, runner):
9494
text_without_linebreaks = result.output.replace("\n", "")
9595
assert "to_be_deleted_file_1.txt" in text_without_linebreaks
9696
assert "to_be_deleted_file_2.txt" in text_without_linebreaks
97-
assert ".pytask.sqlite3" not in text_without_linebreaks
97+
assert "pytask.sqlite3" not in text_without_linebreaks
9898

9999

100100
@pytest.mark.end_to_end()

‎tests/test_database.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def task_write(depends_on, produces):
3333
assert result.exit_code == ExitCode.OK
3434

3535
create_database(
36-
make_url("sqlite:///" + tmp_path.joinpath(".pytask.sqlite3").as_posix())
36+
make_url(
37+
"sqlite:///" + tmp_path.joinpath(".pytask", "pytask.sqlite3").as_posix()
38+
)
3739
)
3840

3941
with DatabaseSession() as session:

‎tests/test_persist.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def task_dummy(depends_on, produces):
6767
assert session.execution_reports[0].outcome == TaskOutcome.PERSISTENCE
6868
assert isinstance(session.execution_reports[0].exc_info[1], Persisted)
6969

70-
create_database("sqlite:///" + tmp_path.joinpath(".pytask.sqlite3").as_posix())
70+
create_database(
71+
"sqlite:///" + tmp_path.joinpath(".pytask", "pytask.sqlite3").as_posix()
72+
)
7173

7274
with DatabaseSession() as session:
7375
task_id = tmp_path.joinpath("task_module.py").as_posix() + "::task_dummy"

‎tests/test_profile.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def task_example(): time.sleep(2)
3030
duration = task.attributes["duration"]
3131
assert duration[1] - duration[0] > 2
3232

33-
create_database("sqlite:///" + tmp_path.joinpath(".pytask.sqlite3").as_posix())
33+
create_database(
34+
"sqlite:///" + tmp_path.joinpath(".pytask", "pytask.sqlite3").as_posix()
35+
)
3436

3537
with DatabaseSession() as session:
3638
task_name = tmp_path.joinpath("task_example.py").as_posix() + "::task_example"

0 commit comments

Comments
 (0)
Please sign in to comment.