Skip to content

Commit

Permalink
Merge pull request #411 from simontorres/packaging_updates
Browse files Browse the repository at this point in the history
Update packaging to latest standard and to use vcs tags for versioning
  • Loading branch information
simontorres authored Jul 26, 2024
2 parents 288fd4c + a5a686d commit 22324aa
Show file tree
Hide file tree
Showing 25 changed files with 266 additions and 267 deletions.
83 changes: 70 additions & 13 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,53 @@ on:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest
tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
include:

- name: Python 3.12 with Coverage
os: ubuntu-latest
python: '3.12'
toxenv: py312-test-cov

- name: Python 3.12
os: ubuntu-latest
python: '3.12'
toxenv: py312-test

- name: Python 3.10
os: ubuntu-latest
python: '3.10'
toxenv: py310-test

- name: Python 3.9
os: ubuntu-latest
python: 3.9
toxenv: py39-test

- name: Python 3.8
os: ubuntu-latest
python: 3.8
toxenv: py38-test

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest-cov wheel
python -m pip install --upgrade tox
pip install flake8 pytest-cov wheel tox
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Compile DCR Binaries
run: |
Expand All @@ -40,13 +70,40 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
- run: |
pwd
ls -la goodman_pipeline
- name: Run Tests
run: |
pytest --cov=goodman_pipeline
tox ${{ matrix.toxargs }} -e ${{ matrix.toxenv }} -- ${{ matrix.toxposargs }}
- name: Upload coverage to artifacts
if: ${{ contains(matrix.toxenv,'-cov') }}
uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.toxenv }}.xml
path: coverage.xml
if-no-files-found: error

- uses: codecov/codecov-action@v4
upload-coverage-report:
needs: ['tests']
permissions:
contents: none
runs-on: ubuntu-latest
name: Upload Coverage
steps:
- name: Download coverage artifacts
uses: actions/download-artifact@v4
with:
path: coverage
pattern: coverage_*
merge-multiple: true
- name: Upload to Codecov
if: ${{ hashFiles('coverage/') != ''}}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
token: ${{ secrets.CODECOV_TOKEN }}
directory: coverage
fail_ci_if_error: true # optional (default = false)
verbose: true


4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ goodman_pipeline/data/dcr_source/*.o
.eggs/*
.tmp/*
.tox/*
goodman_pipeline.egg-info/*
*/goodman_pipeline.egg-info/*
goodman_pipeline/version.py
coverage.xml
*.DS_Store
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
from importlib.metadata import version


# -- General configuration ------------------------------------------------
Expand All @@ -31,7 +32,7 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.

__version__ = __import__('goodman_pipeline').__version__
__version__ = version('goodman_pipeline')

extensions = ['sphinx.ext.todo',
'sphinx.ext.coverage',
Expand Down
6 changes: 4 additions & 2 deletions goodman_pipeline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import absolute_import

from .version import __version__
from importlib.metadata import version

from . import spectroscopy
from . import images
from . import core

from .core import setup_logging
from .core import setup_logging

__version__ = version('goodman_pipeline')
16 changes: 8 additions & 8 deletions goodman_pipeline/core/check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
import requests
import os

from distutils.version import LooseVersion
from packaging.version import Version

logger = logging.getLogger(__name__)

API_URL = 'https://api.github.com/repos/soar-telescope/goodman/releases/latest'


def get_last(github_api_token='GITHUB_ACCESS_TOKEN'):
def get_last(github_api_token: str = 'GITHUB_ACCESS_TOKEN') -> Version:
"""
Returns the version of the last release on GitHub.
Parameters
----------
github_api_token (str, optional) : Name of the environment variable
holding the github access token for the API
holding the github access token for the API
Returns
-------
version (LooseVersion) : the last version of the pipeline.
version (object) : A :class:`pkg_resources.extern.packaging.version.Version` the last version of the pipeline.
"""
try:
access_token = os.environ[github_api_token]
Expand All @@ -39,14 +39,14 @@ def get_last(github_api_token='GITHUB_ACCESS_TOKEN'):
raise ConnectionRefusedError('Number of tests reached maximum for now.')

tag_name = response.json()['tag_name'].replace('v', '')
_version = LooseVersion(tag_name)
_version = Version(tag_name)

return _version.vstring
return _version


def am_i_updated(version):
def am_i_updated(version: str) -> bool:

version = LooseVersion(version.replace('v', ''))
version = Version(version)
last_version = get_last()

return last_version <= version
5 changes: 3 additions & 2 deletions goodman_pipeline/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
from astropy.stats import sigma_clip
from astropy.time import Time
from astroscrappy import detect_cosmics
from importlib.metadata import version
from matplotlib import pyplot as plt
from scipy import signal, interpolate
from threading import Timer

from . import check_version

__version__ = __import__('goodman_pipeline').__version__
__version__ = version('goodman_pipeline')

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -3266,7 +3267,7 @@ def trace_targets(ccd, target_list, sampling_step=5, pol_deg=2, nfwhm=5,
return all_traces


def validate_ccd_region(ccd_region, regexp='^\[\d*:\d*,\d*:\d*\]$'):
def validate_ccd_region(ccd_region, regexp=r'^\[\d*:\d*,\d*:\d*\]$'):
compiled_reg_exp = re.compile(regexp)
if not compiled_reg_exp.match(ccd_region):
raise SyntaxError("ccd regions must be defined in the format "
Expand Down
11 changes: 6 additions & 5 deletions goodman_pipeline/core/tests/test_check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@

import os
import unittest

import requests

from goodman_pipeline.core import check_version
from importlib.metadata import version

from ..core import check_version

__version__ = __import__('goodman_pipeline').__version__
__version__ = version('goodman_pipeline')


class TestVersionChecker(unittest.TestCase):

def test_get_last(self):
try:
v = check_version.get_last()
self.assertRegex(v, '^(\*|\d+(\.\d+){0,2}(\.\*)?)$')
self.assertRegex(v.base_version, '^(\*|\d+(\.\d+){0,2}(\.\*)?)$')
# self.assertEqual(v, __version__)
except ConnectionRefusedError: # pragma: no cover
pass
Expand All @@ -26,7 +27,7 @@ def test_get_last(self):
def test_get_last_no_token(self):
try:
v = check_version.get_last(github_api_token='NONEXISTANTVAR')
self.assertRegex(v, '^(\*|\d+(\.\d+){0,2}(\.\*)?)$')
self.assertRegex(v.base_version, '^(\*|\d+(\.\d+){0,2}(\.\*)?)$')
# self.assertEqual(v, __version__)
except ConnectionRefusedError: # pragma: no cover
pass
Expand Down
14 changes: 7 additions & 7 deletions goodman_pipeline/core/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ class ClassifySpectroscopicData(TestCase):

def setUp(self):
self.path = os.path.join(
os.getcwd(),
'goodman_pipeline/data/test_data/test_classify_spectroscopic');
os.path.dirname(__file__),
'../../data/test_data/test_classify_spectroscopic');
if not os.path.isdir(self.path):
os.mkdir(self.path)

Expand Down Expand Up @@ -1366,7 +1366,7 @@ def setUp(self):
# expected master flat to be retrieved by get_best_flat
self.reference_flat_name = 'master_flat_1200m2_0.84_dome.fits'
# location of sample flats
self.flat_path = 'goodman_pipeline/data/test_data/master_flat'
self.flat_path = os.path.join(os.path.dirname(__file__), '../../data/test_data/master_flat')
slit = re.sub('[A-Za-z" ]',
'',
self.master_flat.header['SLIT'])
Expand Down Expand Up @@ -1761,8 +1761,8 @@ class ReferenceDataTest(TestCase):

def setUp(self):
self.rd = ReferenceData(
reference_dir=os.path.join(os.getcwd(),
'goodman_pipeline/data/ref_comp'))
reference_dir=os.path.join(os.path.dirname(__file__),
'../../data/ref_comp'))
self.ccd = CCDData(data=np.ones((800, 2000)),
meta=fits.Header(),
unit='adu')
Expand Down Expand Up @@ -2037,8 +2037,8 @@ def setUp(self):
'FALSE']], columns=columns)]

self.reference_data = ReferenceData(
reference_dir=os.path.join(os.getcwd(),
'goodman_pipeline/data/ref_comp'))
reference_dir=os.path.join(os.path.dirname(__file__),
'../../data/ref_comp'))

def test_search_comp_group(self):
result = search_comp_group(
Expand Down
4 changes: 0 additions & 4 deletions goodman_pipeline/images/data_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,3 @@ def _get_obs_technique(self):
# inform the results, no need to return
self.log.info('Detected {:s} Data from {:s} '
'Camera'.format(self.technique, self.instrument))


if __name__ == '__main__':
pass
11 changes: 7 additions & 4 deletions goodman_pipeline/images/goodman_ccd.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from .data_classifier import DataClassifier
from .night_organizer import NightOrganizer
from .image_processor import ImageProcessor

import os
import sys
Expand All @@ -13,14 +10,20 @@
import logging
import matplotlib

from importlib.metadata import version

from .data_classifier import DataClassifier
from .night_organizer import NightOrganizer
from .image_processor import ImageProcessor

log = logging.getLogger(__name__)

try:
matplotlib.use('Qt5Agg')
except ImportError as error:
log.warning(error)

__version__ = __import__('goodman_pipeline').__version__
__version__ = version('goodman_pipeline')


def get_args(arguments=None):
Expand Down
4 changes: 0 additions & 4 deletions goodman_pipeline/images/image_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,3 @@ def process_imaging_science(self, imaging_group):
log.info('Created science file: {:s}'.format(final_name))
else:
log.error('Can not process data without a master flat')


if __name__ == '__main__':
pass
4 changes: 2 additions & 2 deletions goodman_pipeline/images/tests/test_data_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class DataClassifierTests(TestCase):

def setUp(self):
self.raw_path = os.path.join(
os.getcwd(),
'goodman_pipeline/data/test_data/classify-data')
os.path.dirname(__file__),
'../../data/test_data/classify-data')

if not os.path.isdir(self.raw_path):
os.mkdir(self.raw_path)
Expand Down
4 changes: 2 additions & 2 deletions goodman_pipeline/images/tests/test_night_organizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class NightOrganizerTest(TestCase):

def setUp(self):
self.full_path = os.path.join(
os.getcwd(),
'goodman_pipeline/data/test_data/night-organizer-test')
os.path.dirname(__file__),
'../../data/test_data/night-organizer-test')

if not os.path.isdir(self.full_path):
os.mkdir(self.full_path)
Expand Down
2 changes: 1 addition & 1 deletion goodman_pipeline/scripts/redccd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ if '-h' not in sys.argv and \
'--version' not in sys.argv:
setup_logging()

if __name__ == '__main__':
if __name__ == '__main__': # pragma: no cover
GOODMAN_CCD = MainApp()
GOODMAN_CCD()
2 changes: 1 addition & 1 deletion goodman_pipeline/scripts/redspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ if '-h' not in sys.argv and \
setup_logging()


if __name__ == '__main__':
if __name__ == '__main__': # pragma: no cover
GOODMAN_SPECTROSCOPY = MainApp()
GOODMAN_SPECTROSCOPY()
Loading

0 comments on commit 22324aa

Please sign in to comment.