Repository: pypa/setuptools (python)

Issue:
AssertionError on len(sdists) == 1 when sdist format is zip
In some Windows projects, users expect sdists to be released in zip form. For that reason, I've added the following to a project's setup.cfg:

```
[sdist]
formats=zip
```

With this setting in place, performing a `pep517.build .` on such a project results in the following traceback:

```
Traceback (most recent call last):
  File "/Users/jaraco/code/main/jaraco.video/.tox/release/lib/python3.7/site-packages/pep517/_in_process.py", line 207, in <module>
    main()
  File "/Users/jaraco/code/main/jaraco.video/.tox/release/lib/python3.7/site-packages/pep517/_in_process.py", line 197, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/Users/jaraco/code/main/jaraco.video/.tox/release/lib/python3.7/site-packages/pep517/_in_process.py", line 170, in build_sdist
    return backend.build_sdist(sdist_directory, config_settings)
  File "/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pep517-build-env-rgz_zb4_/lib/python3.7/site-packages/setuptools/build_meta.py", line 181, in build_sdist
    assert len(sdists) == 1
AssertionError
```

Even though the output from building the sdist was seen above. I suspect the builder expects the sdist to have a particular extension.

Pull request description:
In build_meta (PEP 517), always built gztar
## Summary of changes

Always build gztar in build_meta

Closes #1623

### Pull Request Checklist
- [X] Changes have tests
- [X] News fragment added in changelog.d. See [documentation](http://setuptools.readthedocs.io/en/latest/developer-guide.html#making-a-pull-request) for details

Patch:
diff --git a/changelog.d/1625.change.rst b/changelog.d/1625.change.rst
new file mode 100644
index 000000000..9125ac0ce
--- /dev/null
+++ b/changelog.d/1625.change.rst
@@ -0,0 +1,1 @@
+In PEP 517 build_meta builder, ensure that sdists are built as gztar per the spec.
diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py
index 463d3757a..75178a7a3 100644
--- a/setuptools/build_meta.py
+++ b/setuptools/build_meta.py
@@ -170,7 +170,7 @@ def build_wheel(wheel_directory, config_settings=None,
 def build_sdist(sdist_directory, config_settings=None):
     config_settings = _fix_config(config_settings)
     sdist_directory = os.path.abspath(sdist_directory)
-    sys.argv = sys.argv[:1] + ['sdist'] + \
+    sys.argv = sys.argv[:1] + ['sdist', '--formats', 'gztar'] + \
         config_settings["--global-option"] + \
         ["--dist-dir", sdist_directory]
     _run_setup()


Test patch:
diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py
index 2a0794469..82b44c894 100644
--- a/setuptools/tests/test_build_meta.py
+++ b/setuptools/tests/test_build_meta.py
@@ -172,18 +172,21 @@ def test_build_sdist_version_change(build_backend):
     sdist_name = build_backend.build_sdist(sdist_into_directory)
     assert os.path.isfile(os.path.join(sdist_into_directory, sdist_name))
 
-    # if the setup.py changes subsequent call of the build meta should still succeed, given the
+    # if the setup.py changes subsequent call of the build meta
+    # should still succeed, given the
     # sdist_directory the frontend specifies is empty
     with open(os.path.abspath("setup.py"), 'rt') as file_handler:
         content = file_handler.read()
     with open(os.path.abspath("setup.py"), 'wt') as file_handler:
-        file_handler.write(content.replace("version='0.0.0'", "version='0.0.1'"))
+        file_handler.write(
+            content.replace("version='0.0.0'", "version='0.0.1'"))
 
     shutil.rmtree(sdist_into_directory)
     os.makedirs(sdist_into_directory)
 
     sdist_name = build_backend.build_sdist("out_sdist")
-    assert os.path.isfile(os.path.join(os.path.abspath("out_sdist"), sdist_name))
+    assert os.path.isfile(
+        os.path.join(os.path.abspath("out_sdist"), sdist_name))
 
 
 def test_build_sdist_setup_py_exists(tmpdir_cwd):
@@ -215,3 +218,21 @@ def test_build_sdist_setup_py_manifest_excluded(tmpdir_cwd):
     with tarfile.open(os.path.join("temp", targz_path)) as tar:
         assert not any('setup.py' in name for name in tar.getnames())
 
+
+def test_build_sdist_builds_targz_even_if_zip_indicated(tmpdir_cwd):
+    files = {
+        'setup.py': DALS("""
+            __import__('setuptools').setup(
+                name='foo',
+                version='0.0.0',
+                py_modules=['hello']
+            )"""),
+        'hello.py': '',
+        'setup.cfg': DALS("""
+            [sdist]
+            formats=zip
+            """)
+    }
+
+    build_files(files)
+    build_sdist("temp")