Skip to content

Move .pytask.sqlite3 to .pytask/. #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
82859e7
Draft datastore.
tobiasraabe Sep 18, 2023
47d0fd6
Merge remote-tracking branch 'origin/main' into draft-datastore
tobiasraabe Sep 18, 2023
4001f98
Finish draft of data catalog.
tobiasraabe Sep 18, 2023
93e6da0
Fix tests.
tobiasraabe Sep 18, 2023
9524c30
more data catalog.
tobiasraabe Sep 19, 2023
f45ad78
Merge branch 'main' into draft-datastore
tobiasraabe Oct 12, 2023
891f4a6
Allow to use the datastore independent of pytask.
tobiasraabe Oct 14, 2023
49e684f
Add deepdiff for tests.
tobiasraabe Oct 14, 2023
90fb3f7
Merge branch 'main' into draft-datastore
tobiasraabe Oct 15, 2023
f5948d9
Add collection to data store.
tobiasraabe Oct 15, 2023
dc204c1
Merge branch 'main' into draft-datastore
tobiasraabe Oct 16, 2023
8457c86
Add some tests.
tobiasraabe Oct 17, 2023
9a14830
better docs.
tobiasraabe Oct 17, 2023
d9f6493
Merge branch 'main' into draft-datastore
tobiasraabe Oct 17, 2023
99dd59a
more test.
tobiasraabe Oct 17, 2023
88bf7a9
Merge branch 'main' into draft-datastore
tobiasraabe Oct 18, 2023
7ed8612
Merge branch 'main' into draft-datastore
tobiasraabe Oct 18, 2023
3e14cf8
fix.
tobiasraabe Oct 20, 2023
5282bf3
Merge branch 'main' into draft-datastore
tobiasraabe Oct 21, 2023
51242b6
Merge branch 'main' into draft-datastore
tobiasraabe Oct 25, 2023
d3ccb4a
extend guide.
tobiasraabe Oct 25, 2023
e018a2c
fix.
tobiasraabe Oct 25, 2023
eb2d973
Merge branch 'main' into draft-datastore
tobiasraabe Oct 25, 2023
552c8e8
Fix version.
tobiasraabe Oct 25, 2023
caccdc4
Merge branch 'main' into draft-datastore
tobiasraabe Oct 27, 2023
9208e3f
add more tests.
tobiasraabe Oct 27, 2023
5f5a4f5
Merge branch 'draft-datastore' of https://github.com/pytask-dev/pytas…
tobiasraabe Oct 27, 2023
391fc23
fix.
tobiasraabe Oct 27, 2023
adad36a
Revert some changes.
tobiasraabe Oct 27, 2023
f44d133
Move to hashing instead of modification times.
tobiasraabe Oct 27, 2023
58a4e1a
Move to hashing instead of modification times.
tobiasraabe Oct 27, 2023
a7f8c78
Fix.
tobiasraabe Oct 27, 2023
f502889
Remove unnecessary files.
tobiasraabe Oct 27, 2023
03e0c8f
Merge branch 'draft-datastore' into hashing
tobiasraabe Oct 28, 2023
06b628a
implement hashing of caching.
tobiasraabe Oct 28, 2023
94adeca
FIx.
tobiasraabe Oct 28, 2023
cac6dc6
Move .pytask.sqlite3 to .pytask.
tobiasraabe Oct 28, 2023
7b7b26d
TO changes.
tobiasraabe Oct 28, 2023
c745eba
Fix notebook.
tobiasraabe Oct 28, 2023
9dbfce3
fix.
tobiasraabe Oct 28, 2023
e0f634f
Merge branch 'main' into move-.pytask.sqlite
tobiasraabe Nov 2, 2023
5f05384
FIx.
tobiasraabe Nov 2, 2023
1706022
Remove .pytask.sqlite3 from file trees.
tobiasraabe Nov 2, 2023
70ae020
align.
tobiasraabe Nov 2, 2023
ed41598
align.
tobiasraabe Nov 2, 2023
b8d8365
Fixes.
tobiasraabe Nov 2, 2023
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ _generated
*.egg-info
.eggs

.pytask.sqlite3
.pytask

build
Expand Down
1 change: 1 addition & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
- {pull}`464` improves pinned dependencies.
- {pull}`465` adds test to ensure internal tracebacks are removed by reports.
- {pull}`466` implements hashing for files instead of modification timestamps.
- {pull}`470` moves `.pytask.sqlite3` to `.pytask`.
- {pull}`472` adds `is_product` to {meth}`PNode.load`.

## 0.4.1 - 2023-10-11
Expand Down
3 changes: 2 additions & 1 deletion docs/source/how_to_guides/bp_scaling_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ my_project
├───setup.py
├───.pytask.sqlite3
├───.pytask
│ └────...
└───bld
```
Expand Down
4 changes: 2 additions & 2 deletions docs/source/how_to_guides/functional_interface.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/source/reference_guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ are welcome to also support macOS.

pytask uses a database to keep track of tasks, products, and dependencies over runs. By
default, it will create an SQLite database in the project's root directory called
`.pytask.sqlite3`. If you want to use a different name or a different dialect
`.pytask/pytask.sqlite3`. If you want to use a different name or a different dialect
[supported by sqlalchemy](https://docs.sqlalchemy.org/en/latest/core/engines.html#backend-specific-urls),
use either {option}`pytask build --database-url` or `database_url` in the config.

```toml
database_url = "sqlite:///.pytask.sqlite3"
database_url = "sqlite:///.pytask/pytask.sqlite3"
```

Relative paths for SQLite databases are interpreted as either relative to the
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pytask can be configured via the command-line interface or permanently with a
`pyproject.toml` file.

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

## The configuration file

Expand Down
3 changes: 2 additions & 1 deletion docs/source/tutorials/defining_dependencies_products.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ my_project
├───setup.py
├───.pytask.sqlite3
├───.pytask
│ └────...
└───bld
├────data.pkl
Expand Down
7 changes: 4 additions & 3 deletions docs/source/tutorials/set_up_a_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ my_project
├───pyproject.toml
├───.pytask.sqlite3
├───.pytask
│ └────...
└───bld
└────...
Expand All @@ -42,8 +43,8 @@ paths = "src/my_project"

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

`paths` allows you to set the location of tasks when you do not pass them explicitly via
the CLI.
Expand Down
8 changes: 4 additions & 4 deletions docs/source/tutorials/using_a_data_catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ The project structure is the same as in the previous example with the exception

```text
my_project
├───.pytask
├───pyproject.toml
Expand All @@ -33,7 +32,8 @@ my_project
├───setup.py
├───.pytask.sqlite3
├───.pytask
│ └────...
└───bld
└────plot.png
Expand Down Expand Up @@ -166,7 +166,6 @@ Let's add `file.csv` to the data catalog.

```text
my_project
├───.pytask
├───pyproject.toml
Expand All @@ -179,7 +178,8 @@ my_project
├───setup.py
├───.pytask.sqlite3
├───.pytask
│ └────...
└───bld
├────file.pkl
Expand Down
4 changes: 3 additions & 1 deletion docs/source/tutorials/write_a_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ automatically discovers them.

```text
my_project
├───pyproject.toml
├───src
Expand All @@ -21,7 +22,8 @@ my_project
├───setup.py
├───.pytask.sqlite3
├───.pytask
│ └────...
└───bld
└────data.pkl
Expand Down
14 changes: 6 additions & 8 deletions src/_pytask/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
import sys
from contextlib import suppress
from pathlib import Path
from typing import Any
from typing import Callable
Expand Down Expand Up @@ -45,22 +46,19 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
@hookimpl
def pytask_post_parse(config: dict[str, Any]) -> None:
"""Fill cache of file hashes with stored hashes."""
try:
with suppress(Exception):
path = config["root"] / ".pytask" / "file_hashes.json"
cache = json.loads(path.read_text())
except Exception: # noqa: BLE001
cache = {}

for key, value in cache.items():
HashPathCache.add(key, value)
for key, value in cache.items():
HashPathCache.add(key, value)


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


def build( # noqa: C901, PLR0912, PLR0913
Expand Down
3 changes: 2 additions & 1 deletion src/_pytask/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def pytask_configure(
config["markers"] = parse_markers(config["markers"])

pm.hook.pytask_parse_config(config=config)

pm.hook.pytask_post_parse(config=config)

return config
Expand All @@ -77,6 +76,8 @@ def pytask_configure(
@hookimpl
def pytask_parse_config(config: dict[str, Any]) -> None:
"""Parse the configuration."""
config["root"].joinpath(".pytask").mkdir(exist_ok=True, parents=True)

config["paths"] = parse_paths(config["paths"])

config["markers"] = {
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
# Set default.
if not config["database_url"]:
config["database_url"] = make_url(
f"sqlite:///{config['root'].as_posix()}/.pytask.sqlite3"
f"sqlite:///{config['root'].joinpath('.pytask').as_posix()}/pytask.sqlite3"
)

if (
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _database_url_callback(
type=str,
help=("Url to the database."),
default=None,
show_default="sqlite:///.../.pytask.sqlite3",
show_default="sqlite:///.../.pytask/pytask.sqlite3",
callback=_database_url_callback,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_clean_database_ignored(project, runner):
text_without_linebreaks = result.output.replace("\n", "")
assert "to_be_deleted_file_1.txt" in text_without_linebreaks
assert "to_be_deleted_file_2.txt" in text_without_linebreaks
assert ".pytask.sqlite3" not in text_without_linebreaks
assert "pytask.sqlite3" not in text_without_linebreaks


@pytest.mark.end_to_end()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def task_write(depends_on, produces):
assert result.exit_code == ExitCode.OK

create_database(
make_url("sqlite:///" + tmp_path.joinpath(".pytask.sqlite3").as_posix())
make_url(
"sqlite:///" + tmp_path.joinpath(".pytask", "pytask.sqlite3").as_posix()
)
)

with DatabaseSession() as session:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def task_dummy(depends_on, produces):
assert session.execution_reports[0].outcome == TaskOutcome.PERSISTENCE
assert isinstance(session.execution_reports[0].exc_info[1], Persisted)

create_database("sqlite:///" + tmp_path.joinpath(".pytask.sqlite3").as_posix())
create_database(
"sqlite:///" + tmp_path.joinpath(".pytask", "pytask.sqlite3").as_posix()
)

with DatabaseSession() as session:
task_id = tmp_path.joinpath("task_module.py").as_posix() + "::task_dummy"
Expand Down
4 changes: 3 additions & 1 deletion tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def task_example(): time.sleep(2)
duration = task.attributes["duration"]
assert duration[1] - duration[0] > 2

create_database("sqlite:///" + tmp_path.joinpath(".pytask.sqlite3").as_posix())
create_database(
"sqlite:///" + tmp_path.joinpath(".pytask", "pytask.sqlite3").as_posix()
)

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