From 65896c6d7617a127a2e52a2f4993d2f0f22f3de8 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Wed, 6 Mar 2019 12:38:48 -0500 Subject: [PATCH 1/8] Add cheta link and install cheta package to setup.py --- cheta | 1 + setup.py | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) create mode 120000 cheta diff --git a/cheta b/cheta new file mode 120000 index 00000000..662dd235 --- /dev/null +++ b/cheta @@ -0,0 +1 @@ +Ska/engarchive \ No newline at end of file diff --git a/setup.py b/setup.py index 4eba7250..35bf3d57 100755 --- a/setup.py +++ b/setup.py @@ -20,14 +20,15 @@ description='Modules supporting Ska engineering telemetry archive', author_email='aldcroft@head.cfa.harvard.edu', entry_points={'console_scripts': ['ska_fetch = Ska.engarchive.get_telem:main']}, - py_modules=['Ska.engarchive.fetch', 'Ska.engarchive.converters', 'Ska.engarchive.utils', - 'Ska.engarchive.get_telem'], version=package_version.version, zip_safe=False, - packages=['Ska', 'Ska.engarchive', 'Ska.engarchive.derived', 'Ska.engarchive.tests'], - package_dir={'Ska': 'Ska'}, + packages=['Ska', 'Ska.engarchive', 'Ska.engarchive.derived', 'Ska.engarchive.tests', + 'cheta', 'cheta.derived', 'cheta.tests'], package_data={'Ska.engarchive': ['*.dat', 'units_*.pkl', 'GIT_VERSION'], - 'Ska.engarchive.tests': ['*.dat']}, + 'Ska.engarchive.tests': ['*.dat'], + 'cheta': ['*.dat', 'units_*.pkl', 'GIT_VERSION'], + 'cheta.tests': ['*.dat']}, + tests_require=['pytest'], cmdclass=cmdclass, ) From a1d234fabfcc1fb384f82c4489d2247ab928996e Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Wed, 10 Jul 2019 21:21:35 -0400 Subject: [PATCH 2/8] Make setup.py work on Windows --- setup.py | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/setup.py b/setup.py index 35bf3d57..57f0e3e3 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,7 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst +import shutil import sys +import os from setuptools import setup from setuptools.command.test import test as TestCommand @@ -14,21 +16,35 @@ # (same directory as version.py) package_version.write_git_version_file() +# On Windows the `cheta` soft link can turn into a plain file, so work +# around this by temporarily moving that file to the side and doing a +# full tree copy of Ska/engarchive => cheta. +replace_cheta = sys.platform.startswith('win') and os.path.isfile('cheta') -setup(name='Ska.engarchive', - author='Tom Aldcroft', - description='Modules supporting Ska engineering telemetry archive', - author_email='aldcroft@head.cfa.harvard.edu', - entry_points={'console_scripts': ['ska_fetch = Ska.engarchive.get_telem:main']}, - version=package_version.version, - zip_safe=False, - packages=['Ska', 'Ska.engarchive', 'Ska.engarchive.derived', 'Ska.engarchive.tests', - 'cheta', 'cheta.derived', 'cheta.tests'], - package_data={'Ska.engarchive': ['*.dat', 'units_*.pkl', 'GIT_VERSION'], - 'Ska.engarchive.tests': ['*.dat'], - 'cheta': ['*.dat', 'units_*.pkl', 'GIT_VERSION'], - 'cheta.tests': ['*.dat']}, - - tests_require=['pytest'], - cmdclass=cmdclass, - ) +try: + if replace_cheta: + os.rename('cheta', 'cheta-TEMPORARY') + shutil.copytree(os.path.join('Ska', 'engarchive'), 'cheta') + + setup(name='Ska.engarchive', + author='Tom Aldcroft', + description='Modules supporting Ska engineering telemetry archive', + author_email='aldcroft@head.cfa.harvard.edu', + entry_points={'console_scripts': ['ska_fetch = Ska.engarchive.get_telem:main']}, + version=package_version.version, + zip_safe=False, + packages=['Ska', 'Ska.engarchive', 'Ska.engarchive.derived', 'Ska.engarchive.tests', + 'cheta', 'cheta.derived', 'cheta.tests'], + package_data={'Ska.engarchive': ['*.dat', 'units_*.pkl', 'GIT_VERSION'], + 'Ska.engarchive.tests': ['*.dat'], + 'cheta': ['*.dat', 'units_*.pkl', 'GIT_VERSION'], + 'cheta.tests': ['*.dat']}, + + tests_require=['pytest'], + cmdclass=cmdclass, + ) + +finally: + if replace_cheta: + shutil.rmtree('cheta') + os.rename('cheta-TEMPORARY', 'cheta') From c6a6f3e77f0c69ddb524ecff28805f3e52ba2f9a Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Wed, 10 Jul 2019 21:33:06 -0400 Subject: [PATCH 3/8] Remove unused import --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 57f0e3e3..509e25fc 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ import sys import os from setuptools import setup -from setuptools.command.test import test as TestCommand from Ska.engarchive.version import package_version From 542cb338ebf66741e7b684541e9abdd22a8ac9cc Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Wed, 6 Mar 2019 12:38:48 -0500 Subject: [PATCH 4/8] Use setuptools_scm for version --- Ska/engarchive/__init__.py | 25 ++++++- Ska/engarchive/version.py | 150 ------------------------------------- setup.py | 13 +--- 3 files changed, 28 insertions(+), 160 deletions(-) delete mode 100644 Ska/engarchive/version.py diff --git a/Ska/engarchive/__init__.py b/Ska/engarchive/__init__.py index 7552f476..3b52fa94 100644 --- a/Ska/engarchive/__init__.py +++ b/Ska/engarchive/__init__.py @@ -1,5 +1,28 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst -from .version import __version__, __git_version__ + +from pkg_resources import get_distribution, DistributionNotFound + +try: + _dist = get_distribution('Ska.engarchive') # hard-code only for this dual-name package + __version__ = _dist.version + assert __file__.startswith(_dist.location) + +except (AssertionError, DistributionNotFound): + try: + # get_distribution found a different package from this file, must be in source repo + from setuptools_scm import get_version + from pathlib import Path + + root = Path('..') + try: + __version__ = get_version(root=root, relative_to=__file__) + except LookupError: + __version__ = get_version(root=root / '..', relative_to=__file__) + + except Exception: + import warnings + warnings.warn('Failed to find a package version, setting to 0.0.0') + __version__ = '0.0.0' def test(*args, **kwargs): diff --git a/Ska/engarchive/version.py b/Ska/engarchive/version.py deleted file mode 100644 index 644c250f..00000000 --- a/Ska/engarchive/version.py +++ /dev/null @@ -1,150 +0,0 @@ -# Licensed under a 3-clause BSD style license - see LICENSE.rst -""" -Version numbering for Ska.engarchive. - -This file is intended to be copied into a project and provide version information, -including git version values. It is copied instead of used as a module to ensure -that projects can always run their setup.py with no external dependency. - -The `major`, `minor`, and `bugfix` variables hold the respective parts -of the version number. Basic usage is to copy this file into your package directory -alongside __init__.py. Then use as follows:: - - from package.version import version_object - from package.version import __version__ # version_object.version - -In addition to ``major``, ``minor``, ``bugfix``, and ``dev`` attributes, the object -``version_object`` has a number of useful attributes:: - - version Including git info if dev=True 0.5 or 0.5dev-r21-123acf1 - git_version Always including git info 0.5dev-r21-123acf1 - semantic_version Never including git info 0.5dev - git_sha Git 7-digit SHA tag 123acf1 - git_revs Git revision count 21 - -See ``setup.py`` in the ``versioning`` package for an example of what needs to -be done there. The key step is ``version_object.write_git_version_file()`` -in order to create a package file ``git_version.py`` alongside ``version.py`` -which retains the git information outside of the git repo. -""" - -import os - -############################ -### SET THESE VALUES -############################ -# Major, Minor, Bugfix, Dev -VERSION = (4, 44, 2, False) - -class SemanticVersion(object): - def __init__(self, major=0, minor=None, bugfix=None, dev=False): - """ - Semantic version object with support for git revisions - - :param major: Major version - :param minor: Minor version - :param bugfix: Bugfix version - :param dev: True if this is a development version - :param version_filename: File name for package version.py - """ - self.major = major - self.minor = minor - self.bugfix = bugfix - self.dev = dev - self.version_dir = os.path.abspath(os.path.dirname(__file__)) - - def _get_git_info(self): - """ - Determines the number of revisions in this repository and returns "" if - this is not possible. - """ - try: - # First try getting git version from self.version_dir/GIT_VERSION - git_version_filename = os.path.join(self.version_dir, 'GIT_VERSION') - with open(git_version_filename, 'r') as fh: - git_revs, git_sha = fh.read().strip().split() - git_revs = int(git_revs) - - except: - try: - from subprocess import Popen, PIPE - p = Popen(['git', 'rev-list', 'HEAD'], cwd=self.version_dir, - stdout=PIPE, stderr=PIPE, stdin=PIPE) - stdout, stderr = p.communicate() - - if p.returncode == 0: - revs = stdout.split('\n') - git_revs, git_sha = len(revs), revs[0][:7] - else: - git_revs, git_sha = None, None - except: - git_revs, git_sha = None, None - - return git_revs, git_sha - - @property - def git_revs(self): - if not hasattr(self, '_git_revs'): - self._git_revs, self._git_sha = self._get_git_info() - return self._git_revs - - @property - def git_sha(self): - if not hasattr(self, '_git_sha'): - self._git_revs, self._git_sha = self._get_git_info() - return self._git_sha - - @property - def semantic_version(self): - _version = '{}'.format(self.major) - if self.minor is not None: - _version += '.{}'.format(self.minor) - if self.bugfix is not None: - _version += '.{}'.format(self.bugfix) - if self.dev: - _version += 'dev' - return _version - - @property - def git_version(self): - """ - Get the full version with git hashtag and release, e.g. - 0.5dev-r190-423abc1 - """ - if not hasattr(self, '_git_version'): - self._git_version = self.semantic_version - if self.git_revs and self.git_sha: - self._git_version += '-r{0}-{1}'.format(self.git_revs, self.git_sha) - - return self._git_version - - @property - def version(self): - return self.git_version if self.dev else self.semantic_version - - def write_git_version_file(self): - """ - Make the full version with git hashtag and release from GIT_VERSION, - typically during `python setup.py sdist` - """ - git_version_filename = os.path.join(self.version_dir, 'GIT_VERSION') - - # Remove any existing GIT_VERSION file - if os.path.exists(git_version_filename): - os.unlink(git_version_filename) - - # Remove existing attributes - for attr in ('_git_revs', '_git_sha'): - if hasattr(self, attr): - delattr(self, attr) - - git_revs = self.git_revs - git_sha = self.git_sha - with open(git_version_filename, 'w') as fh: - fh.write('{} {}'.format(git_revs, git_sha)) - - -package_version = SemanticVersion(*VERSION) -__version__ = package_version.version -__git_version__ = package_version.git_version -version = __version__ # For back-compatibility with legacy version.py diff --git a/setup.py b/setup.py index 509e25fc..bac3c550 100755 --- a/setup.py +++ b/setup.py @@ -4,17 +4,11 @@ import os from setuptools import setup -from Ska.engarchive.version import package_version - try: from testr.setup_helper import cmdclass except ImportError: cmdclass = {} -# Write GIT revisions and SHA tag into -# (same directory as version.py) -package_version.write_git_version_file() - # On Windows the `cheta` soft link can turn into a plain file, so work # around this by temporarily moving that file to the side and doing a # full tree copy of Ska/engarchive => cheta. @@ -29,14 +23,15 @@ author='Tom Aldcroft', description='Modules supporting Ska engineering telemetry archive', author_email='aldcroft@head.cfa.harvard.edu', + use_scm_version=True, + setup_requires=['setuptools_scm'], entry_points={'console_scripts': ['ska_fetch = Ska.engarchive.get_telem:main']}, - version=package_version.version, zip_safe=False, packages=['Ska', 'Ska.engarchive', 'Ska.engarchive.derived', 'Ska.engarchive.tests', 'cheta', 'cheta.derived', 'cheta.tests'], - package_data={'Ska.engarchive': ['*.dat', 'units_*.pkl', 'GIT_VERSION'], + package_data={'Ska.engarchive': ['*.dat', 'units_*.pkl'], 'Ska.engarchive.tests': ['*.dat'], - 'cheta': ['*.dat', 'units_*.pkl', 'GIT_VERSION'], + 'cheta': ['*.dat', 'units_*.pkl'], 'cheta.tests': ['*.dat']}, tests_require=['pytest'], From 8efd044383b0391af853cd1e18ee2541165086cd Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Thu, 11 Jul 2019 07:30:16 -0400 Subject: [PATCH 5/8] Change local version imports --- Ska/engarchive/fetch.py | 2 +- Ska/engarchive/fetch_eng.py | 2 +- Ska/engarchive/fetch_sci.py | 2 +- Ska/engarchive/plot.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Ska/engarchive/fetch.py b/Ska/engarchive/fetch.py index 320fff03..5b389fe0 100644 --- a/Ska/engarchive/fetch.py +++ b/Ska/engarchive/fetch.py @@ -27,7 +27,7 @@ from .units import Units from . import cache from . import remote_access -from .version import __version__, __git_version__ +from . import __version__ from Chandra.Time import DateTime diff --git a/Ska/engarchive/fetch_eng.py b/Ska/engarchive/fetch_eng.py index 432e8525..2e9a0a7c 100644 --- a/Ska/engarchive/fetch_eng.py +++ b/Ska/engarchive/fetch_eng.py @@ -1,7 +1,7 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst from .fetch import * from . import fetch -from .version import version as __version__ +from . import __version__ # Module-level units, defaults to CXC units (e.g. Kelvins etc) UNITS = Units('eng') diff --git a/Ska/engarchive/fetch_sci.py b/Ska/engarchive/fetch_sci.py index 1d99ea5e..e5258b49 100644 --- a/Ska/engarchive/fetch_sci.py +++ b/Ska/engarchive/fetch_sci.py @@ -1,7 +1,7 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst from .fetch import * from . import fetch -from .version import version as __version__ +from . import __version__ # Module-level units, defaults to CXC units (e.g. Kelvins etc) UNITS = Units('sci') diff --git a/Ska/engarchive/plot.py b/Ska/engarchive/plot.py index 02d95425..1126992a 100644 --- a/Ska/engarchive/plot.py +++ b/Ska/engarchive/plot.py @@ -8,7 +8,7 @@ from Ska.Matplotlib import plot_cxctime from Chandra.Time import DateTime -from .version import version as __version__ +from . import __version__ MIN_TSTART_UNIX = DateTime('1999:100').unix MAX_TSTOP_UNIX = DateTime().unix + 1e7 From 359dfd2df2f5e2b5c98d88ab062a6c22f03b2412 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Thu, 11 Jul 2019 09:16:30 -0400 Subject: [PATCH 6/8] Fix for windows and file path upper/lower case --- Ska/engarchive/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Ska/engarchive/__init__.py b/Ska/engarchive/__init__.py index 3b52fa94..20310e77 100644 --- a/Ska/engarchive/__init__.py +++ b/Ska/engarchive/__init__.py @@ -5,7 +5,10 @@ try: _dist = get_distribution('Ska.engarchive') # hard-code only for this dual-name package __version__ = _dist.version - assert __file__.startswith(_dist.location) + + # Check if this file is the same as what was found in the distribution. + # Windows does not necessarily respect the case so downcase everything. + assert __file__.lower().startswith(_dist.location.lower()) except (AssertionError, DistributionNotFound): try: From 1b8fbb19651f272a5a83752889a6a3e0a4ecc708 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Thu, 11 Jul 2019 20:22:45 -0400 Subject: [PATCH 7/8] New approach using package_dir directive --- setup.py | 53 ++++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/setup.py b/setup.py index bac3c550..429547da 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,4 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst -import shutil -import sys -import os from setuptools import setup try: @@ -9,36 +6,22 @@ except ImportError: cmdclass = {} -# On Windows the `cheta` soft link can turn into a plain file, so work -# around this by temporarily moving that file to the side and doing a -# full tree copy of Ska/engarchive => cheta. -replace_cheta = sys.platform.startswith('win') and os.path.isfile('cheta') +setup(name='Ska.engarchive', + author='Tom Aldcroft', + description='Modules supporting Ska engineering telemetry archive', + author_email='aldcroft@head.cfa.harvard.edu', + use_scm_version=True, + setup_requires=['setuptools_scm'], + entry_points={'console_scripts': ['ska_fetch = Ska.engarchive.get_telem:main']}, + zip_safe=False, + package_dir={'Ska': 'Ska', 'cheta': 'Ska/engarchive'}, + packages=['Ska', 'Ska.engarchive', 'Ska.engarchive.derived', 'Ska.engarchive.tests', + 'cheta', 'cheta.derived', 'cheta.tests'], + package_data={'Ska.engarchive': ['*.dat', 'units_*.pkl'], + 'Ska.engarchive.tests': ['*.dat'], + 'cheta': ['*.dat', 'units_*.pkl'], + 'cheta.tests': ['*.dat']}, -try: - if replace_cheta: - os.rename('cheta', 'cheta-TEMPORARY') - shutil.copytree(os.path.join('Ska', 'engarchive'), 'cheta') - - setup(name='Ska.engarchive', - author='Tom Aldcroft', - description='Modules supporting Ska engineering telemetry archive', - author_email='aldcroft@head.cfa.harvard.edu', - use_scm_version=True, - setup_requires=['setuptools_scm'], - entry_points={'console_scripts': ['ska_fetch = Ska.engarchive.get_telem:main']}, - zip_safe=False, - packages=['Ska', 'Ska.engarchive', 'Ska.engarchive.derived', 'Ska.engarchive.tests', - 'cheta', 'cheta.derived', 'cheta.tests'], - package_data={'Ska.engarchive': ['*.dat', 'units_*.pkl'], - 'Ska.engarchive.tests': ['*.dat'], - 'cheta': ['*.dat', 'units_*.pkl'], - 'cheta.tests': ['*.dat']}, - - tests_require=['pytest'], - cmdclass=cmdclass, - ) - -finally: - if replace_cheta: - shutil.rmtree('cheta') - os.rename('cheta-TEMPORARY', 'cheta') + tests_require=['pytest'], + cmdclass=cmdclass, + ) From c0a3beeaf6bb535735f714021fbf616e2efd6286 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Wed, 17 Jul 2019 13:06:23 -0400 Subject: [PATCH 8/8] Add setuptools_scm_git_archive usage --- .git_archival.txt | 1 + .gitattributes | 1 + setup.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .git_archival.txt create mode 100644 .gitattributes diff --git a/.git_archival.txt b/.git_archival.txt new file mode 100644 index 00000000..95cb3eea --- /dev/null +++ b/.git_archival.txt @@ -0,0 +1 @@ +ref-names: $Format:%D$ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..00a7b00c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.git_archival.txt export-subst diff --git a/setup.py b/setup.py index 429547da..8caa99e7 100755 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ description='Modules supporting Ska engineering telemetry archive', author_email='aldcroft@head.cfa.harvard.edu', use_scm_version=True, - setup_requires=['setuptools_scm'], + setup_requires=['setuptools_scm', 'setuptools_scm_git_archive'], entry_points={'console_scripts': ['ska_fetch = Ska.engarchive.get_telem:main']}, zip_safe=False, package_dir={'Ska': 'Ska', 'cheta': 'Ska/engarchive'},