Skip to content

Commit

Permalink
e3-pypi-closure: Use pip wheel when setup.py is not found
Browse files Browse the repository at this point in the history
This allows us to build projects that use pyproject.toml if the module is
installed.
  • Loading branch information
leocardao committed Jul 19, 2023
1 parent a5ac69c commit 6dd28df
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/e3/python/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,41 @@ def build(cls, source_dir: str, dest_dir: str, python_tag: str = "py3") -> Wheel
:return: a Wheel object
"""
with tempfile.TemporaryDirectory() as build_dir:
p = Run(
[
sys.executable,
"./setup.py",
"-q",
"bdist_wheel",
f"--python-tag={python_tag}",
"-d",
build_dir,
],
cwd=source_dir,
)
if os.path.isfile(os.path.join(source_dir, "setup.py")):
p = Run(
[
sys.executable,
"./setup.py",
"-q",
"bdist_wheel",
f"--python-tag={python_tag}",
"-d",
build_dir,
],
cwd=source_dir,
)
else:
p = Run(
[
"pip",
"wheel",
".",
"-q",
"--no-deps",
f"-C--python-tag={python_tag}",
"-w",
build_dir,
],
cwd=source_dir,
)

if p.status != 0:
raise WheelError(f"Error during wheel creation:\n{p.out}")

tmp_whl_path = ls(os.path.join(build_dir, "*.whl"))[0]
dest_whl_path = os.path.join(dest_dir, os.path.basename(tmp_whl_path))
mv(tmp_whl_path, dest_whl_path)

return Wheel(path=dest_whl_path)

def install(self) -> None:
Expand Down

0 comments on commit 6dd28df

Please sign in to comment.