Skip to content

Commit a219fac

Browse files
committed
enhance control flow
1 parent 26fc527 commit a219fac

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/gardenlinux/build/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ def main():
5353

5454
match args.type:
5555
case "export-python-libs":
56-
export(output_dir=pathlib.Path(args.output_dir), package_dir=pathlib.Path(args.package_dir))
56+
export(
57+
output_dir=pathlib.Path(args.output_dir),
58+
package_dir=pathlib.Path(args.package_dir),
59+
)
5760
case _:
5861
raise NotImplementedError
5962

src/gardenlinux/build/exporter.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,37 @@ def _getInterpreter(path: str | PathLike[str]) -> pathlib.Path:
6262
case "EM_X86_64":
6363
return pathlib.Path("/lib64/ld-linux-x86-64.so.2")
6464
case arch:
65-
raise RuntimeError(f"Error: Unsupported architecture for {path}: only support x86_64 (003e), aarch64 (00b7) and i686 (0003), but was {arch}")
66-
65+
raise RuntimeError(
66+
f"Error: Unsupported architecture for {path}: only support x86_64 (003e), aarch64 (00b7) and i686 (0003), but was {arch}"
67+
)
68+
69+
6770
def _get_default_package_dir() -> pathlib.Path | None:
6871
"""
6972
Finds the default site-packages or dist-packages directory of the default python3 environment
7073
7174
:return: (str) Path to directory
7275
:since: 1.0.0
7376
"""
74-
77+
7578
# Needs to escape the virtual environment python-gardenlinx-lib is running in
7679
interpreter = shutil.which("python3")
77-
if interpreter:
78-
out = subprocess.run(
79-
[interpreter, "-c", "import site; print(site.getsitepackages()[0])"],
80-
stdout=subprocess.PIPE,
80+
81+
if not interpreter:
82+
raise RuntimeError(
83+
f"Error: Couldn't identify a default python package directory. Please specifiy one using the --package-dir option. Use -h for more information."
8184
)
82-
return pathlib.Path(out.stdout.decode().strip())
83-
else:
84-
raise RuntimeError(f"Error: Couldn't identify a default python package directory. Please specifiy one using the --package-dir option. Use -h for more information.")
85+
86+
out = subprocess.run(
87+
[interpreter, "-c", "import site; print(site.getsitepackages()[0])"],
88+
stdout=subprocess.PIPE,
89+
)
90+
return pathlib.Path(out.stdout.decode().strip())
8591

8692

8793
def export(
8894
output_dir: str | PathLike[str] = "/required_libs",
89-
package_dir: str | PathLike[str] | None = None
95+
package_dir: str | PathLike[str] | None = None,
9096
) -> None:
9197
"""
9298
Identifies shared library dependencies of `package_dir` and copies them to `output_dir`.
@@ -102,7 +108,7 @@ def export(
102108
else:
103109
package_dir = pathlib.Path(package_dir)
104110
output_dir = pathlib.Path(output_dir)
105-
111+
106112
# Collect ld dependencies for installed pip packages
107113
dependencies = set()
108114
for root, dirs, files in package_dir.walk():

0 commit comments

Comments
 (0)