Compare commits
1 commit
stable
...
rfc_pkgmng
Author | SHA1 | Date | |
---|---|---|---|
|
109c910e11 |
7 changed files with 89 additions and 24 deletions
4
.github/workflows/checks.yml
vendored
4
.github/workflows/checks.yml
vendored
|
@ -13,12 +13,12 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: '3.11'
|
python-version: '3.x'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
|
7
.github/workflows/publish.yml
vendored
7
.github/workflows/publish.yml
vendored
|
@ -20,14 +20,11 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v3
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: '3.11'
|
python-version: '3.x'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
|
|
|
@ -6,6 +6,7 @@ from . import (
|
||||||
builder, # noqa: F401 this is imported for side effects
|
builder, # noqa: F401 this is imported for side effects
|
||||||
cli,
|
cli,
|
||||||
const,
|
const,
|
||||||
|
get, # noqa: F401 this is imported for side effects
|
||||||
graph, # noqa: F401 this is imported for side effects
|
graph, # noqa: F401 this is imported for side effects
|
||||||
model,
|
model,
|
||||||
plugins,
|
plugins,
|
||||||
|
|
|
@ -203,10 +203,8 @@ def build(
|
||||||
all = False
|
all = False
|
||||||
shell.mkdir(target.builddir)
|
shell.mkdir(target.builddir)
|
||||||
ninjaPath = os.path.join(target.builddir, "build.ninja")
|
ninjaPath = os.path.join(target.builddir, "build.ninja")
|
||||||
|
with open(ninjaPath, "w") as f:
|
||||||
if not os.path.exists(ninjaPath):
|
gen(f, target, registry)
|
||||||
with open(ninjaPath, "w") as f:
|
|
||||||
gen(f, target, registry)
|
|
||||||
|
|
||||||
if components is None:
|
if components is None:
|
||||||
all = True
|
all = True
|
||||||
|
@ -230,9 +228,10 @@ def build(
|
||||||
)
|
)
|
||||||
|
|
||||||
outs = list(map(lambda p: str(p.path), products))
|
outs = list(map(lambda p: str(p.path), products))
|
||||||
|
if all:
|
||||||
shell.exec("ninja", "-f", ninjaPath, *(outs if not all else []))
|
shell.exec("ninja", "-f", ninjaPath)
|
||||||
|
else:
|
||||||
|
shell.exec("ninja", "-f", ninjaPath, *outs)
|
||||||
return products
|
return products
|
||||||
|
|
||||||
|
|
||||||
|
@ -244,9 +243,9 @@ def buildCmd(args: cli.Args):
|
||||||
registry = model.Registry.use(args)
|
registry = model.Registry.use(args)
|
||||||
target = model.Target.use(args)
|
target = model.Target.use(args)
|
||||||
componentSpec = args.consumeArg()
|
componentSpec = args.consumeArg()
|
||||||
component = None
|
if componentSpec is None:
|
||||||
if componentSpec is not None:
|
raise RuntimeError("No component specified")
|
||||||
component = registry.lookup(componentSpec, model.Component)
|
component = registry.lookup(componentSpec, model.Component)
|
||||||
build(target, registry, component)[0]
|
build(target, registry, component)[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
67
cutekit/get.py
Normal file
67
cutekit/get.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
from . import cli
|
||||||
|
from . import const
|
||||||
|
from . import model
|
||||||
|
from . import shell
|
||||||
|
|
||||||
|
import dataclasses as dt
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@dt.dataclass
|
||||||
|
class InstallManifest:
|
||||||
|
plugins: list[str]
|
||||||
|
targets: list[str]
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("G", "get", "Get a package from a remote repository")
|
||||||
|
def getCmd(args: cli.Args):
|
||||||
|
pkg = args.consumeArg()
|
||||||
|
repo = args.consumeOpt(
|
||||||
|
"repository", "https://github.com/cute-engineering/cutekit-contrib.git"
|
||||||
|
)
|
||||||
|
|
||||||
|
project = model.Project.topmost()
|
||||||
|
|
||||||
|
if project is None:
|
||||||
|
raise RuntimeError("Not inside a project")
|
||||||
|
|
||||||
|
if pkg is None:
|
||||||
|
raise RuntimeError("No package specified")
|
||||||
|
|
||||||
|
with TemporaryDirectory() as temp:
|
||||||
|
try:
|
||||||
|
shell.cloneDir(repo, pkg, temp)
|
||||||
|
except FileNotFoundError:
|
||||||
|
raise RuntimeError(f"Package {pkg} not found")
|
||||||
|
|
||||||
|
pkg_path = Path(temp) / pkg
|
||||||
|
|
||||||
|
with (pkg_path / "install.json").open("r") as f:
|
||||||
|
manifest_json = json.load(f)
|
||||||
|
|
||||||
|
[
|
||||||
|
manifest_json.setdefault(key, [])
|
||||||
|
for key in InstallManifest.__dataclass_fields__.keys()
|
||||||
|
]
|
||||||
|
|
||||||
|
manifest = InstallManifest(**manifest_json)
|
||||||
|
|
||||||
|
plugin_dir = Path(const.META_DIR) / "plugins"
|
||||||
|
target_dir = Path(const.TARGETS_DIR)
|
||||||
|
|
||||||
|
plugin_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
target_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
for plugin in manifest.plugins:
|
||||||
|
_logger.info(f"Copying {plugin} to {project.id}'s plugins")
|
||||||
|
shell.cp(str(pkg_path / plugin), plugin_dir)
|
||||||
|
|
||||||
|
for target in manifest.targets:
|
||||||
|
_logger.info(f"Copying {plugin} to {project.id}'s targets")
|
||||||
|
shell.cp(str(pkg_path / target), target_dir)
|
|
@ -71,7 +71,7 @@ class Manifest(DataClassJsonMixin):
|
||||||
"""
|
"""
|
||||||
Return the directory of the manifest
|
Return the directory of the manifest
|
||||||
"""
|
"""
|
||||||
return os.path.relpath(os.path.dirname(self.path), Path.cwd())
|
return os.path.dirname(self.path)
|
||||||
|
|
||||||
def subpath(self, path) -> Path:
|
def subpath(self, path) -> Path:
|
||||||
return Path(self.dirname()) / path
|
return Path(self.dirname()) / path
|
||||||
|
@ -121,18 +121,19 @@ class Project(Manifest):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ensure() -> "Project":
|
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()
|
project = Project.topmost()
|
||||||
if project is None:
|
if project is None:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"No project found in this directory or any parent directory"
|
"No project found in this directory or any parent directory"
|
||||||
)
|
)
|
||||||
os.chdir(project.dirname())
|
|
||||||
return project
|
return project
|
||||||
|
|
||||||
|
def chdir(self):
|
||||||
|
"""
|
||||||
|
Change the current working directory to the root of the project
|
||||||
|
"""
|
||||||
|
os.chdir(self.dirname())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def at(path: Path) -> Optional["Project"]:
|
def at(path: Path) -> Optional["Project"]:
|
||||||
projectManifest = Manifest.tryLoad(path / "project")
|
projectManifest = Manifest.tryLoad(path / "project")
|
||||||
|
|
|
@ -12,7 +12,7 @@ authors = [
|
||||||
{ name = "Cute Engineering", email = "contact@cute.engineering" },
|
{ name = "Cute Engineering", email = "contact@cute.engineering" },
|
||||||
]
|
]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.10"
|
||||||
license = { text = "MIT" }
|
license = { text = "MIT" }
|
||||||
dynamic = ["version", "dependencies"]
|
dynamic = ["version", "dependencies"]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue