Skip to content

Commit

Permalink
ci: publish and adapt to updates of physical constants in hepunits 2.…
Browse files Browse the repository at this point in the history
…0.0 (#270)

* ci: fix publishing of ZipApp

* style: pre-commit autoupdate

* Fix unbound method bug

* Adapt to hepunits 2.0.0

* Further adapt to hepunits 2.0.0

Co-authored-by: eduardo-rodrigues <eduardo.rodrigues@cern.ch>
  • Loading branch information
henryiii and eduardo-rodrigues authored Oct 5, 2020
1 parent bd36ad4 commit 2066ef4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 91 deletions.
89 changes: 38 additions & 51 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
name: CI

on:
workflow_dispatch:
pull_request:
push:
branches: master
tags:
- 'v*'
branches:
- master
release:
types:
- published


jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- name: set PY
run: echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' ' -f1)"
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/action@v1.0.0
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0

checks:
name: Check 🐍 ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -30,79 +29,74 @@ jobs:
- 2.7
- 3.5
- 3.8
name: Check Python ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v1
- uses: actions/checkout@v1

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install package
run: python -m pip install -e .[test]

- name: Requirements check
- name: Requirements list
run: python -m pip list

- name: Test package
run: python -m pytest

notebooks:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install package
run: python -m pip install -e .[test]

- name: Install notebook requirements
run: python -m pip install nbconvert jupyter_client ipykernel

- name: Run the notebooks inplace
run: jupyter nbconvert --execute --inplace notebooks/*.ipynb



dist:
name: SDist and Wheel
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v1
with:
python-version: 3.8
- uses: actions/checkout@v1

- name: Install wheel and sdist requirements
run: python -m pip install "setuptools>=42.0" "setuptools_scm[toml]>=3.4" "wheel"
- uses: actions/setup-python@v2

- name: Build sdist
run: python setup.py sdist
- name: Install wheel and sdist requirements
run: python -m pip install build

- name: Build wheel
run: >
python -m pip wheel . -w wheels &&
ls -lh wheels &&
mkdir -p dist &&
cp wheels/particle*any.whl dist/
- name: Build SDist and wheel
run: python -m build

- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v2
with:
name: DistPackage
path: dist

- uses: pypa/gh-action-pypi-publish@master
- uses: pypa/gh-action-pypi-publish@v1.4.1
if: github.event_name == 'release' && github.event.action == 'published'
with:
user: __token__
password: ${{ secrets.pypi_password }}
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

zipapp:
name: ZipApp
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1

- uses: actions/setup-python@v2
with:
python-version: 3.7

Expand All @@ -119,24 +113,17 @@ jobs:
run: python -m zipapp -c -p "/usr/bin/env python3" -m "particle.__main__:main" -o ../particle.pyz .
working-directory: src

- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v2
with:
name: ZipApp
path: particle.pyz

- name: "Get upload_url"
run: echo "::set-output name=upload_url::https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH)/assets{?name,label}"
id: release
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
# Tag *must* be made from the GitHub release interface at the moment

- name: Upload Release Asset
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
- name: Upload ZipApp if release
if: github.event_name == 'release' && github.event.action == 'published'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./particle.pyz
asset_name: particle.pyz
asset_content_type: application/zip
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

repos:
- repo: https://github.com/psf/black
rev: 19.10b0
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v3.2.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1000']
Expand All @@ -20,11 +20,11 @@ repos:
- id: end-of-file-fixer
- id: fix-encoding-pragma
- repo: https://github.com/mgedmin/check-manifest
rev: "0.42"
rev: "0.43"
hooks:
- id: check-manifest
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
rev: v0.782
hooks:
- id: mypy
files: src
Expand Down
50 changes: 25 additions & 25 deletions src/particle/converters/bimap.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,31 @@ def __len__(self):

def DirectionalMaps(name_A, name_B, converters=(str, str), filename=None):
"""
Directional map class providing a to and from mapping.
Parameters
----------
name_A, name_B: str
Input names of information to be mapped.
converters: tuple, optional, default=(str,str)
Converter functions applied on each entry (row) of the file
providing the name_a-name_B matches.
The order of the list elements must agree with that of the
object names passed in in the constructor.
By default, data on the file is assumed to be strings,
which is the typical case for particle names.
filename: string or file object, optional, default='particle/data/conversions.csv'.
Specify a file from which to read all name_a-name_B matches.
It is assumed that the order of items in the file matches the order
of arguments specified in the class constructor, hence val_A,val_B.
Examples
--------
>>> from particle import data # doctest: +SKIP
>>> filename = data.open_text(data, 'a_to_b.csv') # doctest: +SKIP
>>> A2BMap, B2AMap = DirectionalMaps('A', 'B', filename=filename) # doctest: +SKIP
"""
Directional map class providing a to and from mapping.
Parameters
----------
name_A, name_B: str
Input names of information to be mapped.
converters: tuple, optional, default=(str,str)
Converter functions applied on each entry (row) of the file
providing the name_a-name_B matches.
The order of the list elements must agree with that of the
object names passed in in the constructor.
By default, data on the file is assumed to be strings,
which is the typical case for particle names.
filename: string or file object, optional, default='particle/data/conversions.csv'.
Specify a file from which to read all name_a-name_B matches.
It is assumed that the order of items in the file matches the order
of arguments specified in the class constructor, hence val_A,val_B.
Examples
--------
>>> from particle import data # doctest: +SKIP
>>> filename = data.open_text(data, 'a_to_b.csv') # doctest: +SKIP
>>> A2BMap, B2AMap = DirectionalMaps('A', 'B', filename=filename) # doctest: +SKIP
"""

name_A = name_A.upper()
name_B = name_B.upper()
Expand Down
16 changes: 8 additions & 8 deletions src/particle/particle/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ def width_to_lifetime(Gamma):
Manipulation with no explicit usage of units:
>>> width_to_lifetime(4.33e-10) # result returned in ns
0.001520119980246514
0.0015201199929582136
Manipulations with explicit units defined in the HEP system of units:
>>> from hepunits.units import MeV, eV, ps # handy module with units in the HEP system of units
>>>
>>> width_to_lifetime(4.33e-10*MeV) # result returned in ns
0.001520119980246514
0.0015201199929582136
>>>
>>> width_to_lifetime(4.33e-4*eV) # result again returned in ns
0.001520119980246514
0.0015201199929582136
>>>
>>> width_to_lifetime(4.33e-10*MeV)/ps # result converted to ps
1.520119980246514
1.5201199929582137
"""

if Gamma < 0.0:
Expand Down Expand Up @@ -81,20 +81,20 @@ def lifetime_to_width(tau):
--------
Manipulation with no explicit usage of units:
>>> lifetime_to_width(0.001520119980246514) # result returned in MeV
>>> lifetime_to_width(0.0015201199929582136) # result returned in MeV
4.33e-10
Manipulations with explicit units defined in the HEP system of units:
>>> from hepunits.units import MeV, eV, ps # handy module with units in the HEP system of units
>>>
>>> lifetime_to_width(0.001520119980246514*ns) # result returned in MeV
>>> lifetime_to_width(0.0015201199929582136*ns) # result returned in MeV
4.33e-10
>>>
>>> lifetime_to_width(1.520119980246514*ps) # result again returned in MeV
>>> lifetime_to_width(1.5201199929582137*ps) # result again returned in MeV
4.33e-10
>>>
>>> lifetime_to_width(1.520119980246514*ps)/eV # result converted to eV
>>> lifetime_to_width(1.5201199929582137*ps)/eV # result converted to eV
0.000433
"""

Expand Down
6 changes: 3 additions & 3 deletions tests/particle/test_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def test_C_consistency():
[4222, "Width = 1.89 + 0.09 - 0.18 MeV"], # Sigma_c(2455)++
[23, u"Width = 2495.2 ± 2.3 MeV"], # H0
# Test print-out of symmetric lifetime errors
[5332, u"Lifetime = 1.65e-03 ± 1.8e-04 ns"], # Omega_b-
[5332, u"Lifetime = 1.65e-03 + 1.8e-04 - 1.8e-04 ns"], # Omega_b-
[211, u"Lifetime = 26.033 ± 0.005 ns"], # pion
# Test print-out of asymmetric lifetime errors
[4332, "Lifetime = 2.7e-04 + 3e-05 - 3e-05 ns"], # Omega_c^0
Expand All @@ -324,8 +324,8 @@ def test_C_consistency():

@pytest.mark.parametrize("pid,description", checklist_describe)
def test_describe(pid, description):
particle = Particle.from_pdgid(pid)
assert description in particle.describe()
part = Particle.from_pdgid(pid)
assert description in part.describe()


def test_default_table_loading():
Expand Down

0 comments on commit 2066ef4

Please sign in to comment.