Repository: wntrblm/nox (python)

Issue:
Add a single character shortcut for --no-reuse-existing-virtualenvs
### How would this feature be useful?

A common way to use Nox that saves a lot of time when re-running sessions over and over by avoiding recreating venvs is to set:

```py
nox.options.reuse_existing_virtualenvs = True
```

You can see the `pip` developers use this:

- https://github.com/pypa/pip/blob/main/noxfile.py#L19

When dependencies _do_ change, the developer can then run:

```
nox --no-reuse-existing-virtualenvs -s test
```

Given this can be a very common work flow, avoiding having to type out `--no-reuse-existing-virtualenvs` on the command line would be a great improvement to UX.

### A note on `tox`

What I'm describing above is also the default workflow for `tox` users. Many people moving from `tox` will be familiar with this workflow. (e.g. `tox` re-uses venvs by default, and `tox -r` is an opt-in recreation).

### Describe the solution you'd like

Add a new alias for `--no-reuse-existing-virtualenvs`, for example `-C` for "Create"

```
nox -C -s test
```

Pull request:
Add short -N alias for --no-reuse-existing-virtualenvs
Closes #624

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9d58716..3cfd2f0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -61,6 +61,6 @@ jobs:
       - name: Build sdist and wheel
         run: pipx run build
       - name: Publish distribution PyPI
-        uses: pypa/gh-action-pypi-publish@v1.5.0
+        uses: pypa/gh-action-pypi-publish@v1.5.1
         with:
           password: ${{ secrets.PYPI_API_TOKEN }}
diff --git a/nox/_option_set.py b/nox/_option_set.py
index 0ffcc9d..2601411 100644
--- a/nox/_option_set.py
+++ b/nox/_option_set.py
@@ -160,7 +160,7 @@ def flag_pair_merge_func(
 def make_flag_pair(
     name: str,
     enable_flags: tuple[str, str] | tuple[str],
-    disable_flags: tuple[str],
+    disable_flags: tuple[str, str] | tuple[str],
     default: bool = False,
     **kwargs: Any,
 ) -> tuple[Option, Option]:
diff --git a/nox/_options.py b/nox/_options.py
index 4f6b3ad..4129c32 100644
--- a/nox/_options.py
+++ b/nox/_options.py
@@ -363,7 +363,10 @@ options.add_options(
     *_option_set.make_flag_pair(
         "reuse_existing_virtualenvs",
         ("-r", "--reuse-existing-virtualenvs"),
-        ("--no-reuse-existing-virtualenvs",),
+        (
+            "-N",
+            "--no-reuse-existing-virtualenvs",
+        ),
         group=options.groups["environment"],
         help="Re-use existing virtualenvs instead of recreating them.",
     ),
diff --git a/nox/sessions.py b/nox/sessions.py
index d017dc8..4a66229 100644
--- a/nox/sessions.py
+++ b/nox/sessions.py
@@ -724,6 +724,7 @@ class SessionRunner:
             with cwd:
                 self._create_venv()
                 session = Session(self)
+                session.env["NOX_CURRENT_SESSION"] = session.name
                 self.func(session)
 
             # Nothing went wrong; return a success.


Test patch:
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index f753595..5f1422f 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -900,6 +900,8 @@ class TestSessionRunner:
     def make_runner_with_mock_venv(self):
         runner = self.make_runner()
         runner._create_venv = mock.Mock()
+        runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv)
+        runner.venv.env = {}
         return runner
 
     def test_execute_noop_success(self, caplog):
@@ -1017,6 +1019,23 @@ class TestSessionRunner:
 
         assert result.status == nox.sessions.Status.FAILED
 
+    def test_execute_check_env(self):
+        runner = self.make_runner_with_mock_venv()
+
+        def func(session):
+            session.run(
+                sys.executable,
+                "-c",
+                'import os; raise SystemExit(0 if os.environ["NOX_CURRENT_SESSION"] =='
+                f" {session.name!r} else 0)",
+            )
+
+        runner.func = func
+
+        result = runner.execute()
+
+        assert result
+
 
 class TestResult:
     def test_init(self):