File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## 0.1.3 (unreleased)
4
4
5
+ New:
6
+
7
+ * project: ` NIAR_WORKING_DIRECTORY ` can be used to override the origin.
8
+
5
9
## 0.1.2
6
10
7
11
New:
Original file line number Diff line number Diff line change
1
+ import os
1
2
import sys
2
3
from pathlib import Path
3
4
from typing import Optional
@@ -100,16 +101,21 @@ class Project:
100
101
]
101
102
102
103
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 )
113
119
114
120
extras = cls .__dict__ .keys () - {"__module__" , "__doc__" , "origin" }
115
121
for prop in cls .PROPS :
You can’t perform that action at this time.
0 commit comments