Skip to content

Commit b4025c0

Browse files
authored
Bump CI to ruff, drop old pythons, add new pythons (#45)
* Bump CI to ruff, drop old pythons, add new pythons * compatibility across major numpy and python versions
1 parent 476036c commit b4025c0

File tree

9 files changed

+172
-120
lines changed

9 files changed

+172
-120
lines changed

.github/workflows/python-package.yaml

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,66 @@ on:
1212
- master
1313

1414
jobs:
15+
lint:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Latest Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.x'
23+
- name: Install Dependancies
24+
run: |
25+
pip install -e .[test]
26+
pre-commit install
27+
- name: Run linting
28+
run: pre-commit run --all-files
29+
1530
unit-test:
1631
runs-on: ubuntu-latest
1732
steps:
18-
- uses: actions/checkout@v3
19-
- name: Set up Python 3.10
20-
uses: actions/setup-python@v4
21-
with:
22-
python-version: "3.10"
23-
- name: Install dependencies
24-
run: |
25-
python -m pip install --upgrade pip
26-
pip install -e .[test]
27-
pre-commit install
28-
pre-commit autoupdate
29-
- name: Lint with precommit checks
30-
run: |
31-
pre-commit run --all-files
32-
- name: Test with Pytest
33-
run: |
34-
pytest \
35-
--junitxml=junit/test-results.xml \
36-
--cov-report=xml --cov=carsons \
37-
tests/
38-
- name: Make coverage file
39-
run: |
40-
coverage xml
41-
- uses: codecov/codecov-action@v3
42-
with:
43-
files: ./coverage.xml # optional
44-
flags: unittests # optional
45-
name: codecov-umbrella # optional
46-
fail_ci_if_error: true # optional (default = false)
47-
verbose: true # optional (default = false)
33+
- uses: actions/checkout@v3
34+
- name: Set up Python 3
35+
uses: actions/setup-python@v4
36+
with:
37+
python-version: '3.x'
38+
- name: Install dependencies
39+
run: pip install -e .[test]
40+
41+
- name: Run tests
42+
run: pytest --cov --cov-report=xml tests/
43+
44+
- name: Report Coverage In Job Summary
45+
run: |
46+
echo "## Coverage Report" >> $GITHUB_STEP_SUMMARY
47+
coverage report -m --format=markdown >> $GITHUB_STEP_SUMMARY
48+
49+
- name: Report coverage annotations
50+
run: pycobertura show coverage.xml --format github-annotation
4851

4952
compatibility:
5053
needs: unit-test
5154
runs-on: ubuntu-latest
5255
strategy:
5356
fail-fast: false
5457
matrix:
55-
python-version: ["3.7", "3.8", "3.9", "3.11", pypy3.8, pypy3.9]
56-
# skipping 3.10 since the unit-test job runs against it
58+
python-version: ["3.10", "3.11", "3.12", "3.13", "pypy3.11"]
59+
numpy-version: ["1.26.4", "2.2.4"]
5760
steps:
5861
- uses: actions/checkout@v3
5962
- name: Set up Python ${{ matrix.python-version }}
6063
uses: actions/setup-python@v4
6164
with:
6265
python-version: ${{ matrix.python-version }}
66+
67+
- name: Install lxml deps for building
68+
if: ${{ startsWith(matrix.python-version, 'pypy' )}}
69+
run: sudo apt-get install libxml2-dev libxslt-dev python3-lxml
70+
6371
- name: Install dependencies
6472
run: |
6573
python -m pip install --upgrade pip
66-
pip install -e .[test]
74+
pip install -e .[test] numpy==${{ matrix.numpy-version }}
6775
- name: Test with Pytest
6876
run: |
69-
pytest
77+
pytest tests/

.github/workflows/python-publish.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,30 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v3
23+
2324
- name: Set up Python
2425
uses: actions/setup-python@v4
2526
with:
2627
python-version: '3.x'
28+
2729
- name: Install dependencies
2830
run: |
2931
python -m pip install --upgrade pip
3032
pip install build
33+
3134
- name: Check VERSION
3235
run: |
3336
if ! echo ${{ env.PUBLISH_TAG }} | grep -P -e "^\d+\.\d+\.\d+((rc|alpha)\d+)?$"; then
3437
echo "Tag ${{ env.PUBLISH_TAG }} doesn't match x.y.z pattern. Not pushing.";
3538
exit 1;
3639
fi
40+
3741
- name: Build package
3842
run: |
3943
echo "Building ${{ env.PUBLISH_TAG }}"
4044
echo ${{ env.PUBLISH_TAG }} > ${{ env.VERSION_FILE }}
4145
python -m build
46+
4247
- name: Publish package
4348
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
4449
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.pytest_cache/
22
.mypy_cache/
33
*/__pycache__/
4+
.ruff_cache
45

56
.coverage
67
.coverage.xml

.pre-commit-config.yaml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,38 @@
1515
# run a single hook: pre-commit run --all-files black
1616
repos:
1717
- repo: https://github.com/pre-commit/pre-commit-hooks
18-
rev: v4.4.0
18+
rev: v5.0.0
1919
hooks:
2020
- id: mixed-line-ending
2121
args: ['--fix=lf']
2222
description: Forces to replace line ending by the UNIX 'lf' character.
2323

24-
- repo: https://github.com/pycqa/flake8
25-
rev: 6.0.0
24+
- repo: https://github.com/tox-dev/pyproject-fmt
25+
rev: v2.5.1
2626
hooks:
27-
- id: flake8
28-
name: Flake PEP8 check
29-
additional_dependencies: ["importlib-metadata<=4.13.0"]
30-
args: ["--max-line-length=120"]
27+
- id: pyproject-fmt
3128

32-
- repo: https://github.com/psf/black
33-
rev: 22.12.0
29+
- repo: https://github.com/dhatim/python-license-check
30+
rev: "0.9.2"
3431
hooks:
35-
- id: black
36-
name: Black autoformatting
32+
- id: liccheck
33+
language: system
3734

38-
- repo: https://github.com/pycqa/isort
39-
rev: 5.11.4
35+
- repo: https://github.com/PyCQA/bandit
36+
rev: "1.8.3"
4037
hooks:
41-
- id: isort
38+
- id: bandit
39+
args: ["-c", "pyproject.toml"]
40+
additional_dependencies: ["bandit[toml]"]
41+
42+
- repo: https://github.com/astral-sh/ruff-pre-commit
43+
rev: v0.11.2
44+
hooks:
45+
- id: ruff # linter
46+
args: [ --fix ]
47+
- id: ruff-format
4248

4349
- repo: https://github.com/pre-commit/mirrors-mypy
44-
rev: "v0.991"
50+
rev: v1.15.0
4551
hooks:
4652
- id: mypy

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ carsons
44
[![latest release on pypi](https://badge.fury.io/py/carsons.svg)](https://badge.fury.io/py/carsons)
55
[![versons of python supported by carsons](https://img.shields.io/pypi/pyversions/carsons.svg)](https://pypi.python.org/pypi/carsons)
66
[![GitHub license](https://img.shields.io/github/license/opusonesolutions/carsons.svg)](https://github.com/opusonesolutions/carsons/blob/master/LICENSE.txt)
7-
[![build passing or failing](https://github.com/opusonesolutions/carsons/blob/master/.github/workflows/python-package.yaml/badge.svg)](https://travis-ci.org/opusonesolutions/carsons)
8-
[![test coverage](https://coveralls.io/repos/github/opusonesolutions/carsons/badge.svg?branch=master)](https://coveralls.io/github/opusonesolutions/carsons?branch=master)
9-
[![Maintainability](https://api.codeclimate.com/v1/badges/22cfed180fd6032fe29b/maintainability)](https://codeclimate.com/github/opusonesolutions/carsons/maintainability)
107

118
This is an implementation of Carson's Equations, a mathematical model
129
for deriving the equivalent impedance of an AC transmission or

carsons/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from carsons.carsons import ( # noqa F401
1+
from carsons.carsons import (
22
CarsonsEquations,
33
ConcentricNeutralCarsonsEquations,
44
MultiConductorCarsonsEquations,
@@ -9,22 +9,24 @@
99
convert_geometric_model,
1010
)
1111

12+
__all__ = [
13+
"CarsonsEquations",
14+
"ConcentricNeutralCarsonsEquations",
15+
"MultiConductorCarsonsEquations",
16+
"TapeShieldedCableCarsonsEquations",
17+
"calculate_impedance",
18+
"calculate_sequence_impedance_matrix",
19+
"calculate_sequence_impedances",
20+
"convert_geometric_model",
21+
]
22+
1223
name = "carsons"
1324

1425

1526
def get_version():
16-
import sys
17-
18-
# TODO: if 3.8 support is dropped, we can standardize on
19-
# importlib.resources.files
20-
if sys.version_info < (3, 9):
21-
from importlib.resources import read_text
22-
23-
return read_text(__name__, "VERSION").strip()
24-
else:
25-
from importlib.resources import files
27+
from importlib.resources import files
2628

27-
return files(__name__).joinpath("VERSION").open("r").read().strip()
29+
return files(__name__).joinpath("VERSION").open("r").read().strip()
2830

2931

3032
__version__ = get_version()

carsons/carsons.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from collections import defaultdict
22
from itertools import islice
3-
from typing import Dict, Iterable, Iterator, Tuple
3+
from typing import Iterable, Iterator
44

5-
from numpy import arctan, array, cos, exp, log, ndarray
5+
from numpy import arctan, array, cos, exp, log, ndarray, sin, sqrt, zeros
66
from numpy import pi as π
7-
from numpy import sin, sqrt, zeros
87
from numpy.linalg import inv
98

109
alpha = exp(2j * π / 3)
@@ -94,15 +93,14 @@ def calculate_sequence_impedances(Z):
9493

9594

9695
class CarsonsEquations:
97-
9896
ρ = 100 # resistivity, ohms/meter^3
9997
μ = 4 * π * 1e-7 # permeability, Henry / meter
10098

10199
def __init__(self, model):
102100
self.phases: Iterable[str] = model.phases
103-
self.phase_positions: Dict[str, Tuple[float, float]] = model.wire_positions
104-
self.gmr: Dict[str, float] = model.geometric_mean_radius
105-
self.r: Dict[str, float] = model.resistance
101+
self.phase_positions: dict[str, tuple[float, float]] = model.wire_positions
102+
self.gmr: dict[str, float] = model.geometric_mean_radius
103+
self.r: dict[str, float] = model.resistance
106104

107105
self.ƒ = getattr(model, "frequency", 60)
108106
self.ω = 2.0 * π * self.ƒ # angular frequency radians / second
@@ -254,15 +252,15 @@ def compute_X(self, i, j) -> float:
254252
class ConcentricNeutralCarsonsEquations(ModifiedCarsonsEquations):
255253
def __init__(self, model, *args, **kwargs):
256254
super().__init__(model)
257-
self.neutral_strand_gmr: Dict[str, float] = model.neutral_strand_gmr
258-
self.neutral_strand_count: Dict[str, float] = defaultdict(
255+
self.neutral_strand_gmr: dict[str, float] = model.neutral_strand_gmr
256+
self.neutral_strand_count: dict[str, float] = defaultdict(
259257
lambda: None, model.neutral_strand_count
260258
)
261-
self.neutral_strand_resistance: Dict[
262-
str, float
263-
] = model.neutral_strand_resistance
259+
self.neutral_strand_resistance: dict[str, float] = (
260+
model.neutral_strand_resistance
261+
)
264262
# fmt: off
265-
self.radius: Dict[str, float] = defaultdict(
263+
self.radius: dict[str, float] = defaultdict(
266264
lambda: None,
267265
{
268266
phase: (diameter_over_neutral - model.neutral_strand_diameter[phase]) / 2
@@ -316,7 +314,6 @@ def GMR_cn(self, phase) -> float:
316314

317315

318316
class TapeShieldedCableCarsonsEquations(ModifiedCarsonsEquations):
319-
320317
ρ_tape_shield = 1.7721e-8 # copper resistivity at 20 degrees, ohm-meter
321318

322319
def __init__(self, model, *args, **kwargs):
@@ -373,7 +370,7 @@ def conductors(self):
373370
class MultiConductorCarsonsEquations(ModifiedCarsonsEquations):
374371
def __init__(self, model):
375372
super().__init__(model)
376-
self.outside_radius: Dict[str, float] = model.outside_radius
373+
self.outside_radius: dict[str, float] = model.outside_radius
377374

378375
def compute_d(self, i, j) -> float:
379376
# Assumptions:

0 commit comments

Comments
 (0)