Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw crash depending on tag existence #1223

Open
AntoineD opened this issue Jun 30, 2023 · 1 comment
Open

Raw crash depending on tag existence #1223

AntoineD opened this issue Jun 30, 2023 · 1 comment
Labels
bug triage Trying to make sure if this is valid or not
Milestone

Comments

@AntoineD
Copy link

Describe the problem

I get a raw traceback when the template git branch HEAD has no tag but has a parent commit with a tag.

It works if there is no tag on parent commits though.

Template

> mkdir template
> cd template
> touch copier.yml
> git init .
> git add .
> git commit -m 'WIP'
> git tag foo
> touch bar
> git add .
> git commit -m 'WIP'

To Reproduce

> copier copy  <path to template> baz
copier copy -r HEAD test xxxxx
Traceback (most recent call last):
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/copier/template.py", line 494, in version
    dunamai.Version.from_git().serialize(style=dunamai.Style.Pep440)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/dunamai/__init__.py", line 1094, in from_git
    tag, base, stage, unmatched, tagged_metadata, epoch = _match_version_pattern(
                                                          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/dunamai/__init__.py", line 244, in _match_version_pattern
    raise ValueError(_pattern_error("The pattern did not match any tags", pattern, sources))
ValueError: The pattern did not match any tags

Pattern:
(?x)                                                        (?# ignore whitespace)
    ^v((?P<epoch>\d+)!)?(?P<base>\d+(\.\d+)*)                   (?# v1.2.3 or v1!2000.1.2)
    ([-._]?((?P<stage>[a-zA-Z]+)[-._]?(?P<revision>\d+)?))?     (?# b0)
    (\+(?P<tagged_metadata>.+))?$                               (?# +linux)

Tags:
['foo']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ad/.local/bin/copier", line 8, in <module>
    sys.exit(copier_app_run())
             ^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/plumbum/cli/application.py", line 639, in run
    inst, retcode = subapp.run(argv, exit=False)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/plumbum/cli/application.py", line 634, in run
    retcode = inst.main(*tailargs)
              ^^^^^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/copier/cli.py", line 66, in handle_exceptions
    return method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/copier/cli.py", line 243, in main
    ).run_copy()
      ^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/copier/main.py", line 737, in run_copy
    f"\nCopying from template version {self.template.version}",
                                       ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/copier/template.py", line 501, in version
    return Version(f"{base}.post{count}+{git_hash}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ad/.local/pipx/venvs/copier/lib64/python3.11/site-packages/packaging/version.py", line 198, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: 'foo.post1+g4e29b5d'

Logs

No response

Expected behavior

No crash or a user friendly error message.

Screenshots/screencasts/logs

No response

Operating system

Linux

Operating system distribution and version

Fedora 37

Copier version

8.0.0

Python version

3.11

Installation method

pipx+pypi

Additional context

No response

@AntoineD AntoineD added bug triage Trying to make sure if this is valid or not labels Jun 30, 2023
@pawamoy
Copy link
Contributor

pawamoy commented Jun 30, 2023

It looks like the issue here is that your tag isn't valid semver, though I'm not sure if Copier is supposed to fail on such tags or just ignore them.

@yajo yajo added this to the Soon milestone Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Trying to make sure if this is valid or not
Projects
None yet
Development

No branches or pull requests

3 participants