nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pypa/setuptools
Pull request #4982 (2025-05-05 05:07:54)

Mark new tests as `uses_network`
## Summary of changes

Mark a few new tests that try to install stuff from PyPI via `pip` as `uses_network`.

To reproduce:

```
tox -e py313
sudo unshare -n sudo -u $USER sh -c '. .tox/py313/bin/activate && pytest -m "not uses_network"'
```

### Pull Request Checklist
- [ ] Changes have tests
- [x] News fragment added in [`newsfragments/`].
  _(See [documentation][PR docs] for details)_


[`newsfragments/`]: https://github.com/pypa/setuptools/tree/main/newsfragments
[PR docs]:
https://setuptools.pypa.io/en/latest/development/developer-guide.html#making-a-pull-request



Patch:
diff --git a/newsfragments/4982.misc.rst b/newsfragments/4982.misc.rst
new file mode 100644
index 000000000..8e4075430
--- /dev/null
+++ b/newsfragments/4982.misc.rst
@@ -0,0 +1,1 @@
+Mark more tests failing without Internet access as ``uses_network``.


Test patch:
diff --git a/setuptools/tests/integration/test_pbr.py b/setuptools/tests/integration/test_pbr.py
index a3e4e095c..f89e5b8b2 100644
--- a/setuptools/tests/integration/test_pbr.py
+++ b/setuptools/tests/integration/test_pbr.py
@@ -1,6 +1,9 @@
 import subprocess
 
+import pytest
 
+
+@pytest.mark.uses_network
 def test_pbr_integration(pbr_package, venv):
     """Ensure pbr packages install."""
     cmd = [
diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py
index 67495b89c..354c51fc3 100644
--- a/setuptools/tests/test_develop.py
+++ b/setuptools/tests/test_develop.py
@@ -70,6 +70,7 @@ class TestNamespaces:
         platform.python_implementation() == 'PyPy',
         reason="https://github.com/pypa/setuptools/issues/1202",
     )
+    @pytest.mark.uses_network
     def test_namespace_package_importable(self, tmpdir):
         """
         Installing two packages sharing the same namespace, one installed
diff --git a/setuptools/tests/test_editable_install.py b/setuptools/tests/test_editable_install.py
index 5d85f2fb6..031f36384 100644
--- a/setuptools/tests/test_editable_install.py
+++ b/setuptools/tests/test_editable_install.py
@@ -1068,6 +1068,7 @@ def test_compat_install(tmp_path, venv):
     assert "cannot import name 'subpackage'" in out
 
 
+@pytest.mark.uses_network
 def test_pbr_integration(pbr_package, venv, editable_opts):
     """Ensure editable installs work with pbr, issue #3500"""
     cmd = [
Repository: pypa/setuptools_scm
Pull request #227 (2018-03-19 19:41:23)

git: ignore directory of the git archive output
Since 1.16.0, if the git project have subdirectory, bdist fails.

For example:

running bdist_wheel
running build
running build_py
running egg_info
writing requirements to gnocchi.egg-info/requires.txt
writing gnocchi.egg-info/PKG-INFO
writing top-level names to gnocchi.egg-info/top_level.txt
writing dependency_links to gnocchi.egg-info/dependency_links.txt
writing entry points to gnocchi.egg-info/entry_points.txt
reading manifest template 'MANIFEST.in'
writing manifest file 'gnocchi.egg-info/SOURCES.txt'
error: can't copy 'gnocchi/cli': doesn't exist or not a regular file

gnocchi/cli is a directory here.

This change ignores directory of "git archive" output to fix the issue.

devkral: there is a better solution, wait a moment
devkral: sry, I was wrong. Your solution is better.

Patch:
diff --git a/setuptools_scm/git.py b/setuptools_scm/git.py
index 6ec9962..83898ec 100644
--- a/setuptools_scm/git.py
+++ b/setuptools_scm/git.py
@@ -129,8 +129,9 @@ def _list_files_in_archive():
     cmd = ['git', 'archive', 'HEAD']
     proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
     tf = tarfile.open(fileobj=proc.stdout, mode='r|*')
-    for name in tf.getnames():
-        print(name)
+    for member in tf.getmembers():
+        if member.type != tarfile.DIRTYPE:
+            print(member.name)
 
 
 if __name__ == "__main__":


Test patch:
diff --git a/testing/test_git.py b/testing/test_git.py
index 4f4ad53..e829fc8 100644
--- a/testing/test_git.py
+++ b/testing/test_git.py
@@ -124,3 +124,12 @@ def test_git_archive_export_ignore(wd):
     wd('git add test1.txt test2.txt')
     wd.commit()
     assert integration.find_files(str(wd.cwd)) == ['test1.txt']
+
+
+@pytest.mark.issue(228)
+def test_git_archive_subdirectory(wd):
+    wd('mkdir foobar')
+    wd.write('foobar/test1.txt', 'test')
+    wd('git add foobar')
+    wd.commit()
+    assert integration.find_files(str(wd.cwd)) == ['foobar/test1.txt']
Repository: pypa/setuptools_scm
Pull request #670 (2022-01-18 10:05:15)

6.4.0 bugfixes
* #668 
* #669 


Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 537b9ec..e39a66b 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,4 +1,9 @@
+v6.4.1
+=======
+
 
+* fix regression #669: restore get_version signature
+* fix #668: harden the selftest for distribution extras
 
 6.4.0
 ======
diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py
index 4c91a36..eb671f7 100644
--- a/src/setuptools_scm/__init__.py
+++ b/src/setuptools_scm/__init__.py
@@ -111,8 +111,24 @@ def _version_missing(config) -> NoReturn:
     )
 
 
-@_types.transfer_input_args(Configuration)
-def get_version(**kw) -> str:
+def get_version(
+    root=".",
+    version_scheme=DEFAULT_VERSION_SCHEME,
+    local_scheme=DEFAULT_LOCAL_SCHEME,
+    write_to=None,
+    write_to_template=None,
+    relative_to=None,
+    tag_regex=DEFAULT_TAG_REGEX,
+    parentdir_prefix_version=None,
+    fallback_version=None,
+    fallback_root=".",
+    parse=None,
+    git_describe_command=None,
+    dist_name=None,
+    version_cls=None,
+    normalize=True,
+    search_parent_directories=False,
+):
     """
     If supplied, relative_to should be a file from which root may
     be resolved. Typically called by a script or module that is not
@@ -120,7 +136,7 @@ def get_version(**kw) -> str:
     root of the repository by supplying ``__file__``.
     """
 
-    config = Configuration(**kw)
+    config = Configuration(**locals())
     maybe_version = _get_version(config)
     if maybe_version is None:
         _version_missing(config)


Test patch:
diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py
index bb3b4ed..55bf346 100644
--- a/testing/test_basic_api.py
+++ b/testing/test_basic_api.py
@@ -58,9 +58,12 @@ def test_version_from_scm(wd):
         setuptools_scm.version_from_scm(str(wd))
 
 
-def test_root_parameter_pass_by(monkeypatch, tmpdir):
-    assert_root(monkeypatch, tmpdir)
-    setuptools_scm.get_version(root=tmpdir.strpath)
+def test_root_parameter_pass_by(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
+    assert_root(monkeypatch, os.fspath(tmp_path))
+    setuptools_scm.get_version(root=os.fspath(tmp_path))
+    setuptools_scm.get_version(
+        os.fspath(tmp_path)
+    )  # issue 669 - posarg difference between Configuration and get_version
 
 
 def test_parentdir_prefix(tmpdir, monkeypatch):
diff --git a/testing/test_integration.py b/testing/test_integration.py
index c0a2297..23d8966 100644
--- a/testing/test_integration.py
+++ b/testing/test_integration.py
@@ -142,11 +142,11 @@ def testwarn_on_broken_setuptools():
 
 
 @pytest.mark.issue(611)
-def test_provides_toml_exta():
+def test_distribution_procides_extras():
     try:
         from importlib.metadata import distribution
     except ImportError:
         from importlib_metadata import distribution
 
     dist = distribution("setuptools_scm")
-    assert "toml" in dist.metadata["Provides-Extra"]
+    assert sorted(dist.metadata.get_all("Provides-Extra")) == ["test", "toml"]
Repository: pypa/setuptools_scm
Pull request #685 (2022-02-14 06:02:48)

fix: empty environment variable breaks versioning
`pretended` should only have an effect if it is set to something - anything, even `"0"`, but not if it's an empty string. This restores that behavior instead of setting 0.0.0 automatically.

If `SETUPTOOLS_SCM_PRETEND_VERSION_FOR_X` is an empty string, this will also cause the native behavior to be restored, giving a way to unset the `SETUPTOOLS_SCM_PRETEND_VERSION` for a single package.

If you want `SETUPTOOLS_SCM_PRETEND_VERSION_FOR_X=""` to cause `SETUPTOOLS_SCM_PRETEND_VERSION` to be used instead, as if it was undefined, that could be done as well, it would require one more explicit None check to be broadened above.


Assuming git = 1.0, `SETUPTOOLS_SCM_PRETEND_VERSION_FOR_X=""`,  `SETUPTOOLS_SCM_PRETEND_VERSION="2.0"`, this PR would produce 2.0 for everything except X, which would get 1.0. The alternative mentioned above would produce 2.0 for everything, including X.


Patch:
diff --git a/src/setuptools_scm/_overrides.py b/src/setuptools_scm/_overrides.py
index 644e87d..00876e0 100644
--- a/src/setuptools_scm/_overrides.py
+++ b/src/setuptools_scm/_overrides.py
@@ -29,7 +29,7 @@ def _read_pretended_version_for(config: Configuration) -> Optional[ScmVersion]:
     if pretended is None:
         pretended = os.environ.get(PRETEND_KEY)
 
-    if pretended is not None:
+    if pretended:
         # we use meta here since the pretended version
         # must adhere to the pep to begin with
         return meta(tag=pretended, preformatted=True, config=config)


Test patch:
diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py
index 55bf346..02ea82f 100644
--- a/testing/test_basic_api.py
+++ b/testing/test_basic_api.py
@@ -90,6 +90,33 @@ setup(use_scm_version={"fallback_version": "12.34"})
     assert res == "12.34"
 
 
+def test_empty_pretend_version(tmpdir, monkeypatch):
+    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
+    monkeypatch.setenv("SETUPTOOLS_SCM_PRETEND_VERSION", "")
+    p = tmpdir.ensure("sub/package", dir=1)
+    p.join("setup.py").write(
+        """from setuptools import setup
+setup(use_scm_version={"fallback_version": "12.34"})
+"""
+    )
+    res = do((sys.executable, "setup.py", "--version"), p)
+    assert res == "12.34"
+
+
+def test_empty_pretend_version_named(tmpdir, monkeypatch):
+    monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
+    monkeypatch.setenv("SETUPTOOLS_SCM_PRETEND_VERSION", "1.23")
+    monkeypatch.setenv("SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MYSCM", "")
+    p = tmpdir.ensure("sub/package", dir=1)
+    p.join("setup.py").write(
+        """from setuptools import setup
+setup(name="myscm", use_scm_version={"fallback_version": "12.34"})
+"""
+    )
+    res = do((sys.executable, "setup.py", "--version"), p)
+    assert res == "12.34"
+
+
 @pytest.mark.parametrize(
     "version", ["1.0", "1.2.3.dev1+ge871260", "1.2.3.dev15+ge871260.d20180625", "2345"]
 )
Repository: pypa/setuptools_scm
Pull request #896 (2023-09-11 12:35:55)

fix mime parsing - ignore potential mime headers after end of headers


Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 85da487..06a9c27 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -39,6 +39,11 @@ features
 * support using rich.logging as console log handler if installed
 * fix #527: type annotation in default version template
 
+bugfixes
+--------
+
+* fix #883: use HeadersParser to ensure only mime metadata in headers is used
+
 v7.1.0
 ======
 
diff --git a/src/setuptools_scm/integration.py b/src/setuptools_scm/integration.py
index 2583f47..390b0a7 100644
--- a/src/setuptools_scm/integration.py
+++ b/src/setuptools_scm/integration.py
@@ -9,11 +9,22 @@ from . import _types as _t
 log = logging.getLogger(__name__)
 
 
-def data_from_mime(path: _t.PathT) -> dict[str, str]:
-    content = Path(path).read_text(encoding="utf-8")
+def data_from_mime(path: _t.PathT, content: None | str = None) -> dict[str, str]:
+    """return a mapping from mime/pseudo-mime content
+    :param path: path to the mime file
+    :param content: content of the mime file, if None, read from path
+    :rtype: dict[str, str]
+
+    """
+
+    if content is None:
+        content = Path(path).read_text(encoding="utf-8")
     log.debug("mime %s content:\n%s", path, textwrap.indent(content, "    "))
-    # the complex conditions come from reading pseudo-mime-messages
-    data = dict(x.split(": ", 1) for x in content.splitlines() if ": " in x)
 
+    from email.parser import HeaderParser
+
+    parser = HeaderParser()
+    message = parser.parsestr(content)
+    data = dict(message.items())
     log.debug("mime %s data:\n%s", path, data)
     return data


Test patch:
diff --git a/testing/test_regressions.py b/testing/test_regressions.py
index 2720cfa..6bd5246 100644
--- a/testing/test_regressions.py
+++ b/testing/test_regressions.py
@@ -12,6 +12,14 @@ import pytest
 from setuptools_scm import Configuration
 from setuptools_scm._run_cmd import run
 from setuptools_scm.git import parse
+from setuptools_scm.integration import data_from_mime
+
+
+def test_data_from_mime_ignores_body() -> None:
+    assert data_from_mime(
+        "test",
+        "version: 1.0\r\n\r\nversion: bad",
+    ) == {"version": "1.0"}
 
 
 def test_pkginfo_noscmroot(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: