Skip to content

Commit 30c502b

Browse files
committed
Refactor rdev
1 parent 8c33e41 commit 30c502b

File tree

4 files changed

+63
-39
lines changed

4 files changed

+63
-39
lines changed

devtools/ci.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ def build_other_wheels(ctx: Context, no_test: bool):
5050
continue
5151

5252
with ctx.handle_exception(project.name):
53-
project.install_build_deps(
54-
wheel_path=ctx.wheel_path, other_wheel_path=ctx.other_wheel_path
55-
)
53+
ctx.install_build_deps(subproject=project)
54+
5655
project.build_wheel(
5756
wheel_path=ctx.wheel_path,
5857
other_wheel_path=ctx.other_wheel_path,

devtools/ctx.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import contextlib
2-
import os
32
import pathlib
43
import subprocess
54
import sys
@@ -10,6 +9,7 @@
109

1110
from . import config
1211
from .subproject import Subproject
12+
from .util import run_pip
1313

1414

1515
class Context:
@@ -77,3 +77,43 @@ def handle_exception(self, msg: str):
7777

7878
print(f"ERROR: {msg}: {e}", file=sys.stderr)
7979
sys.exit(1)
80+
81+
@property
82+
def internal_pyprojects(self):
83+
if not hasattr(self, "_internal_pyprojects"):
84+
self._internal_pyprojects = [
85+
s.pyproject_name for s in self.subprojects.values()
86+
]
87+
return self._internal_pyprojects
88+
89+
def install_build_deps(
90+
self,
91+
*,
92+
subproject: Subproject,
93+
):
94+
# separate requirements into internal and external
95+
internal = []
96+
external = []
97+
98+
for req in subproject.build_requires:
99+
if req.name in self.internal_pyprojects:
100+
internal.append(req)
101+
else:
102+
external.append(req)
103+
104+
if external:
105+
run_pip(
106+
"install",
107+
*[str(req) for req in external],
108+
)
109+
110+
if internal:
111+
run_pip(
112+
"install",
113+
"--no-index",
114+
"--find-links",
115+
str(self.wheel_path),
116+
"--find-links",
117+
str(self.other_wheel_path),
118+
*[str(req) for req in internal],
119+
)

devtools/subproject.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import pathlib
2-
import subprocess
3-
import shlex
42
import shutil
53
import sys
64
import tempfile
@@ -10,6 +8,7 @@
108
import tomli
119

1210
from .config import SubprojectConfig
11+
from .util import run_cmd, run_pip
1312

1413

1514
class Subproject:
@@ -43,36 +42,14 @@ def is_meson_project(self) -> bool:
4342
# Tasks
4443
#
4544

46-
def _cmd(self, *args: str, cwd=None):
47-
print("+", shlex.join(args))
48-
subprocess.check_call(args, cwd=cwd)
49-
50-
def _run_pip(self, *args: str, cwd=None):
51-
self._cmd(
52-
sys.executable, "-m", "pip", "--disable-pip-version-check", *args, cwd=cwd
53-
)
54-
55-
def install_build_deps(
56-
self, *, wheel_path: pathlib.Path, other_wheel_path: pathlib.Path
57-
):
58-
self._run_pip(
59-
"install",
60-
"--no-index",
61-
"--find-links",
62-
str(wheel_path),
63-
"--find-links",
64-
str(other_wheel_path),
65-
*[str(req) for req in self.build_requires],
66-
)
67-
6845
def develop(self):
69-
self._run_pip("install", "-v", "-e", ".", "--no-build-isolation", cwd=self.path)
46+
run_pip("install", "-v", "-e", ".", "--no-build-isolation", cwd=self.path)
7047

7148
def uninstall(self):
72-
self._run_pip("uninstall", "-y", self.pyproject_name)
49+
run_pip("uninstall", "-y", self.pyproject_name)
7350

7451
def update_init(self):
75-
self._cmd(
52+
run_cmd(
7653
sys.executable,
7754
"-m",
7855
"semiwrap",
@@ -88,17 +65,13 @@ def test(self, *, install_requirements=False):
8865
if install_requirements:
8966
requirements = tests_path / "requirements.txt"
9067
if requirements.exists():
91-
self._cmd(
92-
sys.executable,
93-
"-m",
94-
"pip",
95-
"--disable-pip-version-check",
68+
run_pip(
9669
"install",
9770
"-r",
9871
str(requirements),
9972
)
10073

101-
self._cmd(
74+
run_cmd(
10275
sys.executable,
10376
"run_tests.py",
10477
cwd=tests_path,
@@ -120,7 +93,7 @@ def build_wheel(
12093

12194
with tempfile.TemporaryDirectory() as td:
12295
# I wonder if we should use hatch build instead?
123-
self._cmd(
96+
run_cmd(
12497
sys.executable,
12598
"-m",
12699
"build",
@@ -138,7 +111,7 @@ def build_wheel(
138111

139112
if install:
140113
# Install the wheel
141-
self._run_pip(
114+
run_pip(
142115
"install",
143116
"--find-links",
144117
str(wheel_path),

devtools/util.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import shlex
2+
import subprocess
3+
import sys
14
import typing
25

36
from validobj import errors
@@ -39,3 +42,12 @@ def parse_input(value: typing.Any, spec: typing.Type[T], fname) -> T:
3942
return validobj.validation.parse_input(value, spec)
4043
except errors.ValidationError as ve:
4144
raise _convert_validation_error(fname, ve) from None
45+
46+
47+
def run_cmd(*args: str, cwd=None):
48+
print("+", shlex.join(args))
49+
subprocess.check_call(args, cwd=cwd)
50+
51+
52+
def run_pip(*args: str, cwd=None):
53+
run_cmd(sys.executable, "-m", "pip", "--disable-pip-version-check", *args, cwd=cwd)

0 commit comments

Comments
 (0)