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

Rework pyproject.toml parsing to never raise under setuptools #107

Merged
merged 12 commits into from
Jul 29, 2024

Conversation

twm
Copy link
Contributor

@twm twm commented Jul 27, 2024

This turns out to be a logic bug in how Incremental detects whether it has been enabled under setuptools. To quote the newsfragment:

Incremental could mis-identify that a project had opted in to version management.

If a pyproject.toml in the current directory contained a [project] table with a name key, but did not contain the opt-in [tool.incremental] table, Incremental would still treat the file as if the opt-in were present and attempt to validate the configuration. This could happen in contexts outside of packaging, such as when creating a virtualenv. When operating as a setuptools plugin Incremental now always ignores invalid configuration, such as configuration that doesn't match the content of the working directory.

The blast radius is nasty because many packaging tools use the distutils/setuptools APIs that invoke setuptools hooks.

This PR changes the rules for setuptools. Incremental now only activates itself if all of the following are true:

  1. pyproject.toml contains a [tool.incremental] table
  2. The project name can be extracted from pyproject.toml
  3. A directory matching the project name is found in the current working directory
  4. The directory matching the project name contains a _version.py file

In the Hatch case we continue to treat any configuration problems as errors because the Hatch plugin is only loaded when explicitly configured.

Additionally, this improves the integration test suite to isolate the build of the example projects and patches a coverage hole around _inf that brings us to 100% branch coverage.

Fixes #106.

@twm twm force-pushed the 106-never-raise branch from e613ab6 to 47af87a Compare July 27, 2024 20:59
twm added 6 commits July 27, 2024 14:59
The examples seemed to be running against a different version of
Incremental (possibly from pip's cache?). Ensure they run against
exactly the version of Incremental we're trying to test against by
pre-installing it in an isolated environment.

Since this introduces an isolated environment, also install coverage-p
to enable coverage of the subprocess.
@twm twm force-pushed the 106-never-raise branch from 4fcdf4b to b21e68b Compare July 28, 2024 00:08
It seems we must rely on heuristics, so let's go all the way.
@twm twm force-pushed the 106-never-raise branch from b21e68b to d2fe36f Compare July 28, 2024 03:08
.coveragerc Show resolved Hide resolved
src/incremental/__init__.py Outdated Show resolved Hide resolved
@twm twm requested a review from a team July 28, 2024 03:34
@twm twm changed the title Rework pyproject.toml parsing to never raise Rework pyproject.toml parsing to never raise under setuptools Jul 28, 2024
Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

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

Hi.

I did a very quick review... mostly just a placehoder review... in the case nobody else will have time for a full review.

Feel free to merge if another review is not provided in time.

Thanks

@adiroiban adiroiban requested a review from a team July 29, 2024 08:50
@twm
Copy link
Contributor Author

twm commented Jul 29, 2024

Thank you for the review @adiroiban! I will proceed to merge and release as I am concerned that the issue this fixes will cause more problems in the ecosystem as the work week gets going.

@twm twm merged commit 380e669 into trunk Jul 29, 2024
8 checks passed
@twm twm deleted the 106-never-raise branch July 29, 2024 19:35
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.

Incremental version 24.7.1 still breaks some projects's setuptools behaviour
2 participants