Skip to content

Commit 2307ad4

Browse files
committed
More temp
1 parent 7611022 commit 2307ad4

File tree

11 files changed

+91
-23
lines changed

11 files changed

+91
-23
lines changed

devtools/__main__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626

2727
@click.group()
28+
@click.option("-v", "--verbose", default=False, is_flag=True)
2829
@click.pass_context
29-
def main(ctx: click.Context):
30+
def main(ctx: click.Context, verbose: bool):
3031
"""RobotPy development tool"""
31-
ctx.obj = Context()
32+
ctx.obj = Context(verbose)
3233

3334

3435
main.add_command(ci.ci)
@@ -40,7 +41,7 @@ def main(ctx: click.Context):
4041
def info(ctx: Context):
4142
"""Display information"""
4243
for project in ctx.subprojects.values():
43-
print(project.name, project.requires)
44+
print(project.name, project.build_requires)
4445

4546

4647
@main.command()
@@ -82,7 +83,9 @@ def uninstall(ctx: Context, package: str):
8283
def update_init(ctx: Context):
8384
"""Update __init__.py in all projects"""
8485
for project in ctx.subprojects.values():
85-
project.update_init()
86+
if project.is_semiwrap_project():
87+
with ctx.handle_exception(f"update-init {project.name}"):
88+
project.update_init()
8689

8790

8891
@main.command()

devtools/ci.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def run(ctx: Context, no_test: bool):
5050
# Fix build dependencies to be == what we are building
5151
# - install_requires already has this via ==THIS_VERSION in robotpy-build
5252
for project in ctx.subprojects.values():
53-
for i in range(len(project.requires)):
54-
req = project.requires[i]
53+
for i in range(len(project.build_requires)):
54+
req = project.build_requires[i]
5555
if req.name in ctx.subprojects:
56-
project.requires[i] = Requirement(f"{req.name}=={version}")
56+
project.build_requires[i] = Requirement(f"{req.name}=={version}")
5757

5858
for project in ctx.subprojects.values():
5959
project.install_build_deps(wheel_path=ctx.wheel_path)

devtools/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@dataclasses.dataclass
99
class SubprojectConfig:
10-
10+
1111
#: Whether this should be built on roborio or not
1212
roborio: bool
1313

@@ -27,6 +27,7 @@ class Parameters:
2727

2828
requirements: T.Dict[str, str]
2929

30+
3031
@dataclasses.dataclass
3132
class UpdateConfig:
3233
params: Parameters

devtools/ctx.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import contextlib
2+
import os
13
import pathlib
24
import subprocess
5+
import sys
36
import sysconfig
47
import typing
58

@@ -12,7 +15,8 @@
1215
class Context:
1316
"""Global context used by all rdev commands"""
1417

15-
def __init__(self) -> None:
18+
def __init__(self, verbose: bool) -> None:
19+
self.verbose =verbose
1620
self.root_path = pathlib.Path(__file__).parent.parent
1721
self.subprojects_path = self.root_path / "subprojects"
1822
self.cfgpath = self.root_path / "rdev.toml"
@@ -33,7 +37,7 @@ def __init__(self) -> None:
3337
# Create a sorted dictionary of subprojects ordered by build order
3438
si = {p.pyproject_name: i for i, p in enumerate(subprojects)}
3539
ti = {
36-
i: [si[r.name] for r in p.requires if r.name in si]
40+
i: [si[r.name] for r in p.build_requires if r.name in si]
3741
for i, p in enumerate(subprojects)
3842
}
3943

@@ -61,3 +65,14 @@ def git_is_file_dirty(self, relpath: str) -> bool:
6165
["git", "status", "--porcelain", relpath], cwd=self.root_path
6266
).decode("utf-8")
6367
return output != ""
68+
69+
@contextlib.contextmanager
70+
def handle_exception(self, msg: str):
71+
try:
72+
yield
73+
except Exception as e:
74+
if self.verbose:
75+
raise
76+
77+
print(f"ERROR: {msg}: {e}",file=sys.stderr)
78+
sys.exit(1)

devtools/subproject.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ def __init__(self, cfg: SubprojectConfig, path: pathlib.Path) -> None:
2222
with open(self.pyproject_path, "rb") as fp:
2323
self.pyproject_data = tomli.load(fp)
2424

25-
self.requires = [
25+
self.build_requires = [
2626
Requirement(req) for req in self.pyproject_data["build-system"]["requires"]
2727
]
2828

2929
self.pyproject_name: str = self.pyproject_data["project"]["name"]
3030

31+
def is_semiwrap_project(self) ->bool:
32+
return self.pyproject_data.get("tool", {}).get("semiwrap", None) is not None
33+
34+
def is_meson_project(self) -> bool:
35+
return (self.path / "meson.build").exists()
36+
3137
#
3238
# Tasks
3339
#
@@ -37,18 +43,16 @@ def _cmd(self, *args: str, cwd=None):
3743
subprocess.check_call(args, cwd=cwd)
3844

3945
def _run_pip(self, *args: str, cwd=None):
40-
self._cmd(sys.executable, "-m", "pip", "--disable-pip-version-check", *args, cwd=cwd)
46+
self._cmd(
47+
sys.executable, "-m", "pip", "--disable-pip-version-check", *args, cwd=cwd
48+
)
4149

4250
def install_build_deps(self, *, wheel_path: pathlib.Path):
43-
self._cmd(
44-
sys.executable,
45-
"-m",
46-
"pip",
51+
self._run_pip(
4752
"install",
48-
"--disable-pip-version-check",
4953
"--find-links",
5054
str(wheel_path),
51-
*[str(req) for req in self.requires],
55+
*[str(req) for req in self.build_requires],
5256
)
5357

5458
def develop(self):
@@ -60,8 +64,9 @@ def uninstall(self):
6064
def update_init(self):
6165
self._cmd(
6266
sys.executable,
63-
"setup.py",
64-
"update_init",
67+
"-m",
68+
"semiwrap",
69+
"update-init",
6570
cwd=self.path,
6671
)
6772

devtools/util.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import typing
2+
3+
from validobj import errors
4+
import validobj.validation
5+
6+
T = typing.TypeVar("T")
7+
8+
9+
class ValidationError(Exception):
10+
pass
11+
12+
13+
def _convert_validation_error(fname, ve: errors.ValidationError) -> ValidationError:
14+
locs = []
15+
msg = []
16+
17+
e = ve
18+
while e is not None:
19+
20+
if isinstance(e, errors.WrongFieldError):
21+
locs.append(f".{e.wrong_field}")
22+
elif isinstance(e, errors.WrongListItemError):
23+
locs.append(f"[{e.wrong_index}]")
24+
else:
25+
msg.append(str(e))
26+
27+
e = e.__cause__
28+
29+
loc = "".join(locs)
30+
if loc.startswith("."):
31+
loc = loc[1:]
32+
msg = "\n ".join(msg)
33+
vmsg = f"{fname}: {loc}:\n {msg}"
34+
return ValidationError(vmsg)
35+
36+
37+
def parse_input(value: typing.Any, spec: typing.Type[T], fname) -> T:
38+
try:
39+
return validobj.validation.parse_input(value, spec)
40+
except errors.ValidationError as ve:
41+
raise _convert_validation_error(fname, ve) from None

rdev_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ validobj~=1.2
1010
wheel
1111

1212
semiwrap @ git+https://github.com/robotpy/robotpy-build@semiwrap
13+
hatch-robotpy @ git+https://github.com/robotpy/hatch-robotpy@main
14+
hatch-nativelib @ git+https://github.com/robotpy/hatch-nativelib@rm-macos-relink

subprojects/robotpy-hal/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ version-file = "hal/version.py"
3434
[tool.hatch.build.hooks.meson]
3535

3636
[tool.semiwrap]
37+
update_init = []
3738
scan_headers_ignore = [
3839
"hal/ChipObject.h",
3940
"hal/DMA.h",

subprojects/robotpy-halsim-gui/tests/test_halsim_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def test_halsim_gui():
1616
if fname.is_file() and fname.suffix in (".dll", ".dylib", ".so"):
1717
ctypes.CDLL(fname)
1818
loaded += 1
19-
19+
2020
assert loaded

subprojects/robotpy-halsim-ws/tests/test_halsim_ws_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def test_halsim_ws_client():
1414
if fname.is_file() and fname.suffix in (".dll", ".dylib", ".so"):
1515
ctypes.CDLL(fname)
1616
loaded += 1
17-
17+
1818
assert loaded

0 commit comments

Comments
 (0)