Skip to content

Commit

Permalink
Use relative path when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Nov 21, 2023
1 parent 69aa190 commit 8838340
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 7 additions & 6 deletions cutekit/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ def build(
all = False
shell.mkdir(target.builddir)
ninjaPath = os.path.join(target.builddir, "build.ninja")
with open(ninjaPath, "w") as f:
gen(f, target, registry)

if not os.path.exists(ninjaPath):
with open(ninjaPath, "w") as f:
gen(f, target, registry)

if components is None:
all = True
Expand All @@ -228,10 +230,9 @@ def build(
)

outs = list(map(lambda p: str(p.path), products))
if all:
shell.exec("ninja", "-f", ninjaPath)
else:
shell.exec("ninja", "-f", ninjaPath, *outs)

shell.exec("ninja", "-f", ninjaPath, *(outs if not all else []))

return products


Expand Down
13 changes: 6 additions & 7 deletions cutekit/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def dirname(self) -> str:
"""
Return the directory of the manifest
"""
return os.path.dirname(self.path)
return os.path.relpath(os.path.dirname(self.path), Path.cwd())

def subpath(self, path) -> Path:
return Path(self.dirname()) / path
Expand Down Expand Up @@ -121,19 +121,18 @@ def topmost() -> Optional["Project"]:

@staticmethod
def ensure() -> "Project":
"""
Ensure that a project exists in the current directory or any parent directory
and chdir to the root of the project.
"""
project = Project.topmost()
if project is None:
raise RuntimeError(
"No project found in this directory or any parent directory"
)
os.chdir(project.dirname())
return project

def chdir(self):
"""
Change the current working directory to the root of the project
"""
os.chdir(self.dirname())

@staticmethod
def at(path: Path) -> Optional["Project"]:
projectManifest = Manifest.tryLoad(path / "project")
Expand Down

0 comments on commit 8838340

Please sign in to comment.