Newer
Older
# This is the install file for pymagglobal.
#
# Copyright (C) 2020 Helmholtz Centre Potsdam GFZ,
# German Research Centre for Geosciences, Potsdam, Germany
#
# Cite as:
# TODO
#
# This file is part of pymagglobal.
#
# pymagglobal is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pymagglobal is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pymagglobal. If not, see <https://www.gnu.org/licenses/>.
import os
import codecs
from setuptools import setup
cmdclass = dict()
command_options = dict()
try:
from sphinx.setup_command import BuildDoc
class BuildDocAndFigs(BuildDoc):
def __init__(self, dist):
from pymagglobal.__main__ import mst_ex_cmd, mst_ex_ofn, \
dip_ex_cmd, dip_ex_ofn, map_ex_cmd, map_ex_ofn, \
cfs_ex_cmd, cfs_ex_ofn, cfe_ex_cmd, cfe_ex_ofn, \
argument_parser
self.parser = argument_parser
# generate the figures for the docs
self.fig_from_cmd(cfe_ex_cmd, cfe_ex_ofn)
self.fig_from_cmd(cfs_ex_cmd, cfs_ex_ofn)
self.fig_from_cmd(dip_ex_cmd, dip_ex_ofn)
self.fig_from_cmd(map_ex_cmd, map_ex_ofn)
self.fig_from_cmd(mst_ex_cmd, mst_ex_ofn)
super().__init__(dist)
def fig_from_cmd(self, cmd, fname):
arg = cmd.split()[1:]
arg.insert(1, f'--savefig')
arg.insert(2, f'./docs/{fname}')
arg.insert(3, f'--no-show')
nsp = self.parser().parse_args(arg)
fig = nsp.func(nsp)
fig.savefig(nsp.savefig, dpi=600)
cmdclass['build_sphinx'] = BuildDocAndFigs
# https://packaging.python.org/guides/single-sourcing-package-version/
def read(rel_path):
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, rel_path), 'r') as fp:
return fp.read()
def get_version(rel_path):
for line in read(rel_path).splitlines():
if line.startswith('__version__'):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
else:
raise RuntimeError("Unable to find version string.")
name = 'pymagglobal'
version = get_version('pymagglobal/__init__.py')
description = '''python interface for global geomagnetic field models '''
copyright = f'2020 Helmholtz Centre Potsdam GFZ, ' \
+ f'German Research Centre for Geosciences, Potsdam, Germany'
command_options['build_sphinx'] = {'project': ('setup.py', name),
'release': ('setup.py', version),
'copyright': ('setup.py', copyright),
'source_dir': ('setup.py', 'docs')}
name=name,
version=version,
author='Schanner, M. A. and Mauerberger, S. and Korte, M.',
author_email='arthus@gfz-potsdam.de',
packages=['pymagglobal'],
license='GPL v3',
description=description,
long_description=description,
install_requires=[],
package_data={'pymagglobal': ['dat/*']},
include_package_data=True,
entry_points={'console_scripts': [f'pymagglobal = '
f'pymagglobal.__main__:main']},
cmdclass=cmdclass,
command_options=command_options,