@@ -832,6 +832,88 @@ def test_export_pypi_dependencies_multiple_wheels(
832832 assert content == expected
833833
834834
835+ def test_export_pypi_dependencies_sdist_sorted_between_wheels (
836+ tmp_path : Path , poetry : Poetry
837+ ) -> None :
838+ # The lock file sorts files by name, so the sdist can end up between wheels,
839+ # e.g. if the distribution name of some wheels is normalized differently.
840+ lock_data = {
841+ "package" : [
842+ {
843+ "name" : "foo.bar" ,
844+ "version" : "1.0" ,
845+ "optional" : False ,
846+ "python-versions" : "*" ,
847+ "groups" : [MAIN_GROUP ],
848+ "files" : [
849+ {
850+ "file" : "foo.bar-1.0-py2-none-any.whl" ,
851+ "hash" : "sha256:abcdef1234567891" ,
852+ },
853+ {
854+ "file" : "foo.bar-1.0.tar.gz" ,
855+ "hash" : "sha256:0123456789abcdef" ,
856+ },
857+ {
858+ "file" : "foo_bar-1.0-py3-none-any.whl" ,
859+ "hash" : "sha256:abcdef1234567890" ,
860+ },
861+ ],
862+ },
863+ ],
864+ "metadata" : {"lock-version" : "2.1" },
865+ }
866+ poetry .locker .mock_lock_data (lock_data ) # type: ignore[attr-defined]
867+
868+ foo_bar = Package ("foo.bar" , "1.0" )
869+ foo_bar .files = [
870+ {
871+ "file" : "foo.bar-1.0-py2-none-any.whl" ,
872+ "hash" : "sha256:abcdef1234567891" ,
873+ "url" : "https://example.org/foo.bar-1.0-py2-none-any.whl" ,
874+ },
875+ {
876+ "file" : "foo.bar-1.0.tar.gz" ,
877+ "hash" : "sha256:0123456789abcdef" ,
878+ "url" : "https://example.org/foo.bar-1.0.tar.gz" ,
879+ },
880+ {
881+ "file" : "foo_bar-1.0-py3-none-any.whl" ,
882+ "hash" : "sha256:abcdef1234567890" ,
883+ "url" : "https://example.org/foo_bar-1.0-py3-none-any.whl" ,
884+ },
885+ ]
886+ poetry .pool .repository ("PyPI" ).add_package (foo_bar )
887+
888+ exporter = Exporter (poetry , NullIO ())
889+
890+ exporter .export ("pylock.toml" , tmp_path , "pylock.toml" )
891+
892+ with (tmp_path / "pylock.toml" ).open (encoding = "utf-8" ) as f :
893+ content = f .read ()
894+
895+ expected = """\
896+ lock-version = "1.0"
897+ created-by = "poetry-plugin-export"
898+
899+ [[packages]]
900+ name = "foo-bar"
901+ version = "1.0"
902+ index = "https://pypi.org/simple"
903+ sdist = {name = "foo.bar-1.0.tar.gz", url = "https://example.org/foo.bar-1.0.tar.gz", hashes = {sha256 = "0123456789abcdef"}}
904+ wheels = [
905+ {name = "foo.bar-1.0-py2-none-any.whl", url = "https://example.org/foo.bar-1.0-py2-none-any.whl", hashes = {sha256 = "abcdef1234567891"}},
906+ {name = "foo_bar-1.0-py3-none-any.whl", url = "https://example.org/foo_bar-1.0-py3-none-any.whl", hashes = {sha256 = "abcdef1234567890"}},
907+ ]
908+
909+ [tool.poetry-plugin-export]
910+ groups = ["main"]
911+ extras = []
912+ """
913+
914+ assert content == expected
915+
916+
835917def test_export_legacy_repo_dependencies (tmp_path : Path , poetry : Poetry ) -> None :
836918 lock_data = {
837919 "package" : [
0 commit comments