Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pip install setuptools-rust from setup.py #533

Merged
merged 5 commits into from
Dec 17, 2021

Conversation

mtreinish
Copy link
Member

The setup.py has long carried around a pip install fallback if
setuptools-rust can't be imported. This was necessary as prior to the
introduction of pep-517 there was no way to express a build-system
requirement in python packaging. There is the setup_requires field in
the setuptools metadata, but this would both trigger the install too
late (as we need to import setuptools-rust prior to running
setuptools.setup()) and also fallback to using easy_install instead of
pip which complicates installation. With pep-517 we list setuptools-rust
as a build system requirement in the pyproject.toml and pip will just
install that prior to trying to run the setup.py in the sdist.

But, for users on older versions of pip, before pep-517 was supported,
this caused a cryptic error as there would just be an import error that
setuptools_rust can't be found. The pip install fallback on import error
was added to try and make installation seamless for those users. However,
pep-517 support has been around in pip for sufficiently long at this
point I think we can safely remove this fallback as it provides more
harm than good now. In it's place the README is updated to document
that you need a newer version of pip or to manually install
setuptools-rust prior to trying to build retworkx from source. This
should hopefully be sufficient for users on older versions of pip where
they still might encounter issues.

The setup.py has long carried around a pip install fallback if
setuptools-rust can't be imported. This was necessary as prior to the
introduction of pep-517 there was no way to express a build-system
requirement in python packaging. There is the setup_requires field in
the setuptools metadata, but this would both trigger the install too
late (as we need to import setuptools-rust prior to running
setuptools.setup()) and also fallback to using easy_install instead of
pip which complicates installation. With pep-517 we list setuptools-rust
as a build system requirement in the pyproject.toml and pip will just
install that prior to trying to run the setup.py in the sdist.

But, for users on older versions of pip, before pep-517 was supported,
this caused a cryptic error as there would just be an import error that
setuptools_rust can't be found. The pip install fallback on import error
was added to try and make installation seamless for those users. However,
pep-517 support has been around in pip for sufficiently long at this
point I think we can safely remove this fallback as it provides more
harm than good now. In it's place the README is updated to document
that you need a newer version of pip or to manually install
setuptools-rust prior to trying to build retworkx from source. This
should hopefully be sufficient for users on older versions of pip where
they still might encounter issues.
CI is failing without the pip install fallback because tox is calling
`python setup.py sdist` to build the sdist prior to installing. But this
isn't processing the pyproject.toml because nothing is checking for it.
In an attempt to make tox try and respect the pyproject.toml this turns
on the isolated_build option which creates a venv for building which
hopefully will mean tox looks at the pyproject.toml prior to running
`python setup.py sdist`.
Using build isolation tox is failing because we don't explicitly list
setuptools as the build system backend in the pyproject.toml. This isn't
an issue with pip because it implicitly uses setuptools as the backend
(although via a legacy interface) if the build-backend isn't specified.
However, tox doesn't have this default and requires the build system
backend be specified. This commit corrects this oversight and explicitly
lists setuptools as the build-backend field in the pyproject.toml.
@mtreinish mtreinish added this to the 0.11.0 milestone Dec 17, 2021
@coveralls
Copy link

coveralls commented Dec 17, 2021

Pull Request Test Coverage Report for Build 1594098689

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.02%) to 98.477%

Files with Coverage Reduction New Missed Lines %
src/shortest_path/all_pairs_dijkstra.rs 2 98.71%
Totals Coverage Status
Change from base Build 1593765725: 0.02%
Covered Lines: 10990
Relevant Lines: 11160

💛 - Coveralls

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this LGTM and I am in favor of merging.

However, if we have the time to spin up virtual environments and discover the minimum version of pip that can be helpful to people that build retworkx from source. This kind of information can be useful for the more advanced users that build from source or maintain things like conda-forge/staged-recipes#17137

@@ -1,6 +1,7 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
build-backend = "setuptools.build_meta"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those reviewing this PR in the future: build-backend refers to https://github.com/pypa/setuptools/blob/main/setuptools/build_meta.py

README.md Outdated Show resolved Hide resolved
Document that at least pip 19.0.0 is needed to install from sdist.
Version 19.0.0 added pep 517 support:

https://pip.pypa.io/en/stable/news/#v19-0

which is the required feature for pip to parse the pyproject.toml and
properly install setuptools-rust before processing the setup.py.
@IvanIsCoding IvanIsCoding merged commit 53b8756 into Qiskit:main Dec 17, 2021
@mtreinish mtreinish deleted the remove-pip-install-setup.py branch December 17, 2021 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants