Skip to content

Commit

Permalink
Stop invoking setup.py directly to make sdist's
Browse files Browse the repository at this point in the history
Calling `setup.py` is deprecated and wouldn't work if it's not actually
there.  Luckily we don't actually _need_ to build a new sdist as we
should already have it downloaded from PyPI, so just use the source
tarball directly.
  • Loading branch information
elprans committed Feb 7, 2024
1 parent 22d6588 commit ddbe304
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
21 changes: 9 additions & 12 deletions metapkg/packages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,9 @@ def __init__(

if reqs:
if poetry_depgroup.MAIN_GROUP not in self._dependency_groups:
self._dependency_groups[
poetry_depgroup.MAIN_GROUP
] = poetry_depgroup.DependencyGroup(poetry_depgroup.MAIN_GROUP)
self._dependency_groups[poetry_depgroup.MAIN_GROUP] = (
poetry_depgroup.DependencyGroup(poetry_depgroup.MAIN_GROUP)
)

main_group = self._dependency_groups[poetry_depgroup.MAIN_GROUP]
for req in reqs:
Expand Down Expand Up @@ -711,20 +711,17 @@ def is_root(self) -> bool:
@overload
def read_support_files(
self, build: targets.Build, file_glob: str, binary: Literal[False]
) -> dict[str, str]:
...
) -> dict[str, str]: ...

@overload
def read_support_files(
self, build: targets.Build, file_glob: str
) -> dict[str, str]:
...
) -> dict[str, str]: ...

@overload
def read_support_files(
self, build: targets.Build, file_glob: str, binary: Literal[True]
) -> dict[str, bytes]:
...
) -> dict[str, bytes]: ...

def read_support_files(
self, build: targets.Build, file_glob: str, binary: bool = False
Expand Down Expand Up @@ -1075,9 +1072,9 @@ def configure_dependency(
build.sh_append_flags(configure_flags, f"LDFLAGS", ldflags)

elif build.is_stdlib(pkg):
configure_flags[
f"{var_prefix}_CFLAGS"
] = f"-D_{var_prefix}_IS_SYSLIB"
configure_flags[f"{var_prefix}_CFLAGS"] = (
f"-D_{var_prefix}_IS_SYSLIB"
)
std_ldflags = []
for shlib in pkg.get_shlibs(build):
std_ldflags.append(f"-l{shlib}")
Expand Down
24 changes: 15 additions & 9 deletions metapkg/packages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,8 @@ def get_build_requires_from_srcdir(
deps = []
for req in sys_reqs | pkg_reqs:
dep = python_dependency_from_pep_508(req)
# Make sure "wheel" is not a dependency of itself and
# also elide setuptools, because it is always installed.
if dep.name == "pypkg-setuptools" or (
# Make sure "wheel" is not a dependency of itself.
if (
package.name in {"pypkg-wheel", "pypkg-setuptools"}
and dep.name == "pypkg-wheel"
):
Expand All @@ -294,6 +293,15 @@ def get_build_requires_from_srcdir(
return deps


def is_build_system_bootstrap_package(
pkgname: str,
) -> bool:
return pkgname in {
"wheel",
"setuptools",
}


class BasePythonPackage(base.BasePackage):
source: af_sources.BaseSource

Expand Down Expand Up @@ -347,8 +355,9 @@ def get_build_script(self, build: targets.Build) -> str:
dep_names = [dep.name for dep in base.get_build_requirements(self)]
build_deps = build.get_packages(dep_names)

if pkgname == "wheel":
build_command = f'"{src_python}" setup.py sdist -d ${{_wheeldir}}'
if is_build_system_bootstrap_package(pkgname):
tarball = build.get_tarball(self, relative_to="pkgsource")
build_command = f'cp "{tarball}" ${{_wheeldir}}/{pkgname}-{self.version}.tar.gz'
binary = False
else:
args = [
Expand Down Expand Up @@ -445,10 +454,7 @@ def get_build_install_script(self, build: targets.Build) -> str:
if pkgname.startswith("pypkg-"):
pkgname = pkgname[len("pypkg-") :]

if pkgname == "wheel":
binary = False
else:
binary = True
binary = not is_build_system_bootstrap_package(pkgname)

env = {
"PIP_DISABLE_PIP_VERSION_CHECK": "1",
Expand Down
7 changes: 4 additions & 3 deletions metapkg/packages/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,10 @@ def _tar_append(
target_tarball: pathlib.Path,
) -> None:
if platform.system() != "Linux":
with tarfile.open(source_tarball) as modf, tarfile.open(
target_tarball, "a"
) as tf:
with (
tarfile.open(source_tarball) as modf,
tarfile.open(target_tarball, "a") as tf,
):
for m in modf.getmembers():
if m.issym():
# Skip broken symlinks.
Expand Down
8 changes: 8 additions & 0 deletions metapkg/targets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,14 @@ def unpack_sources(self) -> None:
io=self._io,
)

def get_tarball(
self,
pkg: mpkg_base.BasePackage,
*,
relative_to: Location,
) -> pathlib.Path:
return self.get_dir(self._tarballs[pkg], relative_to=relative_to)

def prepare_patches(self) -> None:
patches_dir = self.get_patches_root(relative_to="fsroot")

Expand Down
6 changes: 3 additions & 3 deletions metapkg/targets/macos/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def define_tools(self) -> None:
else:
dash_j = f"-j{self._jobs}"
gmake = self._find_tool("gmake")
self._system_tools[
"make"
] = f"env -u MAKELEVEL {gmake} {dash_j} SHELL={bash}"
self._system_tools["make"] = (
f"env -u MAKELEVEL {gmake} {dash_j} SHELL={bash}"
)
self._system_tools["sed"] = self._find_tool("gsed")
self._system_tools["tar"] = self._find_tool("gtar")

Expand Down

0 comments on commit ddbe304

Please sign in to comment.