Repository: pyca/cryptography

Issue:
cryptography_vectors is missing from `test` extra
There is missing `cryptography_vectors` in the `test` extra in `pyproject.toml` so when tests are run from sdist with the `test` extra installed then testing fails and `cryptography_vectors` needs to be installed manually to make tests passing.


Discussion:
Yes, the vectors need to be installed manually.

This is because there is no way to specify in `pyproject.toml` that we want to use the in-tree vectors when developing cryptography, and to depend on a released version of the vectors otherwise.
This issue has been waiting for a reporter response for 3 days. It will be auto-closed if no activity occurs in the next 5 days.
Maybe it is possible to somehow automatically add `cryptography_vectors` to `pyproject.toml` during the sdist tarball creation.  Or, OTOH, what harm it would cause if there is `cryptography_vectors` always in `pyproject.toml`?  During development you could satisfy that requirement easily: just install any version of `cryptography_vectors`; the actual tests would use the in-tree one.

Just ideas...
If you just specify `cryptography_vectors` sans version constraint, than you can get mis-matched versions. If you specify a version, then we're back to the problem discussed previously -- there's no way to specify the version that's correct for in-tree usage.
You do not need to specify the correct version for in-tree usage because you'll be using the in-tree version that is always correct.
What's the actual use case for any of this?
I'm packaging `cryptography` for OpenIndiana and I need to run tests to make sure the package is okay.  Since the `cryptography_vectors` is missing in the `test` extras some additional care is needed to make sure it is installed into the test environment.  This is not a big deal because it is scriptable, but it would be great if the `cryptography` testing works out of the box and we can do the `cryptography` packaging fully automatic, simple and straightforward.

Thank you.
Ok, so if we were going to do this, I guess the move would be:

- In general on `main`, there's no bound on `cryptography_vectors` -- if you use code from main it's your responsibility to ensure the right version of the vectors is installed.
- When we do a version bump for a release we add an `=={version}` bound to the dependency. This works in CI because the local vectors has the right version, and works in release because it's the right version
- When we re-open main after a release, we remove the bound

Does that match what you were describing?
Yes it does.

Resolving patch:
diff --git a/release.py b/release.py
--- a/release.py
+++ b/release.py
@@ -38,23 +38,24 @@ def release() -> None:
     run("git", "push", "--tags", "git@github.com:pyca/cryptography.git")
 
 
-def replace_version(
-    p: pathlib.Path, variable_name: str, new_version: str
-) -> None:
+def replace_pattern(p: pathlib.Path, pattern: str, replacement: str) -> None:
     content = p.read_text()
-
-    pattern = rf"^{variable_name}\s*=\s*.*$"
     match = re.search(pattern, content, re.MULTILINE)
     assert match is not None
 
     start, end = match.span()
-    new_content = (
-        content[:start] + f'{variable_name} = "{new_version}"' + content[end:]
-    )
-
+    new_content = content[:start] + replacement + content[end:]
     p.write_text(new_content)
 
 
+def replace_version(
+    p: pathlib.Path, variable_name: str, new_version: str
+) -> None:
+    replace_pattern(
+        p, rf"^{variable_name}\s*=\s*.*$", f'{variable_name} = "{new_version}"'
+    )
+
+
 @cli.command()
 @click.argument("new_version")
 def bump_version(new_version: str) -> None:
@@ -75,6 +76,19 @@ def bump_version(new_version: str) -> None:
         new_version,
     )
 
+    if Version(new_version).is_prerelease:
+        replace_pattern(
+            base_dir / "pyproject.toml",
+            r'"cryptography_vectors(==.*?)?"',
+            '"cryptography_vectors"',
+        )
+    else:
+        replace_pattern(
+            base_dir / "pyproject.toml",
+            r'"cryptography_vectors(==.*?)?"',
+            f'"cryptography_vectors=={new_version}"',
+        )
+
 
 if __name__ == "__main__":
     cli()


Test patch: