Repository: pypa/setuptools_scm

Issue:
How to use `write_to_template` parameter?
Would someone please show an example or two of how to use the `write_to_template` parameter? 

I've tried using some of the patterns listed in https://github.com/pypa/setuptools_scm#default-versioning-scheme but they exit with KeyError

~~~
scm_version_options = {
    'write_to_template': '{tag}+dYYYMMMDD',
    'write_to' : 'version.py'
    }
setup(
    name = 'leo',
    use_scm_version = scm_version_options,
    setup_requires=['setuptools_scm'],
    ...snip...
    )
~~~

~~~
>python setup.py check
Traceback (most recent call last):
  File "setup.py", line 81, in <module>
    'gui_scripts' : ['leo = leo.core.runLeo:run']
  File "C:\apps\Miniconda3\lib\distutils\core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "C:\apps\Miniconda3\lib\site-packages\setuptools\dist.py", line 338, in __init__
    _Distribution.__init__(self, attrs)
  File "C:\apps\Miniconda3\lib\distutils\dist.py", line 281, in __init__
    self.finalize_options()
  File "C:\apps\Miniconda3\lib\site-packages\setuptools\dist.py", line 471, in finalize_options
    ep.load()(self, ep.name, value)
  File "C:\apps\Miniconda3\lib\site-packages\setuptools_scm\integration.py", line 22, in version_keyword
    dist.metadata.version = get_version(**value)
  File "C:\apps\Miniconda3\lib\site-packages\setuptools_scm\__init__.py", line 130, in get_version
    template=write_to_template)
  File "C:\apps\Miniconda3\lib\site-packages\setuptools_scm\__init__.py", line 50, in dump_version
    dump = template.format(version=version)
KeyError: 'tag'
~~~


AssertionError: cant parse version apache-arrow-0.9.0
I'm getting the following error with 3.0.1:
```
/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
  warnings.warn(msg)
/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools_scm/version.py:92: UserWarning: tag 'apache-arrow-0.9.0' no version found
  warnings.warn("tag %r no version found" % (tag,))
Traceback (most recent call last):
  File "setup.py", line 545, in <module>
    url="https://arrow.apache.org/"
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools/__init__.py", line 129, in setup
    return distutils.core.setup(**attrs)
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools/dist.py", line 372, in __init__
    _Distribution.__init__(self, attrs)
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/distutils/dist.py", line 287, in __init__
    self.finalize_options()
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools/dist.py", line 528, in finalize_options
    ep.load()(self, ep.name, value)
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools_scm/integration.py", line 23, in version_keyword
    dist.metadata.version = get_version(**value)
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools_scm/__init__.py", line 128, in get_version
    parsed_version = _do_parse(config)
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools_scm/__init__.py", line 73, in _do_parse
    parse_result = _call_entrypoint_fn(config, config.parse)
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools_scm/__init__.py", line 36, in _call_entrypoint_fn
    return fn(config.absolute_root)
  File "setup.py", line 496, in parse_version
    version = setuptools_scm.git.parse(root, describe)
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools_scm/git.py", line 131, in parse
    branch=branch,
  File "/home/antoine/miniconda3/envs/pyarrow27/lib/python2.7/site-packages/setuptools_scm/version.py", line 184, in meta
    assert parsed_version is not None, "cant parse version %s" % tag
AssertionError: cant parse version apache-arrow-0.9.0
```

Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index bd68fab..ea83b4e 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,7 +1,13 @@
+v3.0.2
+======
+
+* fix a regression from tag parsing - support for multi-dashed prefixes - #284
+
+
 v3.0.1
 =======
 
-* fix a regression in setuptools_scm.git.parse - reorder arguments so the positional invocation from before works as expected
+* fix a regression in setuptools_scm.git.parse - reorder arguments so the positional invocation from before works as expected #281
 
 v3.0.0
 =======
diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py
index 58be234..49c0c4b 100644
--- a/src/setuptools_scm/__init__.py
+++ b/src/setuptools_scm/__init__.py
@@ -29,10 +29,14 @@ def version_from_scm(root):
 
 
 def _call_entrypoint_fn(config, fn):
-    if function_has_arg(fn, 'config'):
+    if function_has_arg(fn, "config"):
         return fn(config.absolute_root, config=config)
     else:
-        warnings.warn("parse functions are required to provide a named argument 'config' in the future.", PendingDeprecationWarning)
+        warnings.warn(
+            "parse functions are required to provide a named argument"
+            " 'config' in the future.",
+            PendingDeprecationWarning,
+        )
         return fn(config.absolute_root)
 
 
@@ -75,13 +79,16 @@ def _do_parse(config):
             raise TypeError(
                 "version parse result was a string\nplease return a parsed version"
             )
-        version = parse_result or \
-            _version_from_entrypoint(config, "setuptools_scm.parse_scm_fallback")
-    
+        version = parse_result or _version_from_entrypoint(
+            config, "setuptools_scm.parse_scm_fallback"
+        )
     else:
         # include fallbacks after dropping them from the main entrypoint
-        version = _version_from_entrypoint(config, "setuptools_scm.parse_scm") or \
-            _version_from_entrypoint(config, "setuptools_scm.parse_scm_fallback")
+        version = _version_from_entrypoint(
+            config, "setuptools_scm.parse_scm"
+        ) or _version_from_entrypoint(
+            config, "setuptools_scm.parse_scm_fallback"
+        )
 
     if version:
         return version
@@ -114,7 +121,7 @@ def get_version(
     in the root of the repository to direct setuptools_scm to the
     root of the repository by supplying ``__file__``.
     """
-    
+
     config = Configuration()
     config.root = root
     config.version_scheme = version_scheme
diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py
index dbd3768..b1c07f8 100644
--- a/src/setuptools_scm/config.py
+++ b/src/setuptools_scm/config.py
@@ -6,8 +6,8 @@ import warnings
 
 from .utils import trace
 
-DEFAULT_TAG_REGEX = r'^(?:\w+-)?(?P<version>v?\d+(?:\.\d+){0,2}[^\+]+)(?:\+.*)?$'
-DEFAULT_VERSION_SCHEME = 'version_scheme'
+DEFAULT_TAG_REGEX = r"^(?:[\w-]+-)?(?P<version>v?\d+(?:\.\d+){0,2}[^\+]+)(?:\+.*)?$"
+DEFAULT_VERSION_SCHEME = "version_scheme"
 
 
 def _check_tag_regex(value):
@@ -16,9 +16,11 @@ def _check_tag_regex(value):
     regex = re.compile(value)
 
     group_names = regex.groupindex.keys()
-    if regex.groups == 0 or (regex.groups > 1 and 'version' not in group_names):
-        warnings.warn("Expected tag_regex to contain a single match group or a group named 'version' " +
-                      "to identify the version part of any tag.")
+    if regex.groups == 0 or (regex.groups > 1 and "version" not in group_names):
+        warnings.warn(
+            "Expected tag_regex to contain a single match group or a group named"
+            " 'version' to identify the version part of any tag."
+        )
 
     return regex
 
@@ -26,7 +28,10 @@ def _check_tag_regex(value):
 def _check_absolute_root(root, relative_to):
     if relative_to:
         if os.path.isabs(root) and not root.startswith(relative_to):
-            warnings.warn("absolute root path '%s' overrides relative_to '%s'" % (root, relative_to))
+            warnings.warn(
+                "absolute root path '%s' overrides relative_to '%s'"
+                % (root, relative_to)
+            )
         root = os.path.join(os.path.dirname(relative_to), root)
     return os.path.abspath(root)
 
@@ -44,17 +49,15 @@ class Configuration(object):
     _tag_regex = None
     _absolute_root = None
 
-    def __init__(self,
-                 relative_to=None,
-                 root='.'):
+    def __init__(self, relative_to=None, root="."):
         # TODO:
         self._relative_to = relative_to
-        self._root = '.'
+        self._root = "."
 
         self.root = root
         self.version_scheme = DEFAULT_VERSION_SCHEME
         self.local_scheme = "node-and-date"
-        self.write_to = ''
+        self.write_to = ""
         self.write_to_template = None
         self.parse = None
         self.tag_regex = DEFAULT_TAG_REGEX


Test patch:
diff --git a/testing/test_config.py b/testing/test_config.py
new file mode 100644
index 0000000..89181b8
--- /dev/null
+++ b/testing/test_config.py
@@ -0,0 +1,18 @@
+from setuptools_scm.config import Configuration
+
+import pytest
+
+
+@pytest.mark.parametrize(
+    "tag, expected_version",
+    [
+        ("apache-arrow-0.9.0", "0.9.0"),
+        ("arrow-0.9.0", "0.9.0"),
+        ("arrow-0.9.0-rc", "0.9.0-rc"),
+    ],
+)
+def test_tag_regex(tag, expected_version):
+    config = Configuration()
+    match = config.tag_regex.match(tag)
+    version = match.group("version")
+    assert version == expected_version