Skip to content

Commit

Permalink
Add _DRIVE_ROOT, closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
John B Nelson committed Oct 26, 2017
1 parent 9d41f63 commit 7b2c709
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pathsjson/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ def patch_with_user_globals(data, skip_noexist=True):
return data


def inject_special_variables(data, file_path):
env = data['__ENV']

if '_IMPLICIT_ROOT' not in env:
env['_IMPLICIT_ROOT'] = os.path.abspath(os.path.dirname(file_path))

if '_DRIVE_ROOT' not in env:
env['_DRIVE_ROOT'] = os.path.abspath(os.sep)

return data


class PathsJSON:

def __init__(self, file_path=None, src_dir=None, target_name=".paths.json",
Expand All @@ -218,9 +230,7 @@ def __init__(self, file_path=None, src_dir=None, target_name=".paths.json",
if enable_env_overrides:
data = patch_with_env(data)

if add_implicit_root and '_IMPLICIT_ROOT' not in data['__ENV']:
implicit_root = os.path.abspath(os.path.dirname(file_path))
data['__ENV']['_IMPLICIT_ROOT'] = implicit_root
inject_special_variables(data, file_path)

if validate:
with open(SCHEMA_FILE) as fp:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_pathsjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def test_to_path_strs(self):
"test_dir": (os.path.join("data", "tests"), [], [])}
self.assertEqual(path_strs, expected)

def test_root_paths(self):
data = {"__ENV": {}, "user_bin": ["$$_DRIVE_ROOT", "usr", "bin"]}
inject_special_variables(data, FIXTURES_DIR)
path_strs = to_path_strs(expand(data))
self.assertEqual(path_strs['user_bin'][0], '{}/usr/bin')

def test_find_pathsjson_file_asc(self):
res = find_file_asc(MOCK_LEAF, "test_target")
self.assertTrue(res.endswith("test_target"))
Expand Down

0 comments on commit 7b2c709

Please sign in to comment.