Repository: pypa/setuptools_scm

Issue:
Treat v-prefixed branch as release for release-branch-semver?
The `release-branch-semver` scheme appears to match what we do in Matplotlib pretty closely. Since we make tags like `v1,2,3`, our branches are named like `v1.2.x`. This unfortunately is not treated as a release branch because of the `v` prefix in the branch name, even though the `v` prefix is dropped from the tag.

Now, we've never made a release branch with `setuptools-scm`, so this is something we could change, but it'd require updating a bunch like docs, CI, etc.

Does this make sense to handle this prefixing in the `release-branch-semver`?

Comments:

Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 1952960..d0fd57e 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
 repos:
 -   repo: https://github.com/psf/black
-    rev: 21.5b2
+    rev: 21.6b0
     hooks:
     - id: black
       args: [--safe, --quiet]
@@ -16,7 +16,7 @@ repos:
     hooks:
     -   id: flake8
 -   repo: https://github.com/asottile/pyupgrade
-    rev: v2.19.0
+    rev: v2.19.4
     hooks:
     - id: pyupgrade
       args: [--py36-plus]
diff --git a/README.rst b/README.rst
index 62ad85c..205dc99 100644
--- a/README.rst
+++ b/README.rst
@@ -70,7 +70,7 @@ to be supplied to ``get_version()``. For example:
     # pyproject.toml
 
     [tool.setuptools_scm]
-    write_to = "pkg/version.py"
+    write_to = "pkg/_version.py"
 
 
 ``setup.py`` usage (deprecated)
@@ -316,7 +316,7 @@ The currently supported configuration keys are:
 
 :write_to:
     A path to a file that gets replaced with a file containing the current
-    version. It is ideal for creating a ``version.py`` file within the
+    version. It is ideal for creating a ``_version.py`` file within the
     package, typically used to avoid using `pkg_resources.get_distribution`
     (which adds some overhead).
 
@@ -395,7 +395,7 @@ Example configuration in ``setup.py`` format:
 
     setup(
         use_scm_version={
-            'write_to': 'version.py',
+            'write_to': '_version.py',
             'write_to_template': '__version__ = "{version}"',
             'tag_regex': r'^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$',
         }
diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py
index c560418..befa0dd 100644
--- a/src/setuptools_scm/version.py
+++ b/src/setuptools_scm/version.py
@@ -275,11 +275,15 @@ def release_branch_semver_version(version):
         # Does the branch name (stripped of namespace) parse as a version?
         branch_ver = _parse_version_tag(version.branch.split("/")[-1], version.config)
         if branch_ver is not None:
+            branch_ver = branch_ver["version"]
+            if branch_ver[0] == "v":
+                # Allow branches that start with 'v', similar to Version.
+                branch_ver = branch_ver[1:]
             # Does the branch version up to the minor part match the tag? If not it
             # might be like, an issue number or something and not a version number, so
             # we only want to use it if it matches.
             tag_ver_up_to_minor = str(version.tag).split(".")[:SEMVER_MINOR]
-            branch_ver_up_to_minor = branch_ver["version"].split(".")[:SEMVER_MINOR]
+            branch_ver_up_to_minor = branch_ver.split(".")[:SEMVER_MINOR]
             if branch_ver_up_to_minor == tag_ver_up_to_minor:
                 # We're in a release/maintenance branch, next is a patch/rc/beta bump:
                 return version.format_next_version(guess_next_version)


Test patch:
diff --git a/testing/test_version.py b/testing/test_version.py
index e90e7bf..9984a5d 100644
--- a/testing/test_version.py
+++ b/testing/test_version.py
@@ -82,6 +82,11 @@ def test_next_semver_bad_tag():
             "1.0.1.dev2",
             id="release_branch_legacy_version",
         ),
+        pytest.param(
+            meta("1.0.0", distance=2, branch="v1.0.x", config=c),
+            "1.0.1.dev2",
+            id="release_branch_with_v_prefix",
+        ),
         pytest.param(
             meta("1.0.0", distance=2, branch="release-1.0", config=c),
             "1.0.1.dev2",