Skip to content

Commit

Permalink
Merge f471328 into 4771d3c
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Mar 27, 2022
2 parents 4771d3c + f471328 commit ca2b2fb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# 1.3 (alpha)

- Added support for paths relative to the user's home directory.

# 1.2 (2022-02-24)

- Added a `frozen()` context manager to temporarily disable file updates.
Expand Down
2 changes: 2 additions & 0 deletions datafiles/mapper.py
Expand Up @@ -54,6 +54,8 @@ def path(self) -> Optional[Path]:
path = Path(self._pattern.format(self=self._instance))
if path.is_absolute() or self._pattern.startswith("./"):
return path.resolve()
if self._pattern.startswith("~/"):
return path.expanduser()

cls = self._instance.__class__
try:
Expand Down
5 changes: 5 additions & 0 deletions datafiles/tests/test_mapper.py
Expand Up @@ -58,6 +58,11 @@ def is_relative_to_cwd_when_specified(expect, mapper):
path = Path.cwd() / "foobar" / "sample.yml"
expect(mapper.path) == path

def is_relative_to_home_when_specified(expect, mapper):
mapper._pattern = "~/foobar/sample.yml"
path = Path.home() / "foobar" / "sample.yml"
expect(mapper.path) == path

def describe_relpath():
def when_cwd_is_parent(expect, mapper):
mapper._pattern = "../../tmp/sample.yml"
Expand Down
1 change: 1 addition & 0 deletions docs/api/model.md
Expand Up @@ -57,6 +57,7 @@ Filename patterns are relative to the file in which the model is defined unless
- Absolute: `/tmp/items/{self.name}.yml`
- Relative to model: `items/{self.name}.yml`
- Relative to current directory: `./items/{self.name}.yml`
- Relative to the user's home directory: `~/items/{self.name}.yml`

Attributes included in the filename pattern and those with default value are automatically excluded from serialization since these redundant values are not required to restore objects from disk.

Expand Down
4 changes: 0 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,7 +1,7 @@
[tool.poetry]

name = "datafiles"
version = "1.2"
version = "1.3a1"
description = "File-based ORM for dataclasses."

license = "MIT"
Expand Down

0 comments on commit ca2b2fb

Please sign in to comment.