Skip to content

Commit

Permalink
Fix ORM methods to handle relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Feb 9, 2020
1 parent b3dd417 commit fe9f0a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.7 (unreleased)

- Added a `YAML_LIBRARY` setting to control the underlying YAML library.
- Fixed ORM methods to handle relative file patterns.

# 0.6 (2020-01-25)

Expand Down
2 changes: 1 addition & 1 deletion datafiles/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def extensions(cls):
def deserialize(cls, file_object):
import yaml

data = yaml.safe_load(file_object)
data = yaml.safe_load(file_object) or {}

return data

Expand Down
9 changes: 7 additions & 2 deletions datafiles/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ def get_or_create(self, *args, **kwargs) -> HasDatafile:
return self.model(*args, **kwargs)

def all(self) -> Iterator[HasDatafile]:
root = Path(inspect.getfile(self.model)).parent
pattern = str(root / self.model.Meta.datafile_pattern)
path = Path(self.model.Meta.datafile_pattern)
if path.is_absolute() or self.model.Meta.datafile_pattern.startswith('./'):
pattern = str(path.resolve())
else:
root = Path(inspect.getfile(self.model)).parent
pattern = str(root / self.model.Meta.datafile_pattern)

splatted = pattern.format(self=Splats())
log.info(f'Finding files matching pattern: {splatted}')
for filename in iglob(splatted):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "datafiles"
version = "0.7b2"
version = "0.7b3"
description = "File-based ORM for dataclasses."

license = "MIT"
Expand Down

0 comments on commit fe9f0a0

Please sign in to comment.