From 2066ef437e6e52062320a452f7e4f93cc5fb7fe6 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 5 Oct 2020 16:31:26 -0400 Subject: [PATCH] ci: publish and adapt to updates of physical constants in hepunits 2.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 --- .github/workflows/ci.yml | 89 ++++++++++++----------------- .pre-commit-config.yaml | 8 +-- src/particle/converters/bimap.py | 50 ++++++++-------- src/particle/particle/kinematics.py | 16 +++--- tests/particle/test_particle.py | 6 +- 5 files changed, 78 insertions(+), 91 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21a73d8b..09841524 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -30,19 +29,18 @@ 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 @@ -50,59 +48,55 @@ jobs: 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 @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index abf2583f..dedf791e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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'] @@ -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 diff --git a/src/particle/converters/bimap.py b/src/particle/converters/bimap.py index 1b347584..3f9cbb9d 100644 --- a/src/particle/converters/bimap.py +++ b/src/particle/converters/bimap.py @@ -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() diff --git a/src/particle/particle/kinematics.py b/src/particle/particle/kinematics.py index a9a28cb7..720659b1 100644 --- a/src/particle/particle/kinematics.py +++ b/src/particle/particle/kinematics.py @@ -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: @@ -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 """ diff --git a/tests/particle/test_particle.py b/tests/particle/test_particle.py index f2374929..8a855df3 100644 --- a/tests/particle/test_particle.py +++ b/tests/particle/test_particle.py @@ -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 @@ -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():