duckinator / bork

A Python build and release management tool.
https://bork.readthedocs.io
MIT License
12 stars 2 forks source link

api.download: fix `package` parsing bug #369

Closed nbraud closed 2 months ago

nbraud commented 2 months ago

Granted, IDK whether the name of PyPI packages, GitHub users, or repos can contain : at all.

Still, this shouldn't happen:

❯ python -m bork --verbose download gh:duckinator/emanate:aaa v7.0.0
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/nicoo/dev/py/puppy/bork/bork/__main__.py", line 3, in <module>
    cli.main()
  File "/home/nicoo/dev/py/puppy/bork/bork/cli.py", line 248, in main
    args.func(args)
  File "/home/nicoo/dev/py/puppy/bork/bork/cli.py", line 96, in download
    api.download(package, release_tag, files, directory)
  File "/home/nicoo/dev/py/puppy/bork/bork/api.py", line 77, in download
    source, package = package.split(':')
    ^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)
nbraud commented 2 months ago

Amusingly, fixing this causes a longer stacktrace:

❯ python -m bork --verbose download gh:duckinator/emanate:aaa v7.0.0
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/nicoo/dev/py/puppy/bork/bork/__main__.py", line 3, in <module>
    cli.main()
  File "/home/nicoo/dev/py/puppy/bork/bork/cli.py", line 248, in main
    args.func(args)
  File "/home/nicoo/dev/py/puppy/bork/bork/cli.py", line 96, in download
    api.download(package, release_tag, files, directory)
  File "/home/nicoo/dev/py/puppy/bork/bork/api.py", line 89, in download
    download(package, release_tag, file_pattern, directory) # type:ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/mhl5v3n5mwksxm8j2kdis3a0x6sbsw13-python3-3.12.4-env/lib/python3.12/site-packages/homf/api/github.py", line 61, in download
    release_info = _get_release_info(repo, release, file_pattern)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/mhl5v3n5mwksxm8j2kdis3a0x6sbsw13-python3-3.12.4-env/lib/python3.12/site-packages/homf/api/github.py", line 26, in _get_release_info
    with urlopen(url) as f:
         ^^^^^^^^^^^^
  File "/nix/store/l014xp1qxdl6gim3zc0jv3mpxhbp346s-python3-3.12.4/lib/python3.12/urllib/request.py", line 215, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/l014xp1qxdl6gim3zc0jv3mpxhbp346s-python3-3.12.4/lib/python3.12/urllib/request.py", line 521, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/nix/store/l014xp1qxdl6gim3zc0jv3mpxhbp346s-python3-3.12.4/lib/python3.12/urllib/request.py", line 630, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/nix/store/l014xp1qxdl6gim3zc0jv3mpxhbp346s-python3-3.12.4/lib/python3.12/urllib/request.py", line 559, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/l014xp1qxdl6gim3zc0jv3mpxhbp346s-python3-3.12.4/lib/python3.12/urllib/request.py", line 492, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/nix/store/l014xp1qxdl6gim3zc0jv3mpxhbp346s-python3-3.12.4/lib/python3.12/urllib/request.py", line 639, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found