Created
September 6, 2015 19:49
-
-
Save paveldedik/f62ae1ff008f23c26d46 to your computer and use it in GitHub Desktop.
Setup.py that determines application version, authors and most notably, versions of applications installed from VCS (e.g. GitHub, Google Code etc.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import re | |
import os | |
from setuptools import setup, find_packages | |
from pip.req import parse_requirements | |
def parse(filename, vcs=None): | |
parsed_req = parse_requirements(filename) | |
reqs = [] | |
for line in parsed_req: | |
name = line.req.unsafe_name | |
reqs.append(str(line.req)) | |
if vcs and name in vcs: | |
version = line.req.specs[0][1] | |
vcs[name] = vcs[name].format(ver=version) | |
return reqs | |
# VCS dependencies included in requirements.txt | |
vcs_requires = { | |
'app1': 'git+ssh://git@github.com/user/app1.git@{ver}#egg=app1-{ver}', | |
'app2': 'git+ssh://git@github.com/user/app2.git@{ver}#egg=app2-{ver}', | |
} | |
# Application directory | |
dirname = os.path.abspath(os.path.dirname(__file__)) | |
# PyPi requirements | |
filename = os.path.join(dirname, 'requirements.txt') | |
install_requires = parse(filename, vcs=vcs_requires) | |
# determine version and the authors | |
code = open('app_name/__init__.py', 'r').read(1000) | |
version = re.search(r'__version__ = \'([^\']*)\'', code).group(1) | |
authors = eval(re.search(r'__authors__ = (\[[^\]\[]*\])', code).group(1)) | |
setup( | |
name='app-name', | |
version=version, | |
author=', '.join(authors), | |
py_modules=['manage'], | |
packages=find_packages(exclude=['tests']), | |
include_package_data=True, | |
install_requires=install_requires, | |
dependency_links=vcs_requires.values(), | |
zip_safe=False, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment