Skip to content

Commit 6aee886

Browse files
committed
Revert "use pkg_resources to check for distributions (#395)"
This reverts commit 9b185f9.
1 parent 5496c02 commit 6aee886

File tree

6 files changed

+52
-15
lines changed

6 files changed

+52
-15
lines changed

bin/steps/collectstatic

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ MANAGE_FILE=${MANAGE_FILE:-fakepath}
2020
[ -f .heroku/collectstatic_disabled ] && DISABLE_COLLECTSTATIC=1
2121

2222
# Ensure that Django is explicitly specified in requirements.txt
23-
pip-grep -s Django && DJANGO_INSTALLED=1
23+
pip-grep -s requirements.txt django Django && DJANGO_INSTALLED=1
2424

2525

2626
if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALLED" ]; then

bin/steps/cryptography

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
1818
source $BIN_DIR/utils
1919

2020
# If a package using cffi exists within requirements, use vendored libffi.
21-
if (pip-grep -s argon2-cffi bcrypt cffi cryptography PyNaCl pyOpenSSL PyOpenSSL misaka &> /dev/null) then
21+
if (pip-grep -s requirements.txt argon2-cffi bcrypt cffi cryptography django[argon2] Django[argon2] django[bcrypt] Django[bcrypt] PyNaCl pyOpenSSL PyOpenSSL requests[security] misaka &> /dev/null) then
2222

2323
if [ ! -d ".heroku/vendor/lib/libffi-3.1" ]; then
2424
echo "-----> Noticed cffi. Bootstrapping libffi."

bin/steps/gdal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
1818
source $BIN_DIR/utils
1919

2020
# If GDAL exists within requirements, use vendored gdal.
21-
if (pip-grep -s GDAL pygdal &> /dev/null) then
21+
if (pip-grep -s requirements.txt GDAL gdal pygdal &> /dev/null) then
2222

2323
if [ ! -f ".heroku/vendor/bin/gdalserver" ]; then
2424
echo "-----> Noticed GDAL. Bootstrapping gdal."

bin/steps/pylibmc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ source $BIN_DIR/utils
1717

1818

1919
# If pylibmc exists within requirements, use vendored libmemcached.
20-
if (pip-grep -s pylibmc &> /dev/null) then
20+
if (pip-grep -s requirements.txt pylibmc &> /dev/null) then
2121

2222
if [ ! -d ".heroku/vendor/lib/sasl2" ]; then
2323
echo "-----> Noticed pylibmc. Bootstrapping libmemcached."

bin/steps/setuptools

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Syntax sugar.
44
source $BIN_DIR/utils
55

6+
if (pip-grep -s requirements.txt setuptools distribute &> /dev/null) then
7+
68
puts-step "Removing packaging utilities from requirements.txt."
79

810
if [[ -f requirements.txt ]]; then

vendor/pip-pop/pip-grep

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,58 @@
22
# -*- coding: utf-8 -*-
33

44
"""Usage:
5-
pip-grep [-s] <package>...
5+
pip-grep [-s] <reqfile> <package>...
66
77
Options:
88
-h --help Show this screen.
99
"""
10+
import os
1011
from docopt import docopt
11-
from pkg_resources import DistributionNotFound, get_distribution
12+
from pip.req import parse_requirements
13+
from pip.index import PackageFinder
14+
from pip._vendor.requests import session
1215

16+
requests = session()
1317

14-
def has_any_distribution(names, silent=False):
15-
for name in names:
16-
try:
17-
get_distribution(name)
18-
except DistributionNotFound:
19-
continue
2018

19+
class Requirements(object):
20+
def __init__(self, reqfile=None):
21+
super(Requirements, self).__init__()
22+
self.path = reqfile
23+
self.requirements = []
24+
25+
if reqfile:
26+
self.load(reqfile)
27+
28+
def __repr__(self):
29+
return '<Requirements \'{}\'>'.format(self.path)
30+
31+
def load(self, reqfile):
32+
if not os.path.exists(reqfile):
33+
raise ValueError('The given requirements file does not exist.')
34+
35+
finder = PackageFinder([], [], session=requests)
36+
for requirement in parse_requirements(reqfile, finder=finder, session=requests):
37+
if requirement.req:
38+
if not getattr(requirement.req, 'name', None):
39+
# Prior to pip 8.1.2 the attribute `name` did not exist.
40+
requirement.req.name = requirement.req.project_name
41+
self.requirements.append(requirement.req)
42+
43+
44+
def grep(reqfile, packages, silent=False):
45+
try:
46+
r = Requirements(reqfile)
47+
except ValueError:
2148
if not silent:
22-
print('Package {name} found!'.format(name=name))
49+
print('There was a problem loading the given requirement file.')
50+
exit(os.EX_NOINPUT)
2351

24-
exit(0)
52+
for req in r.requirements:
53+
if req.name in packages:
54+
if not silent:
55+
print('Package {} found!'.format(req.name))
56+
exit(0)
2557

2658
if not silent:
2759
print('Not found.')
@@ -31,7 +63,10 @@ def has_any_distribution(names, silent=False):
3163

3264
def main():
3365
args = docopt(__doc__, version='pip-grep')
34-
has_any_distribution(names=args['<package>'], silent=args['-s'])
66+
67+
kwargs = {'reqfile': args['<reqfile>'], 'packages': args['<package>'], 'silent': args['-s']}
68+
69+
grep(**kwargs)
3570

3671

3772
if __name__ == '__main__':

0 commit comments

Comments
 (0)