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

make hashin work as a library #31

Merged
merged 2 commits into from
Feb 27, 2017
Merged

make hashin work as a library #31

merged 2 commits into from
Feb 27, 2017

Conversation

jayfk
Copy link
Contributor

@jayfk jayfk commented Dec 6, 2016

I've refactored the code so that hashin can be used as a library (#29).

import hashin
hashin.get_package_hashes('hashin')
    {
        "package": "hashin",
        "version": "0.10",
        "hashes": [
            {
                'url': 'https://pypi.python.org/packages/[...]',
                'hash': '45d1c5d2237a3b4f78b4198709fb2ecf[...]'
            },
            {
                'url': 'https://pypi.python.org/packages/[...]',
                'hash': '0d63bf4c115154781846ecf573049324[...]'
            },
            {
                'url': 'https://pypi.python.org/packages/[...]',
                'hash': 'c32e6d9fb09dc36ab9222c4606a1f43a[...]'
            }
        ]
    }

@peterbe
Copy link
Owner

peterbe commented Dec 6, 2016

Awesome. I'll try to dig into it this week.

@peterbe
Copy link
Owner

peterbe commented Dec 13, 2016

It breaks the version. See:

dev/PYTHON/hashin  (0140f07...) ✔                                                                                                                                                                               7d
▶ touch /tmp/reqs.txt; python hashin.py -r /tmp/reqs.txt DjanGO
(hashin)
dev/PYTHON/hashin  (0140f07...) ✔                                                                                                                                                                               7d
▶ cat /tmp/reqs.txt
Django==None \
    --hash=sha256:a8e1a552205cda15023c39ecf17f7e525e96c5b0142e7879e8bd0c445351f2cc \
    --hash=sha256:fff7f062e510d812badde7cfc57745b7779edb4d209b2bc5ea8d954c22305c2b
(hashin)

If I do the same with the master branch it works:

dev/PYTHON/hashin  master ✔                                                                                                                                                                                    97d
▶ rm -fr /tmp/reqs.txt;  touch /tmp/reqs.txt; python hashin.py -r /tmp/reqs.txt DjanGO
(hashin)
dev/PYTHON/hashin  master ✔                                                                                                                                                                                    97d
▶ cat /tmp/reqs.txt
Django==1.10.4 \
    --hash=sha256:a8e1a552205cda15023c39ecf17f7e525e96c5b0142e7879e8bd0c445351f2cc \
    --hash=sha256:fff7f062e510d812badde7cfc57745b7779edb4d209b2bc5ea8d954c22305c2b
(hashin)

Terrible that the unit tests didn't discover that :(

@peterbe
Copy link
Owner

peterbe commented Dec 13, 2016

Note, in the comment above that the error is that it says Django==None.

@jayfk
Copy link
Contributor Author

jayfk commented Dec 13, 2016

Damn, I'll dig into this.

Copy link
Owner

@peterbe peterbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the version thing.

)
else:
raise PackageError(
"No releases could be found for {0}".format(version, python_versions)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for python_versions here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it was like that before. great. :)

verbose=verbose,
python_versions=python_versions,
algorithm=algorithm
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem here you're missing these lines

@jayfk
Copy link
Contributor Author

jayfk commented Jan 25, 2017

I believe ec4a64f fixes the version thing.

@peterbe
Copy link
Owner

peterbe commented Feb 27, 2017

I am so sorry it has taken me so long to review this. Today is my first day back from a long paternity leave.

So we still have a bug in this branch. This works:

import hashin
print(hashin.get_package_hashes('Django'))

But this does not:

import hashin
print(hashin.get_package_hashes('Django==1.10'))

It should work because this works:

python hashin.py Django==1.10 -r /tmp/reqs.txt

The error you get is:

Traceback (most recent call last):
  File "dummy.py", line 3, in <module>
    print(hashin.get_package_hashes('Django==1.10'))
  File "/Users/peterbe/dev/PYTHON/hashin/hashin.py", line 329, in get_package_hashes
    data = get_package_data(package, verbose)
  File "/Users/peterbe/dev/PYTHON/hashin/hashin.py", line 271, in get_package_data
    content = json.loads(_download(url))
  File "/opt/boxen/homebrew/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/opt/boxen/homebrew/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/boxen/homebrew/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

@peterbe
Copy link
Owner

peterbe commented Feb 27, 2017

The "quick explanation" is that it tries to download: https://pypi.python.org/pypi/Django==1.10/json and that returns a non-json response.

What it should download is https://pypi.python.org/pypi/Django/json and from there fish out the relevant data based on 1.10.

@peterbe
Copy link
Owner

peterbe commented Feb 27, 2017

Oh! I get it.
I'm not supposed to run get_package_hashes('Django==1.10'). I'm supposed to do get_package_hashes('Django', version='1.10').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants