Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace black with ruff formatter #19

Merged
merged 9 commits into from
Mar 4, 2024
80 changes: 26 additions & 54 deletions .github/workflows/_build_package.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,26 @@
name: Build Package

on: workflow_call

jobs:
build:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
lfs: true
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install build and twine
run: pip install build twine
- name: Run build
run: python -m build
- name: Run twine check
run: twine check --strict dist/*
- uses: actions/upload-artifact@v3
with:
path: ./dist/*.tar.gz

# build_wheels:
# name: Build wheels for ${{ matrix.platform }}
# needs:
# - black
# - ruff
# - pyright
# - test
# runs-on: ${{ matrix.platform }}
# strategy:
# matrix:
# platform: [ubuntu-latest, macos-latest, windows-latest]
# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 1
# lfs: true
# - uses: actions/setup-python@v4
# with:
# python-version: '3.11'
# cache: 'pip' # cache pip dependencies
# - name: Install cibuildwheel
# run: python -m pip install cibuildwheel==2.16
# - name: Build wheels
# run: python -m cibuildwheel --output-dir wheels
# - uses: actions/upload-artifact@v3
# with:
# path: ./wheels/*.whl
name: Build Package

on: workflow_call

jobs:
build:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
lfs: true
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install build and twine
run: pip install build twine
- name: Run build
run: python -m build
- name: Run twine check
run: twine check --strict dist/*
- uses: actions/upload-artifact@v3
with:
path: ./dist/*.tar.gz
104 changes: 54 additions & 50 deletions .github/workflows/_code_quality.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
name: Code Quality

on: workflow_call

jobs:
black:
name: black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: '--check --diff'
src: '.'
jupyter: true
version: '==24.1'

ruff:
runs-on: ubuntu-latest
name: ruff
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install dependencies
run: pip install -r requirements.txt
- name: Install ruff
run: pip install ruff==0.3.0
- name: Run ruff
run: ruff .

pyright:
runs-on: ubuntu-latest
name: pyright
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest
- name: Install pyright
run: pip install pyright==1.1.352
- name: Run pyright
run: pyright .
name: Code Quality

on: workflow_call

jobs:
ruff_format:
runs-on: ubuntu-latest
name: ruff format
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install dependencies
run: pip install -r requirements.txt
- name: Install ruff
run: pip install ruff==0.3.0
- name: Run ruff format
run: ruff format --diff .

ruff_check:
runs-on: ubuntu-latest
name: ruff check
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install dependencies
run: pip install -r requirements.txt
- name: Install ruff
run: pip install ruff==0.3.0
- name: Run ruff check
run: ruff check --diff .

pyright:
runs-on: ubuntu-latest
name: pyright
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest
- name: Install pyright
run: pip install pyright==1.1.352
- name: Run pyright
run: pyright .
10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"python.languageServer": "Pylance",
"ruff.importStrategy": "fromEnvironment",
"editor.formatOnSave": true,
"notebook.formatOnSave.enabled": true,
"notebook.codeActionsOnSave": {
"notebook.source.fixAll": true,
"notebook.source.organizeImports": true,
},
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
"source.fixAll": "always",
"source.organizeImports": "always",
},
"editor.defaultFormatter": "charliermarsh.ruff",
},
"autoDocstring.docstringFormat": "numpy",
"python.testing.unittestEnabled": false,
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e

## [Unreleased]

### Changed
* replaced black formatter with ruff formatter

### Dependencies
* updated to ruff==0.3.0 (from ruff==0.2.1)
* updated to pyright==1.1.352 (from pyright==1.1.350)
* updated to numpy>=1.26,<2.0 (from numpy>=1.26
)
* updated to numpy>=1.26,<2.0 (from numpy>=1.26)
* removed black

### Changed
* Changed publishing workflow to use OpenID Connect (Trusted Publisher Management) when publishing to PyPI
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ watchCosim = "ospx.watch.cli.watchCosim:main"
where = ["src"]
exclude = ["test*"]

[tool.black]
line-length = 120
target-version = ["py39", "py310", "py311", "py312"]

[tool.ruff]
exclude = [
".git",
Expand Down Expand Up @@ -120,6 +116,9 @@ convention = "numpy"
"__init__.py" = ["I001"]
"./tests/*" = ["D"]

[tool.ruff.format]
docstring-code-format = true

[tool.pyright]
exclude = [
".git",
Expand Down
6 changes: 3 additions & 3 deletions qa.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black .
ruff .
ruff format .
ruff check .
pyright .
sourcery review .
sourcery review .
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pytest>=7.4
pytest-cov>=4.1
black[jupyter]==24.1
ruff==0.3.0
pyright==1.1.352
Sphinx>=7.2
Expand Down
6 changes: 3 additions & 3 deletions src/ospx/fmi/fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ def _modify_start_values(self, variables_with_start_values: dict[str, ScalarVari

model_variables[model_variable_key][type_key]["_attributes"]["start"] = variable_with_start_values.start
model_variables[model_variable_key]["_attributes"]["causality"] = variable_with_start_values.causality
model_variables[model_variable_key]["_attributes"][
"variability"
] = variable_with_start_values.variability
model_variables[model_variable_key]["_attributes"]["variability"] = (
variable_with_start_values.variability
)

self._log_update_in_model_description()

Expand Down
4 changes: 1 addition & 3 deletions src/ospx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ def _get_edge_label(connection: Connection) -> str:
def _create_table(name: str, child: Union[Dict[str, Any], None] = None) -> str:
_child: Dict[str, Any] = child or {" ": " "}
n_child = len(_child)
string: str = (
f'<\n<TABLE BORDER="1" CELLBORDER="1" CELLSPACING="0">\n<TR>\n<TD COLSPAN="{2 * n_child:d}">{name}</TD>\n</TR>\n'
)
string: str = f'<\n<TABLE BORDER="1" CELLBORDER="1" CELLSPACING="0">\n<TR>\n<TD COLSPAN="{2 * n_child:d}">{name}</TD>\n</TR>\n'
for key, item in _child.items():
string += f"<TR><TD>{key}</TD><TD>{item}</TD></TR>\n"
string += "</TABLE>\n>"
Expand Down
8 changes: 2 additions & 6 deletions src/ospx/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ def import_system_structure(
logger.error(msg)
raise NotImplementedError(msg)
else:
msg: str = (
f"Import failed: {system_structure_file.name} contains a connection with unknown connection type '{connection_type}'\n"
)
msg: str = f"Import failed: {system_structure_file.name} contains a connection with unknown connection type '{connection_type}'\n"
logger.error(msg)
raise TypeError(msg)

Expand All @@ -119,9 +117,7 @@ def import_system_structure(
logger.error(msg)
raise NotImplementedError(msg)
else:
msg: str = (
f"Import failed: {system_structure_file.name} contains a connection with unknown endpoint type '{endpoint_type}'\n"
)
msg: str = f"Import failed: {system_structure_file.name} contains a connection with unknown endpoint type '{endpoint_type}'\n"
logger.error(msg)
raise TypeError(msg)

Expand Down
Loading