Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Jun 6, 2024
1 parent 873180f commit 7a80716
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 12 additions & 11 deletions rapids_build_backend/impls.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ def _check_setup_py(setup_py_contents: str) -> None:
"""
``setuptools.get_requires_for_build_wheel()`` executes setup.py if it exists,
to check for dependencies in ``setup_requires`` (passed to ``setuptools.setup()``).
That's a problem for rapids-build-backend, as at the point where that's invoked,
its recalculated list of build dependencies (modified in ``_edit_pyproject()``) haven't yet
been installed.
its recalculated list of build dependencies (modified in ``_edit_pyproject()``)
haven't yet been installed.
If any of them are imported in ``setup.py``, those imports will fail.
This function raises an exception if it detects ``setup_requires`` being used in a ``setup.py``,
to clarify that ``rapids-build-backend`` can't support that case.
This function raises an exception if it detects ``setup_requires`` being used in
a ``setup.py``, to clarify that ``rapids-build-backend`` can't support that case.
ref: https://github.com/rapidsai/rapids-build-backend/issues/39
"""
Expand All @@ -234,11 +234,12 @@ def _check_setup_py(setup_py_contents: str) -> None:
error_msg = (
"Detected use of 'setup_requires' in a setup.py file. "
"rapids-build-backend does not support this pattern. Try moving "
"that list of dependencies into the 'requires' list in the [tool.rapids-build-backend] "
"table in pyproject.toml."
"that list of dependencies into the 'requires' list in the "
"[tool.rapids-build-backend] table in pyproject.toml."
)
raise ValueError(error_msg)


# The hooks in this file could be defined more programmatically by iterating over the
# backend's attributes, but it's simpler to just define them explicitly and avoids any
# potential issues with assuming the right pyproject.toml is readable at import time (we
Expand All @@ -264,7 +265,7 @@ def get_requires_for_build_wheel(config_settings):
"get_requires_for_build_wheel",
):
if config.build_backend.startswith("setuptools"):
_check_setup_py(setup_py_contents = utils._get_setup_py())
_check_setup_py(setup_py_contents=utils._get_setup_py())
else:
requires.extend(
backend.get_requires_for_build_wheel(
Expand All @@ -289,7 +290,7 @@ def get_requires_for_build_sdist(config_settings):
"get_requires_for_build_sdist",
):
if config.build_backend.startswith("setuptools"):
_check_setup_py(setup_py_contents = utils._get_setup_py())
_check_setup_py(setup_py_contents=utils._get_setup_py())
else:
requires.extend(
backend.get_requires_for_build_sdist(
Expand All @@ -312,7 +313,7 @@ def get_requires_for_build_editable(config_settings):
"get_requires_for_build_editable",
):
if config.build_backend.startswith("setuptools"):
_check_setup_py(setup_py_contents = utils._get_setup_py())
_check_setup_py(setup_py_contents=utils._get_setup_py())
else:
requires.extend(
backend.get_requires_for_build_editable(
Expand Down
4 changes: 2 additions & 2 deletions rapids_build_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def _get_pyproject(dirname: str = ".") -> tomlkit.toml_document.TOMLDocument:
with open(os.path.join(dirname, "pyproject.toml")) as f:
return tomlkit.load(f)


def _get_setup_py() -> str:
"""Return a string with the contents of setup.py, or None if it doesn't exist."""
# setuptools.build_meta.get_requires_for_wheel() assumes that "setup.py" is directly
Expand All @@ -18,9 +19,8 @@ def _get_setup_py() -> str:
# ref: https://github.com/pypa/setuptools/blob/f91fa3d9fc7262e0467e4b2f84fe463f8f8d23cf/setuptools/build_meta.py#L304
setup_py_file = "setup.py"


if not os.path.isfile(setup_py_file):
return ""

with open(setup_py_file, "r") as f:
with open(setup_py_file) as f:
return f.read()

0 comments on commit 7a80716

Please sign in to comment.