mirror of
https://git.sr.ht/~kivikakk/niar
synced 2024-12-22 17:32:25 +00:00
project: add NIAR_WORKING_DIRECTORY support.
This commit is contained in:
parent
96df013632
commit
bf3738f777
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## 0.1.3 (unreleased)
|
## 0.1.3 (unreleased)
|
||||||
|
|
||||||
|
New:
|
||||||
|
|
||||||
|
* project: `NIAR_WORKING_DIRECTORY` can be used to override the origin.
|
||||||
|
|
||||||
## 0.1.2
|
## 0.1.2
|
||||||
|
|
||||||
New:
|
New:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
@ -100,6 +101,9 @@ class Project:
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init_subclass__(cls):
|
def __init_subclass__(cls):
|
||||||
|
if origin := os.getenv("NIAR_WORKING_DIRECTORY"):
|
||||||
|
cls.origin = Path(origin).absolute()
|
||||||
|
else:
|
||||||
# We expect to be called from project-root/module/__init.py__ or similar;
|
# We expect to be called from project-root/module/__init.py__ or similar;
|
||||||
# cls.origin is project-root. Keep going up until we find pyproject.toml.
|
# cls.origin is project-root. Keep going up until we find pyproject.toml.
|
||||||
origin = Path(sys._getframe(1).f_code.co_filename).absolute().parent
|
origin = Path(sys._getframe(1).f_code.co_filename).absolute().parent
|
||||||
|
@ -111,6 +115,8 @@ class Project:
|
||||||
assert False, "could not find pyproject.toml"
|
assert False, "could not find pyproject.toml"
|
||||||
origin = origin.parent
|
origin = origin.parent
|
||||||
|
|
||||||
|
os.chdir(cls.origin)
|
||||||
|
|
||||||
extras = cls.__dict__.keys() - {"__module__", "__doc__", "origin"}
|
extras = cls.__dict__.keys() - {"__module__", "__doc__", "origin"}
|
||||||
for prop in cls.PROPS:
|
for prop in cls.PROPS:
|
||||||
prop.validate(cls)
|
prop.validate(cls)
|
||||||
|
|
Loading…
Reference in a new issue