nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: theacodes/nox
Pull request #119 (2018-08-24 23:41:50)

Using more specific regex in `_resolved_interpreter()`.


Patch:
diff --git a/nox/virtualenv.py b/nox/virtualenv.py
index 8942290..3dc1aba 100644
--- a/nox/virtualenv.py
+++ b/nox/virtualenv.py
@@ -108,13 +108,9 @@ class VirtualEnv(ProcessEnv):
 
         # If this is just a X, X.Y, or X.Y.Z string, extract just the X / X.Y
         # part and add Python to the front of it.
-        match = re.match(r"^([\d\.]+?)$", self.interpreter)
+        match = re.match(r"^(?P<xy_ver>\d(\.\d)?)(\.\d+)?$", self.interpreter)
         if match:
-            parts = match.group(1).split(".")
-            if len(parts) > 2:
-                parts = parts[:2]
-
-            self.interpreter = "python{}".format(".".join(parts))
+            self.interpreter = "python{}".format(match.group("xy_ver"))
 
         # Sanity check: We only need the rest of this behavior on Windows.
         if platform.system() != "Windows":


Test patch:
diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py
index 78b41f2..4e8cce8 100644
--- a/tests/test_virtualenv.py
+++ b/tests/test_virtualenv.py
@@ -163,11 +163,18 @@ def test__resolved_interpreter_none(make_one):
 
 
 @pytest.mark.parametrize(
-    ["input", "expected"],
-    [("3", "python3"), ("3.6", "python3.6"), ("3.6.2", "python3.6")],
+    ["input_", "expected"],
+    [
+        ("3", "python3"),
+        ("3.6", "python3.6"),
+        ("3.6.2", "python3.6"),
+        ("2.", "2."),
+        ("2.7.", "2.7."),
+        ("2.7.15", "python2.7"),
+    ],
 )
-def test__resolved_interpreter_numerical_non_windows(make_one, input, expected):
-    venv, _ = make_one(interpreter=input)
+def test__resolved_interpreter_numerical_non_windows(make_one, input_, expected):
+    venv, _ = make_one(interpreter=input_)
     with mock.patch.object(platform, "system") as system:
         system.return_value = "Linux"
         assert venv._resolved_interpreter == expected
Repository: theacodes/nox
Pull request #151 (2018-10-17 17:24:48)

Fix bug where empty parametrized sessions would fail.


Patch:
diff --git a/nox/manifest.py b/nox/manifest.py
index caf0785..2b87314 100644
--- a/nox/manifest.py
+++ b/nox/manifest.py
@@ -275,3 +275,6 @@ def keyword_match(expression, keywords):
 def _null_session_func(session):
     """A no-op session for patemetrized sessions with no available params."""
     session.skip("This session had no parameters available.")
+
+
+_null_session_func.python = False


Test patch:
diff --git a/tests/test_manifest.py b/tests/test_manifest.py
index 91689cf..e94eb97 100644
--- a/tests/test_manifest.py
+++ b/tests/test_manifest.py
@@ -210,6 +210,10 @@ def test_add_session_parametrized_noop():
         manifest.add_session(session)
     assert len(manifest) == 1
 
+    session = manifest["my_session"]
+
+    assert session.func == _null_session_func
+
 
 def test_notify():
     manifest = Manifest({}, mock.sentinel.CONFIG)
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index ea4ee73..2f5a576 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -385,6 +385,15 @@ class TestSessionRunner:
 
         assert result.status == nox.sessions.Status.SKIPPED
 
+    def test_execute_with_manifest_null_session_func(self):
+        runner = self.make_runner()
+        runner.func = nox.manifest._null_session_func
+
+        result = runner.execute()
+
+        assert result.status == nox.sessions.Status.SKIPPED
+        assert "no parameters" in result.reason
+
     def test_execute_skip_missing_interpreter(self):
         runner = self.make_runner_with_mock_venv()
         runner._create_venv.side_effect = nox.virtualenv.InterpreterNotFound("meep")
Repository: theacodes/nox
Pull request #155 (2018-11-04 05:26:15)

Fix function name on docs
I believe this was old nox


Patch:
diff --git a/docs/usage.rst b/docs/usage.rst
index a30932d..6d51c81 100644
--- a/docs/usage.rst
+++ b/docs/usage.rst
@@ -69,7 +69,7 @@ Specifying parametrized sessions
 If you have a :ref:`parametrized <parametrized>` session such as::
 
     @nox.parametrize('django', ['1.9', '2.0'])
-    def session_tests(session, django):
+    def tests(session, django):
         ...
 
 Then running ``nox --session tests`` will actually run all parametrized versions of the session. If you want the run the session with a particular set of parametrized arguments, you can specify them with the session name::
diff --git a/nox/sessions.py b/nox/sessions.py
index 0ddf790..a3b0c54 100644
--- a/nox/sessions.py
+++ b/nox/sessions.py
@@ -232,15 +232,10 @@ class Session:
         if not args:
             raise ValueError("At least one argument required to install().")
 
-        self.run(
-            "pip",
-            "install",
-            "--upgrade",
-            *args,
-            silent=True,
-            external="error",
-            **kwargs
-        )
+        if "silent" not in kwargs:
+            kwargs["silent"] = True
+
+        self.run("pip", "install", "--upgrade", *args, external="error", **kwargs)
 
     def notify(self, target):
         """Place the given session at the end of the queue.


Test patch:
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index 2f5a576..7b4c514 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -199,6 +199,34 @@ class TestSession:
                 external="error",
             )
 
+    def test_install_non_default_kwargs(self):
+        runner = nox.sessions.SessionRunner(
+            name="test",
+            signatures=["test"],
+            func=mock.sentinel.func,
+            global_config=argparse.Namespace(posargs=mock.sentinel.posargs),
+            manifest=mock.create_autospec(nox.manifest.Manifest),
+        )
+        runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv)
+        runner.venv.env = {}
+
+        class SessionNoSlots(nox.sessions.Session):
+            pass
+
+        session = SessionNoSlots(runner=runner)
+
+        with mock.patch.object(session, "run", autospec=True) as run:
+            session.install("requests", "urllib3", silent=False)
+            run.assert_called_once_with(
+                "pip",
+                "install",
+                "--upgrade",
+                "requests",
+                "urllib3",
+                silent=False,
+                external="error",
+            )
+
     def test_notify(self):
         session, runner = self.make_session_and_runner()
Repository: theacodes/nox
Pull request #157 (2018-11-04 16:49:44)

Allow silent argument to be set in session.install
Addresses #156 by checking if `silent` is in the kwargs passed to `session.install()`. If not, it sets it to the default True.

theacodes: Thanks, @erinwild-rubikloud!

Patch:
diff --git a/nox/sessions.py b/nox/sessions.py
index 0ddf790..a3b0c54 100644
--- a/nox/sessions.py
+++ b/nox/sessions.py
@@ -232,15 +232,10 @@ class Session:
         if not args:
             raise ValueError("At least one argument required to install().")
 
-        self.run(
-            "pip",
-            "install",
-            "--upgrade",
-            *args,
-            silent=True,
-            external="error",
-            **kwargs
-        )
+        if "silent" not in kwargs:
+            kwargs["silent"] = True
+
+        self.run("pip", "install", "--upgrade", *args, external="error", **kwargs)
 
     def notify(self, target):
         """Place the given session at the end of the queue.


Test patch:
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index 2f5a576..7b4c514 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -199,6 +199,34 @@ class TestSession:
                 external="error",
             )
 
+    def test_install_non_default_kwargs(self):
+        runner = nox.sessions.SessionRunner(
+            name="test",
+            signatures=["test"],
+            func=mock.sentinel.func,
+            global_config=argparse.Namespace(posargs=mock.sentinel.posargs),
+            manifest=mock.create_autospec(nox.manifest.Manifest),
+        )
+        runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv)
+        runner.venv.env = {}
+
+        class SessionNoSlots(nox.sessions.Session):
+            pass
+
+        session = SessionNoSlots(runner=runner)
+
+        with mock.patch.object(session, "run", autospec=True) as run:
+            session.install("requests", "urllib3", silent=False)
+            run.assert_called_once_with(
+                "pip",
+                "install",
+                "--upgrade",
+                "requests",
+                "urllib3",
+                silent=False,
+                external="error",
+            )
+
     def test_notify(self):
         session, runner = self.make_session_and_runner()
Repository: theacodes/nox
Pull request #386 (2021-02-14 01:52:59)

Add `Session.name`
Being able to know what session you are in is useful for a variety of reasons. One of which is to be able to name artifacts in a way that is traceable back to the session, such as with [code coverage reports](https://stackoverflow.com/q/66170792/1485877). Right now, the only solution is to dig down to `session._runner.friendly_name`:

```python
import nox


@nox.session(python=['3.6', '3.7', '3.8', '3.9'])
def test(session):
    session.install('.')
    session.install('pytest', 'pytest-cov')
    session.env['COVERAGE_FILE'] = f'.coverage.{session._runner.friendly_name}'
    session.run('python', '-m', 'pytest', '--cov', 'tests/')
```

This PR exposes that private attribute via a public property:

```python
import nox


@nox.session(python=['3.6', '3.7', '3.8', '3.9'])
def test(session):
    session.install('.')
    session.install('pytest', 'pytest-cov')
    session.env['COVERAGE_FILE'] = f'.coverage.{session.name}'
    session.run('python', '-m', 'pytest', '--cov', 'tests/')
```


Patch:
diff --git a/nox/sessions.py b/nox/sessions.py
index 96d80eb..78cdcbb 100644
--- a/nox/sessions.py
+++ b/nox/sessions.py
@@ -137,6 +137,11 @@ class Session:
         """
         return {"_runner": self._runner}
 
+    @property
+    def name(self) -> str:
+        """The name of this session."""
+        return self._runner.friendly_name
+
     @property
     def env(self) -> dict:
         """A dictionary of environment variables to pass into all commands."""


Test patch:
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index 2d4cf11..8bb9b78 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -98,6 +98,7 @@ class TestSession:
     def test_properties(self):
         session, runner = self.make_session_and_runner()
 
+        assert session.name is runner.friendly_name
         assert session.env is runner.venv.env
         assert session.posargs is runner.global_config.posargs
         assert session.virtualenv is runner.venv