|
1 |
| -"""Setup script for modoboa-admin.""" |
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
2 | 3 |
|
3 |
| -import re |
4 |
| -import os |
5 |
| -from setuptools import setup, find_packages |
6 |
| - |
7 |
| -from modoboa_webmail import __version__ |
| 4 | +""" |
| 5 | +A setuptools based setup module. |
8 | 6 |
|
9 |
| -ROOT = os.path.dirname(__file__) |
| 7 | +See: |
| 8 | +https://packaging.python.org/en/latest/distributing.html |
| 9 | +""" |
10 | 10 |
|
| 11 | +from __future__ import unicode_literals |
11 | 12 |
|
12 |
| -PIP_REQUIRES = os.path.join(ROOT, "requirements.txt") |
| 13 | +import io |
| 14 | +from os import path |
| 15 | +from pip.req import parse_requirements |
| 16 | +from setuptools import setup, find_packages |
13 | 17 |
|
14 | 18 |
|
15 |
| -def parse_requirements(*filenames): |
16 |
| - """ |
17 |
| - We generate our install_requires from the pip-requires and test-requires |
18 |
| - files so that we don't have to maintain the dependency definitions in |
19 |
| - two places. |
20 |
| - """ |
| 19 | +def get_requirements(requirements_file): |
| 20 | + """Use pip to parse requirements file.""" |
21 | 21 | requirements = []
|
22 |
| - for f in filenames: |
23 |
| - for line in open(f, 'r').read().split('\n'): |
24 |
| - # Comment lines. Skip. |
25 |
| - if re.match(r'(\s*#)|(\s*$)', line): |
26 |
| - continue |
27 |
| - # Editable matches. Put the egg name into our reqs list. |
28 |
| - if re.match(r'\s*-e\s+', line): |
29 |
| - pkg = re.sub(r'\s*-e\s+.*#egg=(.*)$', r'\1', line) |
30 |
| - requirements.append("%s" % pkg) |
31 |
| - # File-based installs not supported/needed. Skip. |
32 |
| - elif re.match(r'\s*-f\s+', line): |
33 |
| - pass |
34 |
| - else: |
35 |
| - requirements.append(line) |
| 22 | + if path.isfile(requirements_file): |
| 23 | + for req in parse_requirements(requirements_file, session="hack"): |
| 24 | + # check markers, such as |
| 25 | + # |
| 26 | + # rope_py3k ; python_version >= '3.0' |
| 27 | + # |
| 28 | + if req.match_markers(): |
| 29 | + requirements.append(str(req.req)) |
36 | 30 | return requirements
|
37 | 31 |
|
38 | 32 |
|
39 |
| -def parse_dependency_links(*filenames): |
40 |
| - """ |
41 |
| - We generate our dependency_links from the pip-requires and test-requires |
42 |
| - files for the dependencies pulled from github (prepended with -e). |
43 |
| - """ |
44 |
| - dependency_links = [] |
45 |
| - for f in filenames: |
46 |
| - for line in open(f, 'r').read().split('\n'): |
47 |
| - if re.match(r'\s*-[ef]\s+', line): |
48 |
| - line = re.sub(r'\s*-[ef]\s+', '', line) |
49 |
| - line = re.sub(r'\s*git\+https', 'http', line) |
50 |
| - line = re.sub(r'\.git#', '/tarball/master#', line) |
51 |
| - dependency_links.append(line) |
52 |
| - return dependency_links |
53 |
| - |
54 |
| - |
55 |
| -def read(fname): |
56 |
| - """A simple function to read the content of a file.""" |
57 |
| - return open(os.path.join(ROOT, fname)).read() |
| 33 | +if __name__ == "__main__": |
| 34 | + HERE = path.abspath(path.dirname(__file__)) |
| 35 | + INSTALL_REQUIRES = get_requirements(path.join(HERE, "requirements.txt")) |
58 | 36 |
|
| 37 | + with io.open(path.join(HERE, "README.rst"), encoding="utf-8") as readme: |
| 38 | + LONG_DESCRIPTION = readme.read() |
59 | 39 |
|
60 |
| -setup( |
61 |
| - name="modoboa-webmail", |
62 |
| - version=__version__, |
63 |
| - url='http://modoboa.org/', |
64 |
| - license='MIT', |
65 |
| - description="The webmail of Modoboa", |
66 |
| - long_description=read('README.rst'), |
67 |
| - author='Antoine Nguyen', |
68 |
| - |
69 |
| - packages=find_packages(), |
70 |
| - include_package_data=True, |
71 |
| - install_requires=parse_requirements(PIP_REQUIRES), |
72 |
| - dependency_links=parse_dependency_links(PIP_REQUIRES), |
73 |
| - classifiers=['Development Status :: 5 - Production/Stable', |
74 |
| - 'Framework :: Django', |
75 |
| - 'Intended Audience :: System Administrators', |
76 |
| - 'License :: OSI Approved :: MIT License', |
77 |
| - 'Operating System :: OS Independent', |
78 |
| - 'Programming Language :: Python', |
79 |
| - 'Topic :: Internet :: WWW/HTTP'] |
80 |
| -) |
| 40 | + setup( |
| 41 | + name="modoboa-webmail", |
| 42 | + description="The webmail of Modoboa", |
| 43 | + long_description=LONG_DESCRIPTION, |
| 44 | + license="MIT", |
| 45 | + url="http://modoboa.org/", |
| 46 | + author="Antoine Nguyen", |
| 47 | + |
| 48 | + classifiers=[ |
| 49 | + "Development Status :: 5 - Production/Stable", |
| 50 | + "Environment :: Web Environment", |
| 51 | + "Framework :: Django :: 1.11", |
| 52 | + "Intended Audience :: System Administrators", |
| 53 | + "License :: OSI Approved :: MIT License", |
| 54 | + "Operating System :: OS Independent", |
| 55 | + "Programming Language :: Python :: 2", |
| 56 | + "Programming Language :: Python :: 2.7", |
| 57 | + "Programming Language :: Python :: 3", |
| 58 | + "Programming Language :: Python :: 3.4", |
| 59 | + "Programming Language :: Python :: 3.5", |
| 60 | + "Programming Language :: Python :: 3.6", |
| 61 | + "Topic :: Communications :: Email", |
| 62 | + "Topic :: Internet :: WWW/HTTP", |
| 63 | + ], |
| 64 | + keywords="email webmail", |
| 65 | + packages=find_packages(exclude=["docs", "test_project"]), |
| 66 | + include_package_data=True, |
| 67 | + zip_safe=False, |
| 68 | + install_requires=INSTALL_REQUIRES, |
| 69 | + use_scm_version=True, |
| 70 | + setup_requires=["setuptools_scm"], |
| 71 | + ) |
0 commit comments