def _check_wheel_metadata_version(dist): """Confirm that metadata generated by wheel is supported by pkginfo. Version 0.31.0 of the wheel package started using metadata version 2.1, which is not supported by versions of pkginfo earlier than 1.4.2. Upgrading wheel without upgrading pkginfo will leave the env unable to read pkg info generated in wheels. Utils like twine rely on this and will break. This is a check to confirm that the metadata generated by wheel can be read using pkginfo. """ from pkginfo import distribution from wheel import metadata egg_info_path = dist.get_name() + ".egg-info" pkginfo_path = os.path.join(egg_info_path, "PKG-INFO") msg = metadata.pkginfo_to_metadata(egg_info_path, pkginfo_path) metadata_ver = msg["Metadata-Version"] supported_vers = distribution.HEADER_ATTRS.keys() if metadata_ver not in supported_vers: raise AssertionError( "wheel metadata version '%s' is not supported by pkginfo " "(should be one of %s)\n" "Try upgrading pkginfo to the latest version." % (metadata_ver, ", ".join(map(repr, supported_vers))) )
def test_pkginfo_to_metadata(tmpdir): expected_metadata = [ ('Metadata-Version', '2.1'), ('Name', 'spam'), ('Version', '0.1'), ('Provides-Extra', 'test'), ('Provides-Extra', 'signatures'), ('Provides-Extra', 'faster-signatures'), ('Requires-Dist', "ed25519ll; extra == 'faster-signatures'"), ('Requires-Dist', "keyring; extra == 'signatures'"), ('Requires-Dist', "keyrings.alt; extra == 'signatures'"), ('Requires-Dist', 'pyxdg; (sys_platform!="win32") and extra == \'signatures\''), ('Requires-Dist', "pytest (>=3.0.0); extra == 'test'"), ('Requires-Dist', "pytest-cov; extra == 'test'"), ] pkg_info = tmpdir.join('PKG-INFO') pkg_info.write("""\ Metadata-Version: 0.0 Name: spam Version: 0.1 Provides-Extra: test Provides-Extra: signatures Provides-Extra: faster-signatures""") egg_info_dir = tmpdir.ensure_dir('test.egg-info') egg_info_dir.join('requires.txt').write("""\ [faster-signatures] ed25519ll [signatures] keyring keyrings.alt [signatures:sys_platform!="win32"] pyxdg [test] pytest>=3.0.0 pytest-cov""") message = pkginfo_to_metadata(egg_info_path=str(egg_info_dir), pkginfo_path=str(pkg_info)) assert message.items() == expected_metadata
def test_pkginfo_to_metadata(tmpdir): expected_metadata = [ ("Metadata-Version", "2.1"), ("Name", "spam"), ("Version", "0.1"), ("Requires-Dist", "pip @ https://github.com/pypa/pip/archive/1.3.1.zip"), ("Requires-Dist", 'pywin32 ; sys_platform=="win32"'), ("Requires-Dist", 'foo @ http://host/foo.zip ; sys_platform=="win32"'), ("Provides-Extra", "signatures"), ( "Requires-Dist", "pyxdg ; (sys_platform!=\"win32\") and extra == 'signatures'", ), ("Provides-Extra", "empty_extra"), ("Provides-Extra", "extra"), ("Requires-Dist", "bar @ http://host/bar.zip ; extra == 'extra'"), ("Provides-Extra", "faster-signatures"), ("Requires-Dist", "ed25519ll ; extra == 'faster-signatures'"), ("Provides-Extra", "rest"), ("Requires-Dist", "docutils (>=0.8) ; extra == 'rest'"), ("Requires-Dist", "keyring ; extra == 'signatures'"), ("Requires-Dist", "keyrings.alt ; extra == 'signatures'"), ("Provides-Extra", "test"), ("Requires-Dist", "pytest (>=3.0.0) ; extra == 'test'"), ("Requires-Dist", "pytest-cov ; extra == 'test'"), ] pkg_info = tmpdir.join("PKG-INFO") pkg_info.write( """\ Metadata-Version: 0.0 Name: spam Version: 0.1 Provides-Extra: empty+extra Provides-Extra: test Provides-Extra: reST Provides-Extra: signatures Provides-Extra: Signatures Provides-Extra: faster-signatures""" ) egg_info_dir = tmpdir.ensure_dir("test.egg-info") egg_info_dir.join("requires.txt").write( """\ pip@https://github.com/pypa/pip/archive/1.3.1.zip [extra] bar @ http://host/bar.zip [empty+extra] [:sys_platform=="win32"] pywin32 foo @http://host/foo.zip [faster-signatures] ed25519ll [reST] docutils>=0.8 [signatures] keyring keyrings.alt [Signatures:sys_platform!="win32"] pyxdg [test] pytest>=3.0.0 pytest-cov""" ) message = pkginfo_to_metadata( egg_info_path=str(egg_info_dir), pkginfo_path=str(pkg_info) ) assert message.items() == expected_metadata
def _pkginfo_to_metadata(self, egg_info_path, pkginfo_path): return metadata.pkginfo_to_metadata(egg_info_path, pkginfo_path)
def test_pkginfo_to_metadata(tmpdir): expected_metadata = [ ('Metadata-Version', '2.1'), ('Name', 'spam'), ('Version', '0.1'), ('Requires-Dist', "pip @ https://github.com/pypa/pip/archive/1.3.1.zip"), ('Requires-Dist', 'pywin32 ; sys_platform=="win32"'), ('Requires-Dist', 'foo @ http://host/foo.zip ; sys_platform=="win32"'), ('Provides-Extra', 'signatures'), ('Requires-Dist', 'pyxdg ; (sys_platform!="win32") and extra == \'signatures\''), ('Provides-Extra', 'empty_extra'), ('Provides-Extra', 'extra'), ('Requires-Dist', 'bar @ http://host/bar.zip ; extra == \'extra\''), ('Provides-Extra', 'faster-signatures'), ('Requires-Dist', "ed25519ll ; extra == 'faster-signatures'"), ('Provides-Extra', 'rest'), ('Requires-Dist', "docutils (>=0.8) ; extra == 'rest'"), ('Requires-Dist', "keyring ; extra == 'signatures'"), ('Requires-Dist', "keyrings.alt ; extra == 'signatures'"), ('Provides-Extra', 'test'), ('Requires-Dist', "pytest (>=3.0.0) ; extra == 'test'"), ('Requires-Dist', "pytest-cov ; extra == 'test'"), ] pkg_info = tmpdir.join('PKG-INFO') pkg_info.write("""\ Metadata-Version: 0.0 Name: spam Version: 0.1 Provides-Extra: empty+extra Provides-Extra: test Provides-Extra: reST Provides-Extra: signatures Provides-Extra: Signatures Provides-Extra: faster-signatures""") egg_info_dir = tmpdir.ensure_dir('test.egg-info') egg_info_dir.join('requires.txt').write("""\ pip@https://github.com/pypa/pip/archive/1.3.1.zip [extra] bar @ http://host/bar.zip [empty+extra] [:sys_platform=="win32"] pywin32 foo @http://host/foo.zip [faster-signatures] ed25519ll [reST] docutils>=0.8 [signatures] keyring keyrings.alt [Signatures:sys_platform!="win32"] pyxdg [test] pytest>=3.0.0 pytest-cov""") message = pkginfo_to_metadata(egg_info_path=str(egg_info_dir), pkginfo_path=str(pkg_info)) assert message.items() == expected_metadata