Skip to content

Commit

Permalink
use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasibalic committed Dec 26, 2024
1 parent 947b469 commit 8cde825
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
35 changes: 16 additions & 19 deletions .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,42 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest black "black[jupyter]"
pip install build
- name: Check
uv venv
uv run python -m compileall -f arc/*.py
- name: Lint and format check
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 --version
flake8 . --count --show-source --statistics
black --version
black -l 80 . --check
python -m compileall -f arc/*.py
uvx ruff check
uv run python -m compileall -f arc/*.py
- name: Typing check
run: |
uv run mypy .
function_test:
name: Basic test suite
runs-on: ubuntu-latest
needs: [format_test]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v4
with:
python-version: 3.12
python-version: ${{ matrix.python-version }}
- name: Setup ARC
run: |
pip install .
pip install pytest coverage
pytest --version
uv venv
- name: Run tests
run:
coverage run -m pytest -s -v
uv run coverage run -m pytest -s -v
- name: Coverage report
run:
coverage report -m
uv run coverage report -m

build_wheels:
name: Build wheels on ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ dist/
/doc/divalent_atom_data
/doc/generated
/doc/_static
.coverage
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
10 changes: 6 additions & 4 deletions arc/alkali_atom_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def _parseLevelsFromNIST(self, fileData: str):
f.close()
return levels

def _addEnergy(self, n: int, l: float, j: float, energyNIST: float):
def _addEnergy(self, n: int, l: int, j: float, energyNIST: float):
"""
Adding energy levels
Expand Down Expand Up @@ -2886,6 +2886,7 @@ def getSphericalMatrixElementHFStoFS(
for f2 in np.arange(
max(self.I - j2, abs(mf2), f1 - 1), 1 + min(self.I + j2, f1 + 1)
):
f2 = cast(float, f2)
# Enforce Triangle Rule
if abs(j2 - self.I) <= f2:
# CG multiplied by <j1 f1 mf1|er_q|j2 f2 mf2> in units of <j1 || er || j2 >
Expand Down Expand Up @@ -3160,6 +3161,7 @@ def getBranchingRatio(
UsedModulesARC.hyperfine = True
b = 0.0
for q in np.arange(-1, 2):
q = cast(int, q)
b += (
self.getSphericalDipoleMatrixElement(fg, mfg, fe, mfe, q) ** 2
* self._reducedMatrixElementFJ(jg, fg, je, fe) ** 2
Expand Down Expand Up @@ -3869,9 +3871,9 @@ def NumerovBack(

br = divergencePoint
while br > 0:
rad[br] = rad[br + 1] - step
sol[br] = 0
br -= 1
rad[br] = rad[br + 1] - step # type: ignore
sol[br] = 0 # type: ignore
br -= 1 # type: ignore

# convert R(r)*r^{3/4} to R(r)*r
sol = np.multiply(sol, np.sqrt(rad))
Expand Down
13 changes: 8 additions & 5 deletions doc/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ Finally, this is the naming convention. of the original package. For consistency
Code format
-----------

Please run ``black`` in the repository folder fixing line length to 80 characters::
Please run install `uv` and run linter::

black -l 80 .
pip install uv
uvx ruff format
uvx ruff check

And then run linter
and resolve any errors that appear there before submitting code.

flake8 .
Optionally also check typing::

and resolve any erros that appear there before submitting code.
uv pip install mypy
uv run mypy .
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,19 @@ Repository = "https://github.com/nikolasibalic/ARC-Alkali-Rydberg-Calculator"
Documentation = "https://arc-alkali-rydberg-calculator.readthedocs.io/en/latest/"
Download = "https://github.com/nikolasibalic/ARC-Alkali-Rydberg-Calculator/archive/refs/tags/v3.6.0.tar.gz"

[dependency-groups]
dev = [
"cibuildwheel>=2.22.0",
"coverage>=7.6.1",
"mypy>=1.14.0",
"pytest>=8.3.4",
]

[tool.cibuildwheel]
skip = ["*-win32", "*-manylinux_i686", "*-musllinux_i686" ,"pp*"]

[tool.mypy]
disable_error_code = ["import-untyped"]
disable_error_code = ["import-untyped", "import-not-found"]

[tool.ruff]
# Exclude a variety of commonly ignored directories.
Expand Down

0 comments on commit 8cde825

Please sign in to comment.