Skip to content

Commit 95a5264

Browse files
committed
using generig setup boilerplate
1 parent 0b256f4 commit 95a5264

File tree

8 files changed

+505
-163
lines changed

8 files changed

+505
-163
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
dist: trusty
21
sudo: false
32
language: python
43
os:
54
- linux
6-
# - osx
75
python:
86
- "3.6"
97
- "3.6-dev"
@@ -46,10 +44,10 @@ install:
4644

4745
script:
4846
- TEST_PACKAGING=1 TEST_DEPENDENCIES=1 python -m coverage run --branch --source . -m unittest discover --verbose
49-
- python -m coverage report --show-missing
50-
- coveralls
5147

5248
after_success:
49+
- python -m coverage report --show-missing
50+
- coveralls
5351
- python -m pylint --load-plugins=pylint.extensions.mccabe --docstring-min-length 5 --no-docstring-rgx "^(test)?_|.*Tests$" --unsafe-load-any-extension y --output-format colorized --reports y $(find . -name "*.py")
5452

5553
notifications:

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
include setup_boilerplate.py
2+
include requirements.txt
3+
include test_requirements.txt
4+
include dev_requirements.txt
15
include LICENSE
26
include NOTICE
37
recursive-include test/examples *.*

dev_requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
coveralls
21
coverage
2+
coveralls
33
pip >= 9.0
44
pylint
55
setuptools >= 20.5
66
twine
77
typed_ast
88
typed_astunparse
9-
-rrequirements.txt
9+
-rtest_requirements.txt

setup.py

Lines changed: 5 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
11
"""Build script for open_fortran_parser package."""
22

3-
import importlib
4-
import pathlib
5-
import shutil
6-
import sys
7-
import typing as t
3+
import setup_boilerplate
84

9-
import setuptools
105

11-
_SRC_DIR = '.'
12-
"""Directory with source code, relative to the setup.py file location."""
6+
class Package(setup_boilerplate.Package):
137

8+
"""Package metadata."""
149

15-
def setup() -> None:
16-
"""Run setuptools.setup() with correct arguments.
17-
18-
List of valid project classifiers: https://pypi.python.org/pypi?:action=list_classifiers
19-
20-
The extras_require is a dictionary which might have the following key-value pairs:
21-
'some_feature': ['requirement1', 'requirement2'],
22-
23-
The entry_points is a dictionary which might have the following key-value pair:
24-
'console_scripts': ['script_name = package.subpackage:function']
25-
"""
2610
name = 'open-fortran-parser'
27-
version = find_version(name.replace('-', '_'))
2811
description = 'Python wrapper for XML output generator for Open Fortran Parser'
29-
url = 'https://mbdevpl.github.io/'
3012
download_url = 'https://github.com/mbdevpl/open-fortran-parser-xml'
31-
author = 'Mateusz Bysiek'
32-
author_email = 'mb@mbdev.pl'
33-
license_str = 'Apache License 2.0'
3413
classifiers = [
3514
'Development Status :: 1 - Planning',
3615
'Environment :: Console',
@@ -43,115 +22,9 @@ def setup() -> None:
4322
'Programming Language :: Python :: 3 :: Only',
4423
'Topic :: Education',
4524
'Topic :: Scientific/Engineering',
46-
'Topic :: Utilities'
47-
]
25+
'Topic :: Utilities']
4826
keywords = ['abstract syntax tree', 'ast', 'parser', 'xml']
49-
package_data = {}
50-
exclude_package_data = {}
51-
extras_require = {}
52-
entry_points = {}
53-
test_suite = 'test'
54-
55-
setuptools.setup(
56-
name=name, version=version, description=description,
57-
long_description=parse_readme(), url=url, download_url=download_url,
58-
author=author, author_email=author_email,
59-
maintainer=author, maintainer_email=author_email,
60-
license=license_str, classifiers=classifiers, keywords=keywords,
61-
packages=find_packages(), package_dir={'': _SRC_DIR}, include_package_data=True,
62-
package_data=package_data, exclude_package_data=exclude_package_data,
63-
install_requires=parse_requirements(), extras_require=extras_require,
64-
python_requires=find_required_python_version(classifiers),
65-
entry_points=entry_points, test_suite=test_suite)
66-
67-
68-
# below code is generic boilerplate and normally should not be changed
69-
# last update: 2017-06-01
70-
71-
_HERE = pathlib.Path(__file__).resolve().parent
72-
73-
74-
def clean(build_directory_name: str = 'build') -> None:
75-
"""Recursively delete build directory (by default "build") if it exists."""
76-
build_directory_path = _HERE.joinpath(build_directory_name)
77-
if build_directory_path.is_dir():
78-
shutil.rmtree(str(build_directory_path))
79-
80-
81-
def find_version(
82-
package_name: str, version_module_name: str = '_version',
83-
version_variable_name: str = 'VERSION') -> str:
84-
"""Simulate behaviour of "from package_name._version import VERSION", and return VERSION."""
85-
version_module = importlib.import_module('{}.{}'.format(package_name, version_module_name))
86-
return getattr(version_module, version_variable_name)
87-
88-
89-
def find_packages() -> t.List[str]:
90-
"""Find packages to pack."""
91-
exclude = ['test', 'test.*'] if 'bdist_wheel' in sys.argv else []
92-
packages_list = setuptools.find_packages(_SRC_DIR, exclude=exclude)
93-
return packages_list
94-
95-
96-
def parse_readme(readme_path: str = 'README.rst', encoding: str = 'utf-8') -> str:
97-
"""Read contents of readme file (by default "README.rst") and return them."""
98-
with open(_HERE.joinpath(readme_path), encoding=encoding) as readme_file:
99-
desc = readme_file.read()
100-
return desc
101-
102-
103-
def parse_requirements(
104-
requirements_path: str = 'requirements.txt') -> t.List[str]:
105-
"""Read contents of requirements.txt file and return data from its relevant lines.
106-
107-
Only non-empty and non-comment lines are relevant.
108-
"""
109-
requirements = []
110-
with open(_HERE.joinpath(requirements_path)) as reqs_file:
111-
for requirement in [line.strip() for line in reqs_file.read().splitlines()]:
112-
if not requirement or requirement.startswith('#'):
113-
continue
114-
requirements.append(requirement)
115-
return requirements
116-
117-
118-
def find_required_python_version(
119-
classifiers: t.Sequence[str], ver_prefix: str = 'Programming Language :: Python :: ',
120-
only_suffix: str = ' :: Only') -> str:
121-
"""Determine the minimum required Python version."""
122-
versions = [ver.replace(ver_prefix, '') for ver in classifiers if ver.startswith(ver_prefix)]
123-
versions_min = [ver for ver in versions if not ver.endswith(only_suffix)]
124-
versions_only = [ver.replace(only_suffix, '') for ver in versions if ver.endswith(only_suffix)]
125-
versions_min = [tuple([int(_) for _ in ver.split('.')]) for ver in versions_min]
126-
versions_only = [tuple([int(_) for _ in ver.split('.')]) for ver in versions_only]
127-
if len(versions_only) > 1:
128-
raise ValueError(
129-
'more than one "{}" version encountered in {}'.format(only_suffix, versions_only))
130-
only_version = None
131-
if len(versions_only) == 1:
132-
only_version = versions_only[0]
133-
for version in versions_min:
134-
if version[:len(only_version)] != only_version:
135-
raise ValueError(
136-
'the "{}" version {} is inconsistent with version {}'
137-
.format(only_suffix, only_version, version))
138-
min_supported_version = None
139-
for version in versions_min:
140-
if min_supported_version is None or \
141-
(len(version) >= len(min_supported_version) and version < min_supported_version):
142-
min_supported_version = version
143-
if min_supported_version is None:
144-
if only_version is not None:
145-
return '.'.join([str(_) for _ in only_version])
146-
else:
147-
return '>=' + '.'.join([str(_) for _ in min_supported_version])
148-
return None
149-
150-
151-
def main() -> None:
152-
clean()
153-
setup()
15427

15528

15629
if __name__ == '__main__':
157-
main()
30+
Package.setup()

0 commit comments

Comments
 (0)