Skip to content

Commit

Permalink
fix relative_path (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeldmann committed Mar 28, 2024
1 parent cc2cb95 commit 2ba48a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion organize/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def relative_path(self) -> Optional[Path]:
return self.path
if self.path is None:
return None
return self.path.relative_to(self.basedir)
try:
return self.path.relative_to(self.basedir)
except ValueError:
# path is not relative to basedir
return None

def dict(self):
return dict(
Expand Down
15 changes: 15 additions & 0 deletions tests/core/test_relativepath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from conftest import make_files

from organize import Config


def test_relative_path(fs):
make_files(["test.txt"], "test")
conf = """
rules:
- locations: /test
actions:
- move: "/other/path/"
- echo: "{relative_path}"
"""
Config.from_string(conf).execute(simulate=False)

0 comments on commit 2ba48a9

Please sign in to comment.