peterbe / hashin

Helping you write hashed entries for packages in your requirements.txt
https://www.peterbe.com/plog/hashin
MIT License
105 stars 27 forks source link

New --index-url option is broken #108

Closed peterbe closed 5 years ago

peterbe commented 5 years ago

Shame on me for landing https://github.com/peterbe/hashin/pull/107 without properly testing it manually on the command line.

▶ python hashin.py -r /tmp/reqs.txt DJANGO -v
Traceback (most recent call last):
  File "hashin.py", line 812, in <module>
    sys.exit(main())
  File "hashin.py", line 804, in main
    index_url=args.index_url,
  File "hashin.py", line 134, in run
    return run_packages(specs, requirements_file, *args, **kwargs)
  File "hashin.py", line 196, in run_packages
    index_url=index_url,
  File "hashin.py", line 655, in get_package_hashes
    data = get_package_data(package, index_url, verbose)
  File "hashin.py", line 583, in get_package_data
    content = json.loads(_download(url))
  File "hashin.py", line 88, in _download
    r = urlopen(url)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 511, in open
    req = Request(fullurl, data)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 329, in __init__
    self.full_url = url
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 355, in full_url
    self._parse()
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 384, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: '/pypi/DJANGO/json'

The reason this happens is that url on this line becomes /pypi/DJANGO/json.

The reason is because index_url is None and that's how urljoin works.

peterbe commented 5 years ago

CC @nmacinnis