Skip to content

Commit bf3738f

Browse files
committed
project: add NIAR_WORKING_DIRECTORY support.
1 parent 96df013 commit bf3738f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 0.1.3 (unreleased)
44

5+
New:
6+
7+
* project: `NIAR_WORKING_DIRECTORY` can be used to override the origin.
8+
59
## 0.1.2
610

711
New:

niar/project.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
from pathlib import Path
34
from typing import Optional
@@ -100,16 +101,21 @@ class Project:
100101
]
101102

102103
def __init_subclass__(cls):
103-
# We expect to be called from project-root/module/__init.py__ or similar;
104-
# cls.origin is project-root. Keep going up until we find pyproject.toml.
105-
origin = Path(sys._getframe(1).f_code.co_filename).absolute().parent
106-
while True:
107-
if (origin / "pyproject.toml").is_file():
108-
cls.origin = origin
109-
break
110-
if not any(origin.parents):
111-
assert False, "could not find pyproject.toml"
112-
origin = origin.parent
104+
if origin := os.getenv("NIAR_WORKING_DIRECTORY"):
105+
cls.origin = Path(origin).absolute()
106+
else:
107+
# We expect to be called from project-root/module/__init.py__ or similar;
108+
# cls.origin is project-root. Keep going up until we find pyproject.toml.
109+
origin = Path(sys._getframe(1).f_code.co_filename).absolute().parent
110+
while True:
111+
if (origin / "pyproject.toml").is_file():
112+
cls.origin = origin
113+
break
114+
if not any(origin.parents):
115+
assert False, "could not find pyproject.toml"
116+
origin = origin.parent
117+
118+
os.chdir(cls.origin)
113119

114120
extras = cls.__dict__.keys() - {"__module__", "__doc__", "origin"}
115121
for prop in cls.PROPS:

0 commit comments

Comments
 (0)