Skip to content

Commit

Permalink
chore: use ruff for linting (#29)
Browse files Browse the repository at this point in the history
* Fix inline quotes

* Fix unnecessary assignments before return

* Simplify code according to flake8-simplify

* Correct docstrings

* Add ruff and disable flake8 and pylint

* Update readme
  • Loading branch information
mortenengen authored Nov 2, 2023
1 parent 876d2bd commit d64254a
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 165 deletions.
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.pylintEnabled": true,
"python.linting.flake8Enabled": true
"python.testing.pytestEnabled": true
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

[![Build](https://github.com/fib-international/structuralcodes/actions/workflows/build.yaml/badge.svg)](https://github.com/fib-international/structuralcodes/actions/workflows/build.yaml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v0.json)](https://github.com/charliermarsh/ruff)

**:construction: Note! This package is work in progress. Feel free to join the discussions in the pull requests. :construction:**

Expand Down Expand Up @@ -36,7 +37,7 @@ Then:
- Start developing the feature in a feature branch with a suitable title :rocket:
- Please follow common best practice when committing, provide a meaningful commit message, and split different sub-topics in separate commits :thumbsup:
- Feel free to open a draft pull request as soon as you start committing so that the community can follow the development. The core team will make sure the pull request is linked to the relevant issue, and that we [keep track of the progress](https://github.com/orgs/fib-international/projects/1).
- We use `black`, `flake8` and `pylint` for code formatting and linting, and we have a test suite based on `pytest`. Please make sure that these checks pass before committing code :heavy_check_mark:
- We use `black` and `ruff` for code formatting and linting, and we have a test suite based on `pytest`. Please make sure that these checks pass before committing code :heavy_check_mark:
- Remember to add tests for the new features that you implement :man_scientist:
- Remember to add docstrings to your functions and classes. We use the [google format](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).
- When you feel that your contribution is ready, mark your pull request as ready for review, and we will assign some suitable reviewers :nerd_face:
Expand All @@ -47,6 +48,6 @@ The core team continues working on the structure for the higher levels of the pa

For the moment, there are no third party dependencies to the package, but it is always useful to work in a virtual environment. To create one on Windows, type `py -m venv venv`, and activate it by typing `venv\scripts\activate`.

We use `black` for code formatting, `flake8` and `pylint` for linting, and have set up our test suite using `pytest`. Make sure you have these installed (`make deps`). We have set up VS Code to use these tools automatically. Open VS Code inside the repo (`code .`), view the tests in the test pane on the left side, and notice how the linters highlight parts of your code that should be rewritten.
We use `black` for code formatting, `ruff` for linting, and have set up our test suite using `pytest`. Make sure you have these installed (`make deps`). We have set up VS Code to use testing. Open VS Code inside the repo (`code .`) and view the tests in the test pane on the left side.

We have supplied a makefile that you may use to run formatting (`make form`), linting (`make lint`) and testing (`make test`). Don't have `make`? You can get it from [chocolatey](https://community.chocolatey.org/packages/make), `choco install make`. If you don't want to use `make`, feel free to e.g. `py -m black structuralcodes` and `py -m pytest`.
We have supplied a makefile that you may use to run formatting (`make form`), linting (`make lint`) and testing (`make test`). Don't have `make`? You can get it from [chocolatey](https://community.chocolatey.org/packages/make), `choco install make`. If you don't want to use `make`, feel free to manually type the commands from the makefile e.g. `py -m black structuralcodes` and `py -m pytest`.
5 changes: 2 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deps: ## Install dependencies
python -m pip install --upgrade wheel
python -m pip install -r requirements.txt
python -m pip install --upgrade black
python -m pip install --upgrade flake8 mccabe pylint
python -m pip install ruff==0.0.291
python -m pip install --upgrade flit
python -m pip install --upgrade pytest pytest-cov

Expand All @@ -17,8 +17,7 @@ form: ## Code formatting
python -m black tests

lint: ## Linting and static type checking
python -m flake8 $(PACKAGE_NAME)
python -m pylint $(PACKAGE_NAME)
python -m ruff $(PACKAGE_NAME)

test: ## Run tests and output reports
python -m pytest --junitxml=junit/test-results.xml --cov=$(PACKAGE_NAME) --cov-report=term-missing --cov-report=xml
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,41 @@ line-length = 79
skip-string-normalization = "True"
check = "True"
diff = "True"

[tool.ruff]
line-length = 79
select = [
"F",
"E",
"W",
"N",
"BLE",
"Q",
"D",
"RET",
"SIM",
"ARG",
"PLC",
"PLE",
"PLR",
"PLW",
]
ignore = [
"N802",
"N803",
"N806",
"N999",
"PLR0913",
"PLR2004",
"PLW0603",
"D205",
"D417",
]

[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.flake8-quotes]
docstring-quotes = "double"
inline-quotes = "single"
multiline-quotes = "double"
2 changes: 1 addition & 1 deletion structuralcodes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""A Python package that contains models from structural design codes"""
"""A Python package that contains models from structural design codes."""
from . import codes, core, materials
from .codes import get_design_codes, set_design_code, set_national_annex

Expand Down
2 changes: 1 addition & 1 deletion structuralcodes/codes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Collection of functions related to design codes"""
"""Collection of functions related to design codes."""
import types
import typing as t

Expand Down
2 changes: 1 addition & 1 deletion structuralcodes/codes/ec2_2004/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""EUROCODE 2 1992-1-1:2004"""
"""EUROCODE 2 1992-1-1:2004."""
import typing as t

from ._section_7_3_crack_control import (
Expand Down
29 changes: 14 additions & 15 deletions structuralcodes/codes/ec2_2004/_section_7_3_crack_control.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Collection of functions from EUROCODE 1992-1-1:2004
Chapter 7.3 - Crack control"""
Chapter 7.3 - Crack control.
"""
import math
import typing as t

Expand Down Expand Up @@ -62,7 +63,7 @@ def As_min(
A_ct: float, sigma_s: float, fct_eff: float, _k: float, kc: float
) -> float:
"""Computes the minimum area of reinforcing steel within the tensile zone
for control of cracking areas
for control of cracking areas.
EUROCODE 2 1992-1-1:2004, Eq. (7.1)
Expand Down Expand Up @@ -117,7 +118,7 @@ def k(h: float) -> float:
non-uniform self-equilibrating stresses, which lead to a
reduction of restraint forces.
k=1 for webs w<=300mm or flanges widths less than 300mm
k=0.65 for webs w>=800mm or flanges with widths greater than 800mm
k=0.65 for webs w>=800mm or flanges with widths greater than 800mm.
EUROCODE 2 1992-1-1:2004, Eq. (7.1)
Expand Down Expand Up @@ -243,7 +244,6 @@ def xi1(xi: float, phi_p: float, phi_s: float) -> float:
ValueError: if diameters phi_s or phi_p are lower than 0.
If ratio of bond strength xi is less than 0.15 or larger than 0.8.
"""

if phi_p <= 0:
raise ValueError(f'phi_p={phi_p} cannot be less than 0')
if phi_s < 0:
Expand Down Expand Up @@ -302,7 +302,7 @@ def As_min_p(
delta_s: float,
) -> float:
"""Computes the minimum area of reinforcing steel within the tensile zone
for control of cracking areas in addition with bonded tendons
for control of cracking areas in addition with bonded tendons.
EUROCODE 2 1992-1-1:2004, Eq. (7.1)
Expand Down Expand Up @@ -385,7 +385,7 @@ def As_min_2(
kc: t.Optional[float] = None,
) -> t.Tuple[float, float]:
"""Computes the minimum area of reinforcing steel within the tensile zone
for control of cracking areas
for control of cracking areas.
EUROCODE 2 1992-1-1:2004, Table (7.2N), Table (7.3N)
Expand Down Expand Up @@ -532,7 +532,7 @@ def alpha_e(Es: float, Ecm: float) -> float:


def rho_p_eff(As: float, _xi1: float, Ap: float, Ac_eff: float) -> float:
"""Effective bond ratio between areas
"""Effective bond ratio between areas.
EUROCODE 2 1992-1-1:2004, Eq. (7.10)
Expand Down Expand Up @@ -565,7 +565,7 @@ def rho_p_eff(As: float, _xi1: float, Ap: float, Ac_eff: float) -> float:

def kt(load_type: str) -> float:
"""Returns the kt factor dependent on the load duration for
the crack width calculation
the crack width calculation.
Args:
load_type (str): the load type:
Expand Down Expand Up @@ -680,7 +680,7 @@ def w_spacing(c: float, phi: float) -> float:

def phi_eq(n1: int, n2: int, phi1: float, phi2: float) -> float:
"""Computes the equivalent diameter. For a section with n1 bars of
diameter phi1 and n2 bars of diameter phi2
diameter phi1 and n2 bars of diameter phi2.
EUROCODE 2 1992-1-1:2004, Sect. (7.12)
Expand Down Expand Up @@ -718,7 +718,7 @@ def phi_eq(n1: int, n2: int, phi1: float, phi2: float) -> float:

def k1(bond_type: str) -> float:
"""Get the k1 coefficient which takes account of the bond properties
of the bounded reinforcement
of the bounded reinforcement.
EUROCODE 2 1992-1-1:2004, Eq. (7.11-k1)
Expand Down Expand Up @@ -749,8 +749,7 @@ def k1(bond_type: str) -> float:


def k2(eps_r: float) -> float:
"""Computes a coefficient which takes into account of the
distribution of strain:
"""Computes a coeff. which takes into account the distribution of strain.
EUROCODE 2 1992-1-1:2004, Eq. (7.13)
Expand All @@ -773,7 +772,7 @@ def k2(eps_r: float) -> float:


def k3():
"""Returns the k3 coefficient for computing sr_max
"""Returns the k3 coefficient for computing sr_max.
Returns:
float: value for the coefficient
Expand All @@ -782,7 +781,7 @@ def k3():


def k4():
"""Returns the k4 coefficient for computing sr_max
"""Returns the k4 coefficient for computing sr_max.
Returns:
float: value for the coefficient
Expand Down Expand Up @@ -912,7 +911,7 @@ def sr_max_theta(sr_max_y: float, sr_max_z: float, theta: float) -> float:


def wk(sr_max: float, _eps_sm_eps_cm: float) -> float:
"""Computes the crack width
"""Computes the crack width.
EUROCODE 2 1992-1-1:2004, Eq. (7.8)
Expand Down
2 changes: 1 addition & 1 deletion structuralcodes/codes/mc2010/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""The fib Model Code 2010"""
"""The fib Model Code 2010."""
import typing as t
from ._concrete_material_properties import fcm, fctm, fctkmin, fctkmax, Gf

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"Shear at the interface between concrete with different casting times"
"""Shear at the interface between concrete with different casting times."""
from math import pi, sin, cos


def tau_edi(beta: float, v_ed: float, z: float, b_i: float):
"""Shear at the interface between concrete cast at different times
"""Shear at the interface between concrete cast at different times.
fib Model Code 2010, eq. (7.3-49)
Expand All @@ -14,8 +14,9 @@ def tau_edi(beta: float, v_ed: float, z: float, b_i: float):
z (float): The inner lever arm of the composed section in mm
b_i (float): The width of the inerface in mm
return:
The shear force that should be used at the intersection"""
Return:
The shear force that should be used at the intersection
"""
return (beta * v_ed) / (z * b_i)


Expand All @@ -28,7 +29,7 @@ def tau_rdi_without_reinforcement(
f_cd: float,
):
"""Shear resistance without reinforcement at the intesection with
different casting time
different casting time.
fib Model Code 2010, eq. (7.3-50)
Expand All @@ -44,8 +45,8 @@ def tau_rdi_without_reinforcement(
Return:
The shear resistance without reinforcement at the intesection with
different casting time"""

different casting time
"""
v = min(0.55 * (30 / f_ck) ** (1 / 3), 0.55)
return min((c_a * f_ctd) + (mu * sigma_n), 0.5 * v * f_cd)

Expand All @@ -64,7 +65,7 @@ def tau_rdi_with_reinforcement(
f_cd: float,
):
"""Shear resistance with reinforcement or dowels at the intesection with
different casting time
different casting time.
fib Model Code 2010, eq. (7.3-51)
Expand All @@ -90,13 +91,13 @@ def tau_rdi_with_reinforcement(
Return:
Shear resistance with reinforcement at intesection with
different casting time"""
different casting time
"""
v = min(0.55 * (30 / f_ck) ** (1 / 3), 0.55)
result = min(
return min(
(c_r * f_ck ** (1 / 3))
+ (mu * sigma_n)
+ k1 * ro * f_yd * (mu * sin(alpha * pi / 180) + cos(alpha * pi / 180))
+ k2 * ro * (f_yd * f_cd) ** 0.5,
beta_c * v * f_cd,
)
return result
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""A collection of material properties for concrete"""
"""A collection of material properties for concrete."""
import math


Expand Down
Loading

0 comments on commit d64254a

Please sign in to comment.