Skip to content

Commit

Permalink
Allowing 3.11 python version (#107)
Browse files Browse the repository at this point in the history
* Adding Python 3.10 and 3.11 to package and actions

Add env system for uv installation

* Moved out coveralls testing to its own action

* Updated publishing adding python versions 3.10 and 3.11

* Fix pytest action

* Updated readme

* Fixed errors

Using plural for properties under Outputs

* Fix ruff
  • Loading branch information
JosePizarro3 authored Aug 15, 2024
1 parent bd2f695 commit 4527342
Show file tree
Hide file tree
Showing 27 changed files with 139 additions and 371 deletions.
52 changes: 27 additions & 25 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: install-and-test
name: Installing and Testing
on: [push]

# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
Expand All @@ -9,55 +9,57 @@ permissions:
checks: write
pull-requests: write

env:
UV_SYSTEM_PYTHON: true

jobs:
install-and-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python_version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
- name: Set up Python ${{matrix.python_version}}
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: ${{matrix.python_version}}
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: |
pip install --upgrade pip
pip install uv
uv pip install -e '.[dev]' --index-url https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple --system
uv pip install coveralls --system
uv pip install -e '.[dev]'
- name: mypy
run: |
python -m mypy --ignore-missing-imports --follow-imports=silent --no-strict-optional src/nomad_simulations/schema_packages tests
- name: Build coverage file
- name: Test with pytest
run: |
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=src tests | tee pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: pytest-coverage.txt
junitxml-path: pytest.xml
- name: Submit to coveralls
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
coveralls --service=github
python -m pytest -sv tests
build-and-install:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python_version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
- name: Set up Python ${{matrix.python_version}}
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: ${{matrix.python_version}}
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Build the package
run: |
pip install uv
uv pip install --upgrade pip --system
uv pip install build --system
uv pip install build
python -m build --sdist
- name: Install the package
run: |
uv pip install dist/*.tar.gz --index-url https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple --system
uv pip install dist/*.tar.gz
ruff-linting:
runs-on: ubuntu-latest
steps:
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Testing with coveralls Report
on: [push]

# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
# `contents` is for permission to the contents of the repository.
# `pull-requests` is for permission to pull request
permissions:
contents: write
checks: write
pull-requests: write

env:
UV_SYSTEM_PYTHON: true

jobs:
coveralls-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: |
uv pip install -e '.[dev]'
uv pip install coveralls
- name: Build coverage file
run: |
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=src tests | tee pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: pytest-coverage.txt
junitxml-path: pytest.xml
- name: Submit to coveralls
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
coveralls --service=github
26 changes: 15 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,31 @@ on:
permissions:
contents: read

env:
UV_SYSTEM_PYTHON: true

jobs:
deploy:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python_version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v3
- uses: actions/checkout@v4
- name: Set up Python ${{matrix.python_version}}
uses: actions/setup-python@v5
with:
python-version: '3.9'

python-version: ${{matrix.python_version}}
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: |
pip install --upgrade pip
pip install build
uv pip install build
- name: Build package
run: python -m build

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pip install nomad-simulations --index-url https://gitlab.mpcdf.mpg.de/api/v4/pro

## Development

If you want to develop locally this package, clone the project and in the workspace folder, create a virtual environment (note this project uses Python 3.9):
If you want to develop locally this package, clone the project and in the workspace folder, create a virtual environment (you can use Python 3.9, 3.10, or 3.11):
```sh
git clone https://github.com/nomad-coe/nomad-simulations.git
cd nomad-simulations
python3.9 -m venv .pyenv
python3.11 -m venv .pyenv
. .pyenv/bin/activate
```

Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ classifiers = [
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: Apache Software License",
]
name = "nomad-simulations"
Expand Down Expand Up @@ -46,6 +48,9 @@ dev = [
"structlog",
]

[tool.uv]
index-url = "https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple"

[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
Expand Down
10 changes: 5 additions & 5 deletions src/nomad_simulations/schema_packages/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ class Outputs(ArchiveSection):

xas_spectra = SubSection(sub_section=XASSpectrum.m_def, repeats=True)

total_energy = SubSection(sub_section=TotalEnergy.m_def, repeats=True)
total_energies = SubSection(sub_section=TotalEnergy.m_def, repeats=True)

kinetic_energy = SubSection(sub_section=KineticEnergy.m_def, repeats=True)
kinetic_energies = SubSection(sub_section=KineticEnergy.m_def, repeats=True)

potential_energy = SubSection(sub_section=PotentialEnergy.m_def, repeats=True)
potential_energies = SubSection(sub_section=PotentialEnergy.m_def, repeats=True)

total_force = SubSection(sub_section=TotalForce.m_def, repeats=True)
total_forces = SubSection(sub_section=TotalForce.m_def, repeats=True)

temperature = SubSection(sub_section=Temperature.m_def, repeats=True)
temperatures = SubSection(sub_section=Temperature.m_def, repeats=True)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down
12 changes: 12 additions & 0 deletions src/nomad_simulations/schema_packages/properties/energies.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ class KineticEnergy(BaseEnergy):
Physical property section describing the kinetic energy of a (sub)system.
"""

def __init__(
self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs
) -> None:
super().__init__(m_def, m_context, **kwargs)
self.name = self.m_def.name

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

Expand All @@ -136,5 +142,11 @@ class PotentialEnergy(BaseEnergy):
Physical property section describing the potential energy of a (sub)system.
"""

def __init__(
self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs
) -> None:
super().__init__(m_def, m_context, **kwargs)
self.name = self.m_def.name

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)
5 changes: 3 additions & 2 deletions src/nomad_simulations/schema_packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ def multiplicity(self):

@property
def degeneracy(self):
return factorial(self.multiplicity) / (
factorial(self.multiplicity - self.occupation) * factorial(self.occupation)
return factorial(int(self.multiplicity)) / (
factorial(int(self.multiplicity - self.occupation))
* factorial(self.occupation)
)


Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import pytest
from nomad.datamodel import EntryArchive
from nomad.units import ureg

from nomad_simulations.schema_packages.atoms_state import AtomsState, OrbitalsState
from nomad_simulations.schema_packages.general import Simulation
from nomad_simulations.schema_packages.model_method import ModelMethod
Expand Down
1 change: 1 addition & 0 deletions tests/test_atoms_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pytest
from nomad.datamodel import EntryArchive
from nomad.units import ureg

from nomad_simulations.schema_packages.atoms_state import (
AtomsState,
CoreHole,
Expand Down
4 changes: 1 addition & 3 deletions tests/test_band_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pytest
from nomad.datamodel import EntryArchive
from nomad.units import ureg

from nomad_simulations.schema_packages.properties import ElectronicBandGap
from nomad_simulations.schema_packages.variables import Temperature

Expand Down Expand Up @@ -78,9 +79,6 @@ def test_validate_values(self, value: Union[list[float], float], result: float):
(None, None, None),
(None, 'direct', 'direct'),
(None, 'indirect', 'indirect'),
([], None, None),
([], 'direct', 'direct'),
([], 'indirect', 'indirect'),
([[0, 0, 0]], None, None),
([[0, 0, 0]], 'direct', None),
([[0, 0, 0]], 'indirect', None),
Expand Down
35 changes: 1 addition & 34 deletions tests/test_band_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import numpy as np
import pytest
from nomad.datamodel import EntryArchive

from nomad_simulations.schema_packages.properties import ElectronicEigenvalues

from . import logger
Expand Down Expand Up @@ -91,12 +92,6 @@ def test_default_quantities(self, n_bands: Optional[int], rank: Optional[list]):
False,
(None, None),
),
(
[],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
False,
(None, None),
),
(
[[2, 2], [0, 0]],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
Expand Down Expand Up @@ -188,13 +183,6 @@ def test_order_eigenvalues(
None,
(None, None),
),
(
[],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
None,
None,
(None, None),
),
(
[[2, 2], [0, 0]],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
Expand All @@ -217,13 +205,6 @@ def test_order_eigenvalues(
2.0,
(1.0, 2.0),
),
(
[],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
1.0,
2.0,
(1.0, 2.0),
),
(
[[2, 2], [0, 0]],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
Expand Down Expand Up @@ -290,13 +271,6 @@ def test_homo_lumo_eigenvalues(
None,
None,
),
(
[],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
None,
None,
None,
),
(
[[2, 2], [0, 0]],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
Expand All @@ -319,13 +293,6 @@ def test_homo_lumo_eigenvalues(
2.0,
1.0,
),
(
[],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
1.0,
2.0,
1.0,
),
(
[[2, 2], [0, 0]],
[[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]],
Expand Down
Loading

1 comment on commit 4527342

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py14286%53–55
   atoms_state.py1902189%31–33, 219–222, 246, 301–302, 370–371, 373, 555, 567–568, 629–633, 648–652, 659
   general.py75791%29–30, 98, 162, 272–273, 283
   model_method.py2657771%28–30, 189–192, 195–202, 294–295, 315, 336–355, 371–397, 400–417, 771, 782, 824–831, 869, 888, 968, 1025, 1100, 1214
   model_system.py2612292%43–45, 512–515, 562–569, 743–744, 965–969, 975–976, 984–985, 990, 1013
   numerical_settings.py2636575%30–32, 164, 234, 236–237, 240–243, 247–248, 255–258, 267–270, 274–277, 279–282, 287–290, 296–299, 470–497, 572, 607–610, 634, 637, 682, 684–687, 691, 695, 742, 746–767, 822–823, 890, 899–901, 904
   outputs.py1151091%27–28, 247–250, 290–293, 318, 320, 357, 376
   physical_property.py102793%38–40, 220, 349–351
   variables.py651183%26–28, 116, 139, 159–160, 163, 185, 208, 228
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%26–28, 153–154
   band_structure.py1112280%27–29, 249–282, 295, 302, 338–339, 342
   energies.py42979%25–27, 54, 75, 100, 121, 137, 152
   fermi_surface.py17476%25–27, 58
   forces.py22673%26–28, 55, 75, 98
   hopping_matrix.py29583%25–27, 75, 110
   permittivity.py48883%25–27, 115–123
   spectral_profile.py26012851%27–29, 75–78, 113–116, 217–318, 374–386, 411–414, 434, 439–442, 484–520, 544, 591–594, 610–611, 616–622
   thermodynamics.py752764%25–27, 53, 74, 90, 99, 108, 119, 128, 155, 165, 175, 190–192, 195, 211, 231–233, 236, 252, 272–274, 277
src/nomad_simulations/schema_packages/utils
   utils.py681479%26–29, 79–88, 97–98, 103, 106
TOTAL209845478% 

Tests Skipped Failures Errors Time
297 0 💤 0 ❌ 0 🔥 2.306s ⏱️

Please sign in to comment.