From d5e0c3ffdedca6a79926c079600ea9d7c8d240a3 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Sat, 12 May 2018 23:12:10 +0700 Subject: [PATCH] Build setup.py and requirements files using moban coala-mobans provides a set of metadata common to all repositories, with local overrides. Related to https://github.com/coala/meta/issues/117 --- .moban.yaml | 27 ++++++ .travis.yml | 3 + coala_quickstart/VERSION | 1 + coala_quickstart/__init__.py | 13 +++ coala_quickstart/coala_quickstart.py | 3 +- setup.py | 131 ++++++++++++++++++++++++--- 6 files changed, 163 insertions(+), 15 deletions(-) create mode 100644 coala_quickstart/VERSION diff --git a/.moban.yaml b/.moban.yaml index a987ae5..b78a238 100644 --- a/.moban.yaml +++ b/.moban.yaml @@ -1,6 +1,30 @@ overrides: coala.yaml name: coala-quickstart +contact: coala.analyzer@gmail.com +description: A quickstart tool for coala +current_version: 0.4.0 +version: 0.4.0 +build_version: 0.4.0 +package_module: coala_quickstart +url: https://github.com/coala/coala-quickstart +docs_dir: false + +maintainers: false +maintainer_list: + - Satwik Kansal + - Adrian Zatreanu + - Alexandros Dimos + - Adhityaa Chandrasekar +maintainer_emails: + - satwikkansal@gmail.com + - adrianzatreanu1@gmail.com + - alexandros.dimos.95@gmail.com + - c.adhityaa@gmail.com + +entry_points: + console_scripts: + - coala-quickstart = coala_quickstart.coala_quickstart:main dependencies: # TODO: Remove lxml once the upstream issue https://github.com/vfaronov/httpolice/issues/5 with HTTpolice is fixed. @@ -17,5 +41,8 @@ configuration: configuration: .moban.yaml configuration_dir: ../coala-mobans/ targets: + - setup.py: coala-setup.py.jj2 - requirements.txt: requirements.txt.jj2 - test-requirements.txt: test-requirements.txt.jj2 + - coala_quickstart/VERSION: VERSION.jj2 + - coala_quickstart/__init__.py: __init__.py.jj2 diff --git a/.travis.yml b/.travis.yml index a08dd64..baf6edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,9 @@ cache: before_install: - pip install setuptools -U - pip install -r requirements.txt -r test-requirements.txt + - git clone https://gitlab.com/coala/mobans ../coala-mobans + - moban + - git diff --exit-code script: - pytest diff --git a/coala_quickstart/VERSION b/coala_quickstart/VERSION new file mode 100644 index 0000000..1d0ba9e --- /dev/null +++ b/coala_quickstart/VERSION @@ -0,0 +1 @@ +0.4.0 diff --git a/coala_quickstart/__init__.py b/coala_quickstart/__init__.py index e69de29..fdaf317 100644 --- a/coala_quickstart/__init__.py +++ b/coala_quickstart/__init__.py @@ -0,0 +1,13 @@ +from os.path import join, dirname + + +VERSION_FILE = join(dirname(__file__), 'VERSION') + + +def get_version(): + with open(VERSION_FILE, 'r') as ver: + return ver.readline().strip() + + +VERSION = get_version() +__version__ = VERSION diff --git a/coala_quickstart/coala_quickstart.py b/coala_quickstart/coala_quickstart.py index c889b72..bd06428 100644 --- a/coala_quickstart/coala_quickstart.py +++ b/coala_quickstart/coala_quickstart.py @@ -8,6 +8,7 @@ from coala_utils.FilePathCompleter import FilePathCompleter from coala_utils.Question import ask_question +from coala_quickstart import __version__ from coala_quickstart.interaction.Logo import print_welcome_message from coala_quickstart.generation.InfoCollector import collect_info from coala_quickstart.generation.Project import ( @@ -37,7 +38,7 @@ def _get_arg_parser(): ) arg_parser.add_argument( - '-v', '--version', action='version', version='0.4.0') + '-v', '--version', action='version', version=__version__) arg_parser.add_argument( '-C', '--non-interactive', const=True, action='store_const', diff --git a/setup.py b/setup.py index c0fb942..7bf0593 100755 --- a/setup.py +++ b/setup.py @@ -1,25 +1,122 @@ #!/usr/bin/env python3 import locale +import os +import platform +import sys + from setuptools import find_packages, setup +from setuptools.command.test import test as TestCommand try: - locale.getlocale() -except (ValueError, UnicodeError): + lc = locale.getlocale() + pf = platform.system() + if pf != 'Windows' and lc == (None, None): + locale.setlocale(locale.LC_ALL, 'C.UTF-8') +except (ValueError, UnicodeError, locale.Error): locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') -with open('requirements.txt') as requirements: - required = requirements.read().splitlines() +VERSION = '0.4.0' +DEPENDENCY_LINKS = [] + +SETUP_COMMANDS = {} + + +def set_python_path(path): + if 'PYTHONPATH' in os.environ: + user_paths = os.environ['PYTHONPATH'].split(os.pathsep) + user_paths.insert(0, path) + os.environ['PYTHONPATH'] = os.pathsep.join(user_paths) + else: + os.environ['PYTHONPATH'] = path + + +class PyTestCommand(TestCommand): + """ + From https://pytest.org/latest/goodpractices.html + """ + user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.pytest_args = [] + + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + # import here, cause outside the eggs aren't loaded + import pytest + errno = pytest.main(self.pytest_args) + sys.exit(errno) + + +SETUP_COMMANDS['test'] = PyTestCommand + + +__dir__ = os.path.dirname(__file__) + + +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 = [] + filename = os.path.join(__dir__, filename) + with open(filename) as requirements: + required = requirements.read().splitlines() + for line in required: + 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(repo_link) + + line = egg_name.replace('-', '==') + + data.append(line) + + return data + + +required = read_requirements('requirements.txt') + +test_required = read_requirements('test-requirements.txt') + +filename = os.path.join(__dir__, 'README.rst') +with open(filename) as readme: + long_description = readme.read() + +extras_require = None +EXTRAS_REQUIRE = {} +data_files = None -with open('test-requirements.txt') as requirements: - test_required = requirements.read().splitlines() +if extras_require: + EXTRAS_REQUIRE = extras_require +SETUP_COMMANDS.update({ +}) if __name__ == '__main__': setup(name='coala-quickstart', - version='0.4.0', + version=VERSION, description='A quickstart tool for coala', author='The coala developers', - maintainer='Satwik Kansal, Adrian Zatreanu, Alexandros Dimos, ' + author_email='coala.analyzer@gmail.com', + maintainer='Satwik Kansal, ' + 'Adrian Zatreanu, ' + 'Alexandros Dimos, ' 'Adhityaa Chandrasekar', maintainer_email=('satwikkansal@gmail.com, ' 'adrianzatreanu1@gmail.com, ' @@ -27,17 +124,20 @@ 'c.adhityaa@gmail.com'), url='https://github.com/coala/coala-quickstart', platforms='any', - packages=find_packages(exclude=['build.*', '*.tests.*', '*.tests']), + packages=find_packages(exclude=('build.*', 'tests', 'tests.*')), install_requires=required, + extras_require=EXTRAS_REQUIRE, tests_require=test_required, + dependency_links=DEPENDENCY_LINKS, + package_data={'coala_quickstart': ['VERSION']}, license='AGPL-3.0', - long_description='coala-quickstart is a tool to help you ' - 'quickly and easily get started with ' - 'coala.', + data_files=data_files, + long_description=long_description, entry_points={ 'console_scripts': [ 'coala-quickstart = coala_quickstart.coala_quickstart:main', - ]}, + ], + }, # from http://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ 'Development Status :: 4 - Beta', @@ -57,8 +157,11 @@ 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3 :: Only', 'Topic :: Scientific/Engineering :: Information Analysis', 'Topic :: Software Development :: Quality Assurance', - 'Topic :: Text Processing :: Linguistic']) + 'Topic :: Text Processing :: Linguistic'], + cmdclass=SETUP_COMMANDS, + )