Skip to content
Snippets Groups Projects
Commit e471a8c9 authored by Jan Caron's avatar Jan Caron
Browse files

Streamlined setup.py,

put most options into setup.cfg
parent a9c22581
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,83 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: Check if everything is taylored to pyramid!
# CONFIGURATION FOR SETUP.PY:
[metadata]
name = pyramid
version = 0.1.0.dev0
author = Jan Caron
author-email = j.caron@fz-juelich.de
description = PYthon based Reconstruction Algorithm for MagnetIc Distributions
long-description = file: README.md
url = https://jugit.fz-juelich.de/j.caron/pyramid
license = GPLv3
classifiers =
Development Status :: 3 - alpha
Intended Audience :: Developers
Intended Audience :: Science/Research
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Programming Language :: Python :: 3.7
Topic :: Scientific/Engineering
Operating System :: OS Independen
[options]
zip_safe = False
include_package_data = True
packages = find:
python_requires = >=3.7
# TODO: Check (Comment out everything and test what's really needed)!
setup_requires =
setuptools
numpy>=1.6
pytest
pytest-runner
# TODO: Check!
tests_require =
coverage
pytest
pytest-cov
pytest-flake8
pytest-runner
# TODO: Check!
install_requires =
numpy>=1.6
tqdm
scipy
matplotlib
Pillow
h5py
hyperspy
cmocean
# jutil # TODO: How to handle this??? Ask Jörn!
[options.extras_require]
# TODO: necessary? Does it work with pip/conda?
3Dplot =
qt==4.8
mayavi==4.5
# TODO: Pillow and such?
io =
hyperspy
fftw =
pyfftw
# TODO: Notebooks and stuff
# demos =
# TODO: Add? How?
# snippets =
# TODO: make this optional? Or silent fallback to matplotlib? stylesheet?
colors =
cmocean
# TODO: Don't use too many!
# TODO: What about jupyter notebooks?
# TODO: Check all submodules if anything should be optional or is missing?
# TODO: in general, make CI test THESE requirements (maybe in addition to the environment.yml)
# TODO: more for mayavi (plotting in general) and hyperspy, etc (see below)...
# TODO: what about demos? see Hyperspy?
# CONFIGURATION FOR TESTING:
[aliases]
test=pytest
......@@ -34,12 +110,16 @@ source = pyramid
omit =
tests/*
[tool:pytest]
addopts = --cov --flake8
[tool:pytest] # TODO: Check if everything is taylored to pyramid!
#addopts = --cov --flake8
flake8-max-line-length = 100
flake8-ignore =
ALL # TODO: PEP8 deactivated by this line (remove at a later point)!
E402 E124 E125
pyramid/__init__.py F401
doc/conf.py ALL
scripts/*.py ALL
#ALL # TODO: PEP8 deactivated by this line (remove at a later point)!
E402 # module import not at top of file
E124 # closing bracket does not match visual indentation
E125 # continuation line with same indent as next logical line
E226 # missing whitespace around arithmetic operator
W503 # line break before binary operator
E741 # do not use variables named ‘l’, ‘O’, or ‘I’
pyramid/__init__.py F401 # module imported but unused
#doc/conf.py ALL
......@@ -3,172 +3,52 @@
"""Setup for testing, building, distributing and installing the 'Pyramid'-package"""
import os
import re
import subprocess
import sys
import itertools
#from distutils.command.build import build
from setuptools import setup
from setuptools.config import read_configuration
#import numpy
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!
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!
"""Get the Mercurial reference identifier.
Returns
-------
hg_ref: basestring
The Mercurial reference identifier.
"""
def git_version():
'''Get current git revision.'''
try:
hg_rev = subprocess.check_output(['hg', 'id', '--id']).strip()
except:
hg_rev = "???"
return hg_rev
git_rev = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip().decode()
except Exception:
git_rev = "???"
return git_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'.
"""
def write_version_py(version, git_version, filename='pyramid/version.py'):
'''Write version.py file.'''
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())
'""""This file was automatically generated by `setup.py`"""\n' + \
f'version = "{version}"\n' + \
f'git_revision = "{git_version}"\n'
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.
# Read setup.cfg (setup() would auto-read it, but we want to read the version and modify it here):
conf_dict = read_configuration('setup.cfg')
metadata_dict = conf_dict['metadata']
options_dict = conf_dict['options']
"""
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
# Read version and write to version.py:
version = metadata_dict['version']
write_version_py(version, git_version())
# Add 'full' convenience option to extras_require for full install: python setup.py install .[full]
full_list = list(itertools.chain(*list(options_dict['extras_require'].values())))
options_dict['extras_require']['full'] = full_list
# TODO: Outsource stuff to setup.cfg? See https://github.com/pypa/setuptools/pull/862
# Run setup:
setup(**metadata_dict, **options_dict) # TODO: Is this overwritten by setup.cfg again?
# 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: not current!
# TODO: in general, make CI test THESE requirements (maybe in addition to the environment.yml)
# TODO: more for mayavi (plotting in general) and hyperspy, etc (see below)...
}
# TODO: Currently does not work, find out why!
extras_require["all"] = list(itertools.chain(*list(extras_require.values())))
# TODO: What about the demo?
# TODO: HOW TO GET JUTIL???
print('\n-------------------------------------------------------------------------------')
# print('checking requirements') # TODO: Get rid of!
# 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,
extras_require=extras_require,
#cmdclass={'build': build} # TODO: necessary?
)
print('-------------------------------------------------------------------------------\n')
# TODO: Also create conda recipe!
# TODO: Handle extras via metapackage (depends on pyramid-base that holds the core code and extras?)
# TODO: https://docs.conda.io/projects/conda-build/en/latest/user-guide/tutorials/build-pkgs.html
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment