-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new way of recording version & other metadata
- Loading branch information
Showing
1 changed file
with
18 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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__}') |