Skip to content

Commit

Permalink
Use new way of recording version & other metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mhucka committed Oct 19, 2020
1 parent dc40877 commit db182c1
Showing 1 changed file with 18 additions and 44 deletions.
62 changes: 18 additions & 44 deletions eprints2bags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,31 @@
Copyright
---------
Copyright (c) 2019 by the California Institute of Technology. This code is
open-source software released under a 3-clause BSD license. Please see the
Copyright (c) 2019-2020 by the California Institute of Technology. This code
is open-source software released under a 3-clause BSD license. Please see the
file "LICENSE" for more information.
'''

from os import path
import sys
# Package metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# ╭────────────────────── Notice ── Notice ── Notice ─────────────────────╮
# | The following values are automatically updated at every release |
# | by the Makefile. Manual changes to these values will be lost. |
# ╰────────────────────── Notice ── Notice ── Notice ─────────────────────╯

# Set module-level dunder variables like __version__
# .............................................................................
# The following code reads from either ../setup.cfg (if running from a source
# directory) or data/setup.cfg (if running from an application created by
# PyInstaller using our PyInstaller configuration scheme), or the installed
# package metadata (if installed normally). It reads config vars and sets the
# corresponding module-level variables with '__' surrounding their names.

keys = ['version', 'description', 'license', 'url', 'keywords',
'author', 'author_email', 'maintainer', 'maintainer_email']

this_module = sys.modules[__package__]
module_path = this_module.__path__[0]
setup_cfg = path.join(module_path, 'data/setup.cfg')
if not path.exists(setup_cfg):
setup_cfg = path.join(path.dirname(__file__), '..', 'setup.cfg')

if path.exists(setup_cfg):
# If setup.cfg is directly available, use that.
from setuptools.config import read_configuration
conf_dict = read_configuration(setup_cfg)
conf = conf_dict['metadata']
for name in [key for key in keys if key in conf]:
variable_name = '__' + name + '__'
setattr(this_module, variable_name, str(conf[name]))
else:
# If we are not running from the source directory, we read from the
# package metadata file created by setuptools.
import distutils.dist, io, pkg_resources
pkg = pkg_resources.get_distribution(__package__)
metadata = distutils.dist.DistributionMetadata()
metadata.read_pkg_file(io.StringIO(pkg.get_metadata(pkg.PKG_INFO)))
for name in [key for key in keys if hasattr(metadata, key)]:
variable_name = '__' + name + '__'
setattr(this_module, variable_name, getattr(metadata, name))
__version__ = '1.9.2'
__description__ = 'Download EPrints content and save it in BagIt-format bags'
__url__ = 'https://github.com/caltechlibrary/eprints2bags'
__author__ = 'Michael Hucka'
__email__ = '[email protected]'
__license__ = 'BSD 3-clause'


# Miscellaneous utilities.
# .............................................................................

def print_version():
this_module = sys.modules[__package__]
print('{} version {}'.format(this_module.__name__, this_module.__version__))
print('Authors: {}'.format(this_module.__author__))
print('URL: {}'.format(this_module.__url__))
print('License: {}'.format(this_module.__license__))
print(f'{__name__} version {__version__}')
print(f'Authors: {__author__}')
print(f'URL: {__url__}')
print(f'License: {__license__}')

0 comments on commit db182c1

Please sign in to comment.