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