Skip to content

Commit 0c43a94

Browse files
authored
Merge pull request #16 from StackStorm/bugfix/sync-distutils
Sync dist_utils.py with latest from st2 repo
2 parents f48e704 + da72907 commit 0c43a94

File tree

3 files changed

+102
-42
lines changed

3 files changed

+102
-42
lines changed

dist_utils.py

Lines changed: 96 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# -*- coding: utf-8 -*-
2-
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
3-
# contributor license agreements. See the NOTICE file distributed with
4-
# this work for additional information regarding copyright ownership.
5-
# The ASF licenses this file to You under the Apache License, Version 2.0
6-
# (the "License"); you may not use this file except in compliance with
7-
# the License. You may obtain a copy of the License at
2+
# NOTE: This file is auto-generated - DO NOT EDIT MANUALLY
3+
# Instead copy from https://github.com/StackStorm/st2/blob/master/scripts/dist_utils.py
4+
5+
# Copyright 2019 Extreme Networks, Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
810
#
911
# http://www.apache.org/licenses/LICENSE-2.0
1012
#
@@ -15,37 +17,36 @@
1517
# limitations under the License.
1618

1719
from __future__ import absolute_import
20+
1821
import os
1922
import re
2023
import sys
2124

2225
from distutils.version import StrictVersion
2326

24-
GET_PIP = 'curl https://bootstrap.pypa.io/get-pip.py | python'
25-
26-
try:
27-
import pip
28-
from pip import __version__ as pip_version
29-
except ImportError as e:
30-
print('Failed to import pip: %s' % (str(e)))
31-
print('')
32-
print('Download pip:\n%s' % (GET_PIP))
33-
sys.exit(1)
34-
35-
try:
36-
# pip < 10.0
37-
from pip.req import parse_requirements
38-
except ImportError:
39-
# pip >= 10.0
27+
# NOTE: This script can't rely on any 3rd party dependency so we need to use this code here
28+
#
29+
# TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import
30+
# from pip?
31+
#
32+
# TODO: Dear future developer, if you are back here fixing a bug with how we parse
33+
# requirements files, please look into using the packaging package on PyPI:
34+
# https://packaging.pypa.io/en/latest/requirements/
35+
# and specifying that in the `setup_requires` argument to `setuptools.setup()`
36+
# for subpackages.
37+
# At the very least we can vendorize some of their code instead of reimplementing
38+
# each piece of their code every time our parsing breaks.
39+
PY3 = sys.version_info[0] == 3
40+
41+
if PY3:
42+
text_type = str
43+
else:
44+
text_type = unicode # NOQA
4045

41-
try:
42-
from pip._internal.req.req_file import parse_requirements
43-
except ImportError as e:
44-
print('Failed to import parse_requirements from pip: %s' % (str(e)))
45-
print('Using pip: %s' % (str(pip_version)))
46-
sys.exit(1)
46+
GET_PIP = 'curl https://bootstrap.pypa.io/get-pip.py | python'
4747

4848
__all__ = [
49+
'check_pip_is_installed',
4950
'check_pip_version',
5051
'fetch_requirements',
5152
'apply_vagrant_workaround',
@@ -54,26 +55,85 @@
5455
]
5556

5657

57-
def check_pip_version():
58+
def check_pip_is_installed():
59+
"""
60+
Ensure that pip is installed.
61+
"""
62+
try:
63+
import pip # NOQA
64+
except ImportError as e:
65+
print('Failed to import pip: %s' % (text_type(e)))
66+
print('')
67+
print('Download pip:\n%s' % (GET_PIP))
68+
sys.exit(1)
69+
70+
return True
71+
72+
73+
def check_pip_version(min_version='6.0.0'):
5874
"""
5975
Ensure that a minimum supported version of pip is installed.
6076
"""
61-
if StrictVersion(pip.__version__) < StrictVersion('6.0.0'):
62-
print("Upgrade pip, your version `{0}' "
63-
"is outdated:\n{1}".format(pip.__version__, GET_PIP))
77+
check_pip_is_installed()
78+
79+
import pip
80+
81+
if StrictVersion(pip.__version__) < StrictVersion(min_version):
82+
print("Upgrade pip, your version '{0}' "
83+
"is outdated. Minimum required version is '{1}':\n{2}".format(pip.__version__,
84+
min_version,
85+
GET_PIP))
6486
sys.exit(1)
6587

88+
return True
89+
6690

6791
def fetch_requirements(requirements_file_path):
6892
"""
6993
Return a list of requirements and links by parsing the provided requirements file.
7094
"""
7195
links = []
7296
reqs = []
73-
for req in parse_requirements(requirements_file_path, session=False):
74-
if req.link:
75-
links.append(str(req.link))
76-
reqs.append(str(req.req))
97+
98+
def _get_link(line):
99+
vcs_prefixes = ['git+', 'svn+', 'hg+', 'bzr+']
100+
101+
for vcs_prefix in vcs_prefixes:
102+
if line.startswith(vcs_prefix) or line.startswith('-e %s' % (vcs_prefix)):
103+
req_name = re.findall('.*#egg=(.+)([&|@]).*$', line)
104+
105+
if not req_name:
106+
req_name = re.findall('.*#egg=(.+?)$', line)
107+
else:
108+
req_name = req_name[0]
109+
110+
if not req_name:
111+
raise ValueError('Line "%s" is missing "#egg=<package name>"' % (line))
112+
113+
link = line.replace('-e ', '').strip()
114+
return link, req_name[0]
115+
116+
return None, None
117+
118+
with open(requirements_file_path, 'r') as fp:
119+
for line in fp.readlines():
120+
line = line.strip()
121+
122+
if line.startswith('#') or not line:
123+
continue
124+
125+
link, req_name = _get_link(line=line)
126+
127+
if link:
128+
links.append(link)
129+
else:
130+
req_name = line
131+
132+
if ';' in req_name:
133+
req_name = req_name.split(';')[0].strip()
134+
135+
reqs.append(req_name)
136+
77137
return (reqs, links)
78138

79139

st2auth_pam_backend/pam_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def authenticate(self, username, password):
6666
LOG.info('Invalid username/password for user "%s".', username)
6767

6868
return ret
69-
except:
69+
except Exception:
7070
LOG.exception('Unable to PAM authenticate user "%s".', username)
7171
raise
7272

test-requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
unittest2
2-
mock
3-
pep8>=1.6.0,<1.7
4-
flake8>=2.3.0,<2.4
5-
pylint>=1.4.3,<1.5
1+
mock==3.0.5
62
nose>=1.3.7
3+
pep8==1.7.1
4+
pylint==1.9.4
5+
st2flake8==0.1.0
6+
unittest2

0 commit comments

Comments
 (0)