Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github action for coveralls, readme badges, metadata refactor #246

Merged
merged 24 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/coveralls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: coveralls

on:
push:
branches: [ $default-branch ]
pull_request:

jobs:
coveralls_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install --only-binary=numpy,scipy -r requirements-dev.txt
- name: Install package
run: |
pip install -e .
- name: Test with pytest
run: |
pytest
- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
parallel: true
flag-name: Unit Test

coveralls_finish:
needs: coveralls_test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
debug: true
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This workflow will install dependencies, install becquerel and run tests.
# It runs on multiple python3 versions on macOS and Ubuntu.
# It runs on multiple python3 versions on macOS, Ubuntu and Windows.
# It runs when a commit (merge) is push to the main (default) branch or for updates to a PR targeting main.
# Based on: https://github.com/actions/starter-workflows/blob/main/ci/python-package.yml

name: Python package
name: tests

on:

Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
pip install -r requirements-dev.txt
- name: Install package
run: |
pip install -e .
pip install .
- name: Test with pytest
run: |
python -c 'import becquerel;'
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,3 @@ $RECYCLE.BIN/

# Becquerel settings
__df_cache_*.csv
__metadata__.py
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# becquerel

[![tests](https://github.com/lbl-anp/becquerel/actions/workflows/tests.yaml/badge.svg)](https://github.com/lbl-anp/becquerel/actions/workflows/tests.yaml)
[![Coverage Status](https://coveralls.io/repos/github/lbl-anp/becquerel/badge.svg?branch=main)](https://coveralls.io/github/lbl-anp/becquerel?branch=main)

Becquerel is a Python package for analyzing nuclear spectroscopic
measurements. The core functionalities are reading and writing different
spectrum file types, fitting spectral features, performing detector
Expand Down
82 changes: 46 additions & 36 deletions becquerel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,78 @@
"""Becquerel: Tools for radiation spectral analysis."""

from . import core
from . import parsers
from . import tools
from .__metadata__ import __description__, __url__
from .__metadata__ import __version__, __license__, __copyright__
from .__metadata__ import (
__description__,
__url__,
__version__,
__license__,
__copyright__,
)

from .core.rebin import rebin, RebinError, RebinWarning
from .core.spectrum import Spectrum, SpectrumError, UncalibratedError
from .core.spectrum import SpectrumWarning
from . import core
from .core import utils, fitting
from .core.autocal import AutoCalibrator, AutoCalibratorError
from .core.energycal import LinearEnergyCal, EnergyCalError, BadInput
from .core.utils import UncertaintiesError
from .core.plotting import SpectrumPlotter, PlottingError
from .core.fitting import Fitter
from .core.peakfinder import (
PeakFilter,
PeakFilterError,
GaussianPeakFilter,
PeakFinder,
PeakFinderError,
)
from .core.autocal import AutoCalibrator, AutoCalibratorError
from .core.plotting import SpectrumPlotter, PlottingError
from .core.rebin import rebin, RebinError, RebinWarning
from .core.spectrum import Spectrum, SpectrumError, UncalibratedError, SpectrumWarning
from .core.utils import UncertaintiesError

from .core import utils
from .core import fitting
from .core.fitting import Fitter
from . import parsers

from .tools import nndc
from . import tools
from .tools import nndc, xcom, materials
from .tools.element import Element
from .tools.isotope import Isotope
from .tools.isotope_qty import IsotopeQuantity
from .tools import xcom
from .tools import materials

import warnings

warnings.simplefilter("default", DeprecationWarning)

__all__ = [
"__description__",
"__url__",
"__version__",
"__license__",
"__copyright__",
"core",
"parsers",
"tools",
"rebin",
"RebinError",
"RebinWarning",
"Spectrum",
"SpectrumError",
"SpectrumWarning",
"SpectrumPlotter",
"PlottingError",
"UncalibratedError",
"utils",
"fitting",
"AutoCalibrator",
"AutoCalibratorError",
"LinearEnergyCal",
"EnergyCalError",
"BadInput",
"UncertaintiesError",
"Fitter",
"PeakFilter",
"PeakFilterError",
"GaussianPeakFilter",
"PeakFinder",
"PeakFinderError",
"AutoCalibrator",
"AutoCalibratorError",
"__description__",
"__url__",
"__version__",
"__license__",
"__copyright__",
"SpectrumPlotter",
"PlottingError",
"rebin",
"RebinError",
"RebinWarning",
"Spectrum",
"SpectrumError",
"UncalibratedError",
"SpectrumWarning",
"UncertaintiesError",
"parsers",
"tools",
"nndc",
"xcom",
"materials",
"Element",
"Isotope",
"IsotopeQuantity",
]
40 changes: 40 additions & 0 deletions becquerel/__metadata__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""becquerel package metadata."""

__name__ = "becquerel"
__author__ = "The Becquerel Development Team"
__maintainer__ = __author__
__email__ = "becquerel-dev@lbl.gov"
__description__ = "Tools for radiation spectral analysis."
__url__ = "https://github.com/lbl-anp/becquerel"
__version__ = "0.3.0"
# classifiers from list at https://pypi.org/classifiers/
__classifiers__ = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: Other/Proprietary License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
]
__license__ = "Other/Proprietary License (see LICENSE.txt)"
__copyright__ = """\
Becquerel v. 0.3.0, Copyright (c) 2017, The Regents of the University of
California (UC), through Lawrence Berkeley National Laboratory, and the UC
Berkeley campus (subject to receipt of any required approvals from the U.S.
Dept. of Energy). All rights reserved. If you have questions about your rights
to use or distribute this software, please contact Berkeley Lab's Innovation &
Partnerships Office at IPO@lbl.gov.

NOTICE. This Software was developed under funding from the U.S. Department of
Energy and the U.S. Government consequently retains certain rights. As such,
the U.S. Government has been granted for itself and others acting on its
behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software
to reproduce, distribute copies to the public, prepare derivative works, and
perform publicly and display publicly, and to permit other to do so.
"""
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r requirements.txt
coverage
flake8
black>=20.8b1
pydocstyle
Expand Down
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[aliases]
test=pytest
test = pytest

[tool:pytest]
addopts = --black --cov=becquerel --cov-report term --cov-report html:htmlcov -m "not plottest"
Expand All @@ -10,3 +10,6 @@ filterwarnings =
always
; Not fixing the problem: https://github.com/pytest-dev/pytest/pull/3613
ignore:.*t resolve package from __spec__ or __package__.*:ImportWarning

[coverage:run]
relative_files = True
81 changes: 25 additions & 56 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,54 @@
import sys
import site
from setuptools import setup, find_packages
import importlib.util

# Enables --editable install with --user
# https://github.com/pypa/pip/issues/7953
site.ENABLE_USER_SITE = "--user" in sys.argv[1:]

NAME = "becquerel"

MAJOR = 0
MINOR = 3
MICRO = 0
VERSION = f"{MAJOR}.{MINOR}.{MICRO}"

DESCRIPTION = __doc__.split("\n")[0].split(": ")[-1]
URL = "https://github.com/lbl-anp/becquerel"
MAINTAINER = "The Becquerel Development Team"
EMAIL = "becquerel-dev@lbl.gov"
_spec = importlib.util.spec_from_file_location(
"__metadata__", "./becquerel/__metadata__.py"
)
METADATA = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(METADATA)

# classifiers from list at https://pypi.org/classifiers/
CLASSIFIERS = """\
Development Status :: 3 - Alpha
Intended Audience :: Science/Research
License :: Other/Proprietary License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Physics
"""
# Enables --editable install with --user
# https://github.com/pypa/pip/issues/7953
site.ENABLE_USER_SITE = "--user" in sys.argv[1:]

with open("README.md", "r") as fh:
README = fh.read()
# remove package title from description
README = "\n".join(README.split("\n")[2:])
with open("README.md", "r") as fh:
README = "\n".join(fh.readlines()[2:])

with open("CONTRIBUTING.md", "r") as fh:
CONTRIBUTING = fh.read()

with open("LICENSE.txt", "r") as fh:
LICENSE = fh.read()

with open("requirements.txt", "r") as fh:
REQUIREMENTS = fh.read()
REQUIREMENTS = [_line for _line in fh.readlines() if _line]

# make long description from README and CONTRIBUTING
# but move copyright notice to the end
LONG_DESCRIPTION, COPYRIGHT = README.split("## Copyright Notice")
LONG_DESCRIPTION += "\n" + CONTRIBUTING
LONG_DESCRIPTION += "\n" + "## Copyright Notice" + COPYRIGHT

# write metadata to a file that will be imported by becquerel
with open("becquerel/__metadata__.py", "w") as f:
print('"""Becquerel package metadata."""', file=f)
print("", file=f)
print(f'__description__ = "{DESCRIPTION}"', file=f)
print(f'__url__ = "{URL}"', file=f)
print(f'__version__ = "{VERSION}"', file=f)
print(f'__license__ = """{LICENSE}"""', file=f)
print(f'__copyright__ = """{COPYRIGHT}"""', file=f)
LONG_DESCRIPTION = "{0}\n{2}\n## Copyright Notice\n{1}".format(
*README.split("## Copyright Notice"), CONTRIBUTING
markbandstra marked this conversation as resolved.
Show resolved Hide resolved
)

setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
name=METADATA.__name__,
version=METADATA.__version__,
description=METADATA.__description__,
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
url=URL,
download_url=URL + "/releases",
maintainer=MAINTAINER,
maintainer_email=EMAIL,
classifiers=[_f for _f in CLASSIFIERS.split("\n") if _f],
url=METADATA.__url__,
download_url=f"{METADATA.__url__}/releases",
maintainer=METADATA.__maintainer__,
maintainer_email=METADATA.__email__,
classifiers=METADATA.__classifiers__,
platforms="any",
packages=find_packages(),
python_requires=">=3.6",
install_requires=[_f for _f in REQUIREMENTS.split("\n") if _f],
install_requires=REQUIREMENTS,
setup_requires=["pytest-runner"],
tests_require=["pytest", "pytest-cov"],
license="Other/Proprietary License (see LICENSE.txt)",
license=METADATA.__license__,
)
13 changes: 5 additions & 8 deletions tests/autocal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@


# read in spectra
filename1 = os.path.join(os.path.dirname(bq.__file__), "../tests/samples/sim_spec.csv")
filename2 = os.path.join(
os.path.dirname(bq.__file__), "../tests/samples/Mendocino_07-10-13_Acq-10-10-13.Spe"
)
filename3 = os.path.join(
os.path.dirname(bq.__file__), "../tests/samples/nai_detector.csv"
)
filename4 = os.path.join(os.path.dirname(bq.__file__), "../tests/samples/SGM102432.csv")
SAMPLES_PATH = os.path.join(os.path.dirname(__file__), "samples")
filename1 = os.path.join(SAMPLES_PATH, "sim_spec.csv")
filename2 = os.path.join(SAMPLES_PATH, "Mendocino_07-10-13_Acq-10-10-13.Spe")
filename3 = os.path.join(SAMPLES_PATH, "nai_detector.csv")
filename4 = os.path.join(SAMPLES_PATH, "SGM102432.csv")

counts = []
with open(filename1, "r") as f:
Expand Down