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

Add a distribution package test for aioax25 #123

Merged
merged 7 commits into from
Dec 4, 2023
Merged

Conversation

diazona
Copy link
Owner

@diazona diazona commented Dec 4, 2023

This is the long-awaited (by me, probably not anyone else) implementation of a test of aioax25, to confirm that setuptools-pyproject-migration produces a pyproject.toml file that generates the same core metadata as the project's own setup.py file. In order to get this working, I kind of had to rewrite the distribution package test support code. Details are in the commit messages, but basically:

  • I added support for testing packages that only provide sdists
  • I added support for testing packages that require their own source code to be importable when running setup.py
  • I refactored the DistributionPackage/DistributionPackagePreparation class hierarchies so that DistributionPackage would not have any state that needs to be changed during testing
  • I also changed the distribution package test function to a test class, with individual methods for each of the fields, to give better visibility into which fields are and aren't getting properly computed and better error reporting

Fortunately, after all that work, the new test passes 😄

Closes #105

Different distribution packages store their metadata in different ways
which can be hard to compare directly, most notably due to different
versions of the core metadata standard. For example, the Requires and
Requires-Dist headers are equivalent-ish in the sense that they both
express dependencies, but technically any recent core metadata listing
such in a PKG-INFO file could use either one (or maybe even a mix of
both, not that I've seen that). This makes it difficult to compare
the expected metadata for a package, obtained from the package itself,
with the metadata generated from setuptools-pyproject-migration, since
they could adhere to different versions of the core metadata standard
and use different sets of headers in other ways.

After lots of false starts, I decided that the most practical way to
do that comparison is to parse the core metadata (PKG-INFO or whatever)
back into some canonical format, such as the StandardMetadata object
from pyproject-metadata. But pyproject-metadata doesn't allow parsing
its RFC822Message class back into a StandardMetadata, it only goes
the other way. So I wrote us a function to do that conversion, which is
what I'm adding here.

I haven't extensively tested this function, and it could very well have
bugs - handling all the different versions of the core metadata standard
is a little complex. But it seems to work well enough for the moment. We
can always add more tests (ah, the irony of having to test the test
support code) and fix issues that may show up in the future.
This commit does a pretty major refactoring of the distribution package
test support code. The main change is to remove all test-specific state
and state-changing operations from the DistributionPackage class and put
them in DistributionPackagePreparation, so now the workflow is that we
use a list of DistributionPackage objects to parametrize the tests, and
in each test we "convert" the DistributionPackage to an instance of
DistributionPackagePreparation which is then used and mutated as needed
for the test. Without doing this, it wouldn't really make sense to use
DistributionPackage instances to parametrize tests because they would
change each time they were used.

A big part of that change involved creating a hierarchy of
DistributionPackagePreparation classes, because each type of
DistributionPackage needs its own DistributionPackagePreparation
subclass to store relevant state.

That change turned out to be a very complex one, and while working on it
I also made some other changes that turned out to be pretty difficult to
disentangle afterwards. So I'm leaving these additional changes as part
of this commit:

- Improved use of cached properties and function return values to avoid
  downloading or extracting the same files more than once
- Better organization of the code that computes core reference metadata
  so that now each possible metadata source (wheel file or metadata file
  from PyPI) is its own separate method
This will enable running distribution package tests on packages that
don't provide wheels.
In this commit I'm introducing a new flag that will cause the root
directory of a distribution package project to be added to sys.path
while that package is being tested. Some packages expect their own
code to be available when running their setup.py, and this accounts
for that requirement.
This package exposed an issue that arises where the long description is
only given in setup.py, not setup.cfg, so it's a useful test. Plus it is
maintained by Stuart.
This change allows using custom logic to compare individual fields,
which is occasionally necessary (e.g. to ignore the order of a list). It
also allows skipping the fields related to entry points which cannot be
computed from the core metadata.
@diazona diazona added this to the v0.2 milestone Dec 4, 2023
@diazona diazona requested a review from sjlongland December 4, 2023 04:22
@diazona diazona assigned diazona and sjlongland and unassigned diazona Dec 4, 2023
Copy link
Collaborator

@sjlongland sjlongland left a comment

Choose a reason for hiding this comment

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

We might want to add a flag that turns off the network-dependent tests for some environments (e.g. Debian dpkg-buildpackage and Gentoo ebuild will both probably squawk at this), but not a huge priority just now. :-)

@sjlongland sjlongland merged commit 2e88ee2 into main Dec 4, 2023
11 checks passed
@sjlongland sjlongland deleted the add-aioax25-test/1/dev branch December 4, 2023 04:36
@diazona
Copy link
Owner Author

diazona commented Dec 4, 2023

The needs_network marker should take care of that. Something like -k 'not needs_network' passed to pytest, I think.

I doubt that this is going to be packaged by any Linux distributions though. If that winds up happening we can cross the proverbial bridge when we come to it.

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.

Add aioax25 0.0.12 as a distribution package test
2 participants