Skip to content

Commit

Permalink
Merge pull request #71 from StackStorm/clean-setup
Browse files Browse the repository at this point in the history
delete pointless requirements parsing code in dist_utils.py
  • Loading branch information
cognifloyd authored Mar 15, 2023
2 parents 36abbc1 + 5542fd8 commit 4a00791
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

jobs:
build-and-test-python:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
# NOTE: Lifted from https://github.com/StackStorm/st2/blob/master/.github/workflows/ci.yaml#L183
services:
mongo:
Expand Down
53 changes: 0 additions & 53 deletions dist_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,13 @@

from distutils.version import StrictVersion

GET_PIP = 'curl https://bootstrap.pypa.io/get-pip.py | python'

try:
import pip
from pip import __version__ as pip_version
except ImportError as e:
print('Failed to import pip: %s' % (str(e)))
print('')
print('Download pip:\n%s' % (GET_PIP))
sys.exit(1)

try:
# pip < 10.0
from pip.req import parse_requirements
except ImportError:
# pip >= 10.0

try:
from pip._internal.req.req_file import parse_requirements
except ImportError as e:
print('Failed to import parse_requirements from pip: %s' % (str(e)))
print('Using pip: %s' % (str(pip_version)))
sys.exit(1)

__all__ = [
'check_pip_version',
'fetch_requirements',
'apply_vagrant_workaround',
'get_version_string',
'parse_version_string'
]


def check_pip_version(min_version='6.0.0'):
"""
Ensure that a minimum supported version of pip is installed.
"""
if StrictVersion(pip.__version__) < StrictVersion(min_version):
print("Upgrade pip, your version '{0}' "
"is outdated. Minimum required version is '{1}':\n{2}".format(pip.__version__,
min_version,
GET_PIP))
sys.exit(1)


def fetch_requirements(requirements_file_path):
"""
Return a list of requirements and links by parsing the provided requirements file.
"""
links = []
reqs = []
for req in parse_requirements(requirements_file_path, session=False):
# Note: req.url was used before 9.0.0 and req.link is used in all the recent versions
link = getattr(req, 'link', getattr(req, 'url', None))
if link:
links.append(str(link))
reqs.append(str(req.req))
return (reqs, links)


def apply_vagrant_workaround():
"""
Function which detects if the script is being executed inside vagrant and if it is, it deletes
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

from setuptools import setup, find_packages

from dist_utils import fetch_requirements
from dist_utils import parse_version_string

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
REQUIREMENTS_FILE = os.path.join(BASE_DIR, "requirements.txt")
INIT_FILE = os.path.join(BASE_DIR, "st2rbac_backend", "__init__.py")

version = parse_version_string(INIT_FILE)
install_reqs, dep_links = fetch_requirements(REQUIREMENTS_FILE)

setup(
name="st2-rbac-backend",
Expand All @@ -50,8 +48,8 @@
provides=["st2rbac_backend"],
packages=find_packages(),
include_package_data=True,
install_requires=install_reqs,
dependency_links=dep_links,
install_requires=[],
dependency_links=[],
test_suite="tests",
entry_points={
"st2common.rbac.backend": [
Expand Down

0 comments on commit 4a00791

Please sign in to comment.