Skip to content

Instantly share code, notes, and snippets.

@andrewgross
Created July 10, 2013 16:25
Show Gist options
  • Save andrewgross/5967784 to your computer and use it in GitHub Desktop.
Save andrewgross/5967784 to your computer and use it in GitHub Desktop.
import re
import os
from setuptools import setup, find_packages
def parse_requirements():
"""Rudimentary parser for the `requirements.txt` file
We just want to separate regular packages from links to pass them to the
`install_requires` and `dependency_links` params of the `setup()`
function properly.
"""
try:
requirements = \
map(str.strip, local_file('requirements.txt').splitlines())
except IOError:
raise RuntimeError("Couldn't find the `requirements.txt' file :(")
links = []
pkgs = []
for req in requirements:
if not req:
continue
if 'http:' in req or 'https:' in req:
links.append(req)
name, version = re.findall("\#egg=([^\-]+)-(.+$$)", req)[0]
pkgs.append('{0}=={1}'.format(name, version))
else:
pkgs.append(req)
return pkgs, links
local_file = lambda f: \
open(os.path.join(os.path.dirname(__file__), f)).read()
install_requires, dependency_links = parse_requirements()
if __name__ == '__main__':
setup(
name="${package}",
version='0.0.1',
description="${description|nothing}",
long_description=local_file('README.md'),
author='',
author_email='',
url='',
packages=find_packages(exclude=['*tests*']),
install_requires=install_requires,
dependency_links=dependency_links,
classifiers=[
'Programming Language :: Python',
],
zip_safe=False,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment