Newer
Older
#!python
# coding=utf-8
"""Setup for testing, building, distributing and installing the 'Pyramid'-package"""
import os
import re
import subprocess
import sys
from setuptools import setup, find_packages
DISTNAME = 'pyramid'
DESCRIPTION = 'PYthon based Reconstruction Algorithm for MagnetIc Distributions'
MAINTAINER = 'Jan Caron'
MAINTAINER_EMAIL = 'j.caron@fz-juelich.de'
URL = ''
VERSION = '0.1.0.dev0' # TODO: Better way?
PYTHON_VERSION = (2, 7) # TODO: get rid of!!!
DEPENDENCIES = {'numpy': (1, 10)} # TODO: get rid of!!!
LONG_DESCRIPTION = 'long description (TODO!)' # TODO: Long description! put in (Readme?) file!
# TODO: get rid of superfluous functions!
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def get_package_version(package):
"""Return the package version of the specified package.
Parameters
----------
package: basestring
Name of the package whic should be checked.
Returns
-------
version: tuple (N=3)
Version number as a tuple.
"""
version = []
for version_attr in ('version', 'VERSION', '__version__'):
if (hasattr(package, version_attr) and
isinstance(getattr(package, version_attr), str)):
version_info = getattr(package, version_attr, '')
for part in re.split('\D+', version_info):
try:
version.append(int(part))
except ValueError:
pass
return tuple(version)
def check_requirements():
"""Checks the requirements of the Pyramid package."""
if sys.version_info < PYTHON_VERSION:
raise SystemExit('You need Python version %d.%d or later.'
% PYTHON_VERSION)
for package_name, min_version in DEPENDENCIES.items():
dep_error = False
try:
package = __import__(package_name)
except ImportError:
dep_error = True
else:
package_version = get_package_version(package)
if min_version > package_version:
dep_error = True
if dep_error:
raise ImportError('You need `%s` version %d.%d or later.'
% ((package_name,) + min_version))
def hg_version(): # TODO: Replace with GIT! Also check build output on GitLab! See numpy setup.py!
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""Get the Mercurial reference identifier.
Returns
-------
hg_ref: basestring
The Mercurial reference identifier.
"""
try:
hg_rev = subprocess.check_output(['hg', 'id', '--id']).strip()
except:
hg_rev = "???"
return hg_rev
def write_version_py(filename='pyramid/version.py'):
"""Write the version.py file.
Parameters
----------
filename: basestring, optional
Write the version and hg_revision into the specified python file.
Defaults to 'pyramid/version.py'.
"""
version_string = '# -*- coding: utf-8 -*-\n' + \
'""""This file is generated automatically by the Pyramid `setup.py`"""\n' + \
'version = "{}"\n'.format(VERSION) + \
'hg_revision = "{}"\n'.format(hg_version())
with open(os.path.join(os.path.dirname(__file__), filename), 'w') as vfile:
vfile.write(version_string)
def get_files(rootdir):
"""Returns a list of .py-files inside rootdir.
Parameters
----------
rootdir: basestring
Root directory in which to search for ``.py``-files.
Returns
-------
filepaths: list
List of filepaths which were found.
"""
filepaths = []
for root, dirs, files in os.walk(rootdir):
for filename in files:
if filename.endswith('.py'):
filepaths.append(os.path.join(root, filename))
return filepaths
# TODO: Use requirements.txt? extras_require for optional stuff (hyperspy, plotting)?
# TODO: After split of Pyramid, comment out and see what really is used (is e.g. scipy?)!
install_requires = ['numpy>=1.6', 'tqdm', 'scipy', 'matplotlib', 'Pillow', 'h5py',
'hyperspy', 'jutil', 'cmocean']
# TODO: extend extras_require for plotting and IO:
# TODO: extra: 'pyfftw', 'mayavi' (not easy to install... find a way!)
# TODO: See https://stackoverflow.com/a/28842733 for extras_require...
# TODO: ...replace [dev] with [IO] (hyperspy) and [plotting] (separate plotting library)!
extras_require = {
# TODO: Test all if really needed! don't use nose, if possible (pure pytest)!
'tests': ['pytest', 'pytest-runner', 'pytest-cov', 'pytest-flake8', 'coverage'],
'3Dplot': ['qt==4.8', 'mayavi==4.5']
# TODO: more for mayavi (plotting in general) and hyperspy, etc (see below)...
}
extras_require["all"] = list(itertools.chain(*list(extras_require.values())))
print('\n-------------------------------------------------------------------------------')
print('checking requirements')
check_requirements()
print('write version.py')
write_version_py()
setup(name=DISTNAME,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
url=URL,
download_url=URL,
version=VERSION,
packages=find_packages(exclude=['tests', 'doc']), # TODO: necessary?
#include_dirs=[numpy.get_include()], # TODO: Maybe used for sphinx?!
#setup_requires=['numpy>=1.6', 'pytest', 'pytest-runner'],
#tests_require=['pytest', 'pytest-cov', 'pytest-flake8'],
install_requires=install_requires,
cmdclass={'build': build} # TODO: necessary?
)
print('-------------------------------------------------------------------------------\n')