From 7256e561aaacc87cc0f7763af8dcf3cc7a1ce990 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Wed, 5 Dec 2018 21:58:59 +0700 Subject: [PATCH] setup.py: Parse git+ links in requirements.txt Fixes https://github.com/thanethomson/statik/issues/97 --- requirements.txt | 2 +- setup.py | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index cd51243..56a3655 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,4 +18,4 @@ SQLAlchemy==1.2.12 Unidecode==1.0.22 watchdog==0.9.0 paramiko==2.4.2 -git+https://github.com/kx-chen/netlify_deployer.git +git+https://github.com/kx-chen/netlify_deployer.git#egg=netlify_uploader diff --git a/setup.py b/setup.py index 7831e82..ac6b98a 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,8 @@ import os.path from setuptools import setup +DEPENDENCY_LINKS = [] + def read_file(filename): full_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), filename) @@ -17,6 +19,36 @@ def read_file(filename): return lines +def read_requirements(filename): + """ + Parse a requirements file. + + Accepts vcs+ links, and places the URL into + `DEPENDENCY_LINKS`. + + :return: list of str for each package + """ + data = [] + for line in read_file(filename): + line = line.strip() + if not line or line.startswith('#'): + continue + + if '+' in line[:4]: + repo_link, egg_name = line.split('#egg=') + if not egg_name: + raise ValueError('Unknown requirement: {0}' + .format(line)) + + DEPENDENCY_LINKS.append(line) + + line = egg_name + + data.append(line) + + return data + + def get_version(): pattern = re.compile(r"__version__ = \"(?P[0-9.a-zA-Z-]+)\"") for line in read_file(os.path.join("statik", "__init__.py")): @@ -26,6 +58,8 @@ def get_version(): raise ValueError("Cannot extract version number for Statik") +install_requires = read_requirements('requirements.txt') + setup( name="statik", version=get_version(), @@ -34,7 +68,8 @@ def get_version(): author="Thane Thomson", author_email="connect@thanethomson.com", url="https://getstatik.com", - install_requires=[r.strip() for r in read_file("requirements.txt") if len(r.strip()) > 0], + install_requires=install_requires, + dependency_links=DEPENDENCY_LINKS, entry_points={ 'console_scripts': [ 'statik = statik.cmdline:main',