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

Optional dependencies not listed with their corresponding extras #134

Closed
diazona opened this issue Dec 10, 2023 · 1 comment · Fixed by #168
Closed

Optional dependencies not listed with their corresponding extras #134

diazona opened this issue Dec 10, 2023 · 1 comment · Fixed by #168
Assignees
Labels
bug Something isn't working
Milestone

Comments

@diazona
Copy link
Owner

diazona commented Dec 10, 2023

When running the test tests/distribution/test_distribution_packages.py::TestExternalProject::test_optional_dependencies[pytest==7.3.0], setuptools-pyproject-migration does not list the corresponding extras as part of the Requirement objects.

I'm not sure what the correct approach should be; we can figure that out while solving this issue.

self = <test_distribution_packages.TestExternalProject object at 0x7f32b0ca7090>
expected = StandardMetadata(name='pytest', version=<Version('7.3.0')>, description='pytest: simple powerful testing with Python',...are Development :: Testing', 'Topic :: Utilities'], keywords=['test,unittest'], scripts={}, gui_scripts={}, dynamic=[])
actual = StandardMetadata(name='pytest', version=<Version('7.3.0')>, description='pytest: simple powerful testing with Python',..., 'unittest'], scripts={'pytest': 'pytest:console_main', 'py.test': 'pytest:console_main'}, gui_scripts={}, dynamic=[])

    def test_optional_dependencies(self, expected: StandardMetadata, actual: StandardMetadata):
        # Check that the set of extras is the same
        assert expected.optional_dependencies.keys() == actual.optional_dependencies.keys()
    
        # Check that the dependencies associated with each extra are the same
        for extra in expected.optional_dependencies:
>           assert sorted(expected.optional_dependencies[extra], key=str) == sorted(
                actual.optional_dependencies[extra], key=str
            )
E           assert [<Requirement('argcomplete; extra == "testing"')>, <Requirement('attrs>=19.2.0; extra == "testing"')>, <Requirement('hypothesis>=3.56; extra == "testing"')>, <Requirement('mock; extra == "testing"')>, <Requirement('nose; extra == "testing"')>, <Requirement('pygments>=2.7.2; extra == "testing"')>, <Requirement('requests; extra == "testing"')>, <Requirement('xmlschema; extra == "testing"')>] == [<Requirement('argcomplete')>, <Requirement('attrs>=19.2.0')>, <Requirement('hypothesis>=3.56')>, <Requirement('mock')>, <Requirement('nose')>, <Requirement('pygments>=2.7.2')>, <Requirement('requests')>, <Requirement('xmlschema')>]
E             At index 0 diff: <Requirement('argcomplete; extra == "testing"')> != <Requirement('argcomplete')>
E             Full diff:
E               [
E             -  <Requirement('argcomplete')>,
E             +  <Requirement('argcomplete; extra == "testing"')>,
E             ?                           ++++++++++++++++++++
E             -  <Requirement('attrs>=19.2.0')>,
E             +  <Requirement('attrs>=19.2.0; extra == "testing"')>,
E             ?                             ++++++++++++++++++++
E             -  <Requirement('hypothesis>=3.56')>,
E             +  <Requirement('hypothesis>=3.56; extra == "testing"')>,
E             ?                                ++++++++++++++++++++
E             -  <Requirement('mock')>,
E             -  <Requirement('nose')>,
E             +  <Requirement('mock; extra == "testing"')>,
E             +  <Requirement('nose; extra == "testing"')>,
E             -  <Requirement('pygments>=2.7.2')>,
E             +  <Requirement('pygments>=2.7.2; extra == "testing"')>,
E             ?                               ++++++++++++++++++++
E             -  <Requirement('requests')>,
E             -  <Requirement('xmlschema')>,
E             +  <Requirement('requests; extra == "testing"')>,
E             +  <Requirement('xmlschema; extra == "testing"')>,
E               ]

/home/diazona/programming/setuptools-pyproject-migration/tests/distribution/test_distribution_packages.py:146: AssertionError
@diazona diazona added the bug Something isn't working label Dec 10, 2023
@diazona diazona added this to the v0.3 milestone Dec 29, 2023
@diazona diazona self-assigned this Jul 22, 2024
@diazona
Copy link
Owner Author

diazona commented Jul 28, 2024

After investigating, I think the root of this problem is that our code which parses the core metadata keeps the extra == ... markers when it creates Requirement objects for optional dependencies, but pyproject-metadata's StandardMetadata.from_pyproject() creates Requirement objects without extra == ... markers. It adds the marker when writing the StandardMetadata object out to RFC822 headers. So we either need to add the extra marker to the Requirement objects we create in TestExternalProject.actual() (it could be done there, or later, while running the test for optional dependencies), or remove the extra marker from the Requirements created in PyPiPackagePreparation._core_metadata_*(). Either way I think to do this robustly would require some parsing of the markers, but perhaps we could take advantage of the fact that pyproject-metadata always adds an extra marker at the end.

I'll continue looking into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant