Skip to content

Commit

Permalink
fix: allow --hash=... in requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-go committed Feb 1, 2018
1 parent fe19d73 commit 2bfa8b8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plug/requirements/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ def parse_line(cls, line):
# This is a requirement specifier.
# Delegate to pkg_resources and hope for the best
req.specifier = True

# an optional --hash param is not part of the req specifier
line = re.sub('\s*--hash=\S+', '', line)

pkg_req = Req.parse(line)
req.name = pkg_req.unsafe_name
req.extras = list(pkg_req.extras)
Expand Down
52 changes: 52 additions & 0 deletions test/inspect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,58 @@ test('editables ignored', function (t) {
});
});

test('deps withs hashes', function (t) {
chdirWorkspaces('pip-app-deps-with-hashes');

return pipInstall()
.then(function () {
return plugin.inspect('.', 'requirements.txt')
.then(function (result) {
var plugin = result.plugin;
var pkg = result.package;

t.test('plugin', function (t) {
t.ok(plugin, 'plugin');
t.equal(plugin.name, 'snyk-python-plugin', 'name');
t.match(plugin.runtime, 'Python', 'runtime');
t.end();
});

t.test('package', function (t) {
t.ok(pkg, 'package');
t.equal(pkg.name, 'pip-app-deps-with-hashes', 'name');
t.equal(pkg.version, '0.0.0', 'version');
t.same(pkg.from, ['pip-app-deps-with-hashes@0.0.0'], 'from self');
t.end();
});

t.test('package dependencies', function (t) {
t.match(pkg.dependencies.markupsafe, {
name: 'markupsafe',
version: '1.0',
from: [
'pip-app-deps-with-hashes@0.0.0',
'markupsafe@1.0',
],
}, 'MarkupSafe looks ok');

t.match(pkg.dependencies.dnspython, {
name: 'dnspython',
version: '1.13.0',
from: [
'pip-app-deps-with-hashes@0.0.0',
'dnspython@1.13.0',
],
}, 'dnspython looks ok');

t.end();
});

t.end();
});
});
});

test('trusted host ignored', function (t) {
chdirWorkspaces('pip-app-trusted-host');
return pipInstall()
Expand Down
2 changes: 2 additions & 0 deletions test/workspaces/pip-app-deps-with-hashes/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MarkupSafe==1.0 --hash=sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665
dnspython==1.13.0 --hash=sha256:80f89881b402fc3b931a936111b43bcfe3abd8b0005d27e50e3c5fb59f7260f8

0 comments on commit 2bfa8b8

Please sign in to comment.