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

Style switch to ruff format #1652

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
24fe611
Merge pull request #1639 from Deltares/add_ci
SGeeversAtVortech Oct 8, 2024
4ab4100
readme: update workflow status badge
SGeeversAtVortech Oct 15, 2024
e811168
readme: update info on github migration
SGeeversAtVortech Oct 15, 2024
ed8f275
Merge pull request #1641 from Deltares/update_readme
jarsarasty Oct 15, 2024
3f95875
versioneer: update versioneer
SGeeversAtVortech Nov 15, 2024
b031806
setup: unpin numpy and scipy dependencies
SGeeversAtVortech Nov 15, 2024
d5b5700
csv: fix string conversion in loading csv files
SGeeversAtVortech Nov 15, 2024
7e54817
modelica_mixin: fix except clause when model transfer failed
SGeeversAtVortech Nov 15, 2024
a8a8dd6
tests: update missing values in test data
SGeeversAtVortech Nov 15, 2024
fb9335d
tests: update tests for python 3.12
SGeeversAtVortech Nov 15, 2024
76bab09
docs: fix cross reference
SGeeversAtVortech Nov 15, 2024
6f509e7
docs: set languange to English
SGeeversAtVortech Nov 15, 2024
ddc92c4
docs: update install instructions
SGeeversAtVortech Nov 15, 2024
6b9d5da
docs: use np.genfromtxt instead of recfromcsv
SGeeversAtVortech Nov 15, 2024
be3b540
doc: remove deprecated get_html_theme_path
SGeeversAtVortech Nov 26, 2024
b5312d7
Merge pull request #1644 from Deltares/upgrade_for_python_3_12
SGeeversAtVortech Dec 6, 2024
4a96354
fix: Typo
datawookie Jan 12, 2025
10d1626
fix: Same typo, different file
datawookie Jan 22, 2025
f856a4a
Merge pull request #1646 from datawookie/patch-1
jarsarasty Jan 28, 2025
f1df48b
Bump minimum requried Python version to 3.9
jackvreeken Jan 28, 2025
c056794
Remove obsolete .gitlab-ci.yml
jackvreeken Jan 28, 2025
7528b4f
CI/CD: Run tests on Python 3.13 as well
jackvreeken Jan 28, 2025
6c05c9b
CI/CD: Create deploy job
jackvreeken Feb 4, 2025
48e1821
CI/CD: Run examples job in parallel with coverage
jackvreeken Jan 28, 2025
689e5f1
CI/CD: Run coverage in parallel with tests
jackvreeken Jan 29, 2025
3bdb1fd
CI/CD: Unify 'build' packaging command
jackvreeken Feb 4, 2025
1560be1
Remove dependency on deprecated pkg_resources
jackvreeken Feb 4, 2025
6886778
Style: Switch from Black to Ruff Format
jackvreeken Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions .github/workflows/rtc-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v4.1.0
- run: python setup.py sdist bdist_wheel
- run: |
python -m pip install --upgrade pip
pip install build
- run: python -m build
- uses: actions/upload-artifact@v4
if: success()
with:
Expand All @@ -50,13 +53,15 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
steps:
- uses: actions/checkout@v4
- run: pip install tox
- run: tox -vv

coverage:
needs: test-linux
needs: build
runs-on: ubuntu-latest
container:
image: python:3.9
Expand All @@ -71,7 +76,7 @@ jobs:
# - run: codecov --token=$CODECOV_TOKEN

examples-linux:
needs: coverage
needs: build
runs-on: ubuntu-latest
container:
image: python:${{ matrix.version }}
Expand All @@ -85,22 +90,36 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
steps:
- uses: actions/checkout@v4.1.0
- run: pip install tox
- run: tox -vv

# deploy:
# needs: examples-linux
# runs-on: ubuntu-latest
# container:
# image: python:3.9
# if: (github.ref == 'refs/tags//^2\..*$/') && !(startsWith(github.ref, 'refs/heads'))
# timeout-minutes: 30
# steps:
# - uses: actions/checkout@v4.1.0
# - uses: actions/download-artifact@v4.1.0
# with:
# name: "${{ github.job }}"
# - run: pip install twine
# - run: twine upload -u $PYPI_USER -p $PYPI_PASSWORD dist/*
deploy:
needs: [test-linux, coverage, examples-linux]
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/2.') }}
permissions:
id-token: write # Required for OIDC PyPI publishing
contents: read
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build

- name: Build package
run: python -m build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
90 changes: 0 additions & 90 deletions .gitlab-ci.yml

This file was deleted.

8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ exclude: |
versioneer.py
)$
repos:
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
rev: v0.9.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
9 changes: 4 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Commit messages should have the following structure:

To set up your development environment, you will need:

- Python 3.8 or higher
- Python 3.9 or higher
- Git

You can clone the repository and install it from source:
Expand Down Expand Up @@ -104,12 +104,11 @@ pip install pytest
pytest tests
```

To build the documentation, you will need Sphinx amd the sphnix-rtd-theme:
To build the documentation, you will need matploblib, sphinx and sphinx-rtd-theme:

```bash
pip install sphinx
pip install sphnix-rtd-theme
cd docs
pip install matplotlib sphinx sphinx-rtd-theme
cd doc
make html
```

Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Deltares RTC-Tools

[![Pipeline](https://gitlab.com/deltares/rtc-tools/badges/master/pipeline.svg)](https://gitlab.com/deltares/rtc-tools/commits/master)
[![Coverage](https://codecov.io/gl/deltares/rtc-tools/branch/master/graph/badge.svg)](https://codecov.io/gl/deltares/rtc-tools)
[![Pipeline](https://github.com/deltares/rtc-tools/actions/workflows/rtc-tools.yml/badge.svg)](
https://github.com/deltares/rtc-tools/actions/workflows/rtc-tools.yml
)
[![Coverage](https://codecov.io/gl/deltares/rtc-tools/branch/master/graph/badge.svg)](
https://codecov.io/gl/deltares/rtc-tools
)

> **NOTE** The rtc-tools repository has been migrated from gitlab to here;
see [migration from gitlab](#migration-from-gitlab).

RTC-Tools is an open-source Python package for simulation and optimization of cyber-physical systems. It can be used for model-predictive control and operational decision making of water and energy systems. It is developed and maintained by Deltares, in collaboration with partners.

Expand Down Expand Up @@ -45,6 +51,19 @@ pip install rtc-tools
Documentation and examples can be found on [readthedocs](https://rtc-tools.readthedocs.io).


## Migration from GitLab

The rtc-tools repository has been migrated from gitlab (https://gitlab.com/deltares/rtc-tools)
to here.
To change the git remote url, run

`git remote set-url origin https://github.com/Deltares/rtc-tools.git`

and

`git remote set-url --push origin https://github.com/Deltares/rtc-tools.git`.


## License
RTC-Tools is licensed under the **[GNU Lesser General Public License v3.0](https://gitlab.com/deltares/rtc-tools/-/blob/guidelines_contributions/COPYING)**, and can be used free of charge. Deltares offers support packages for users who require assistance.

Expand Down
5 changes: 1 addition & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os
import re

import sphinx_rtd_theme
from rtctools._version import get_versions

# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -77,7 +76,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down Expand Up @@ -139,8 +138,6 @@
# html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

html_static_path = ["_static"]

html_css_files = [
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/optimization/ensemble.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ should print out the following lines::
This is the same output as the output for :doc:`mixed_integer`, except
now the output for each ensemble is printed.


.. _ensemble-results:

Extracting Results
------------------

Expand All @@ -254,9 +257,6 @@ matplotlib:
.. plot:: examples/pyplots/ensemble_results.py
:include-source:


.. _ensemble-results:

This plots the inflow and release values in two different ways: the middle graph
depicts them in the same way you have seen until now (and this is how they truly
should be interpreted). The lower plot shows the same points, but connected with
Expand Down
8 changes: 6 additions & 2 deletions doc/examples/pyplots/basic_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

# Import Data
output_data_path = "../../../examples/basic/reference_output/timeseries_export.csv"
results = np.recfromcsv(output_data_path, encoding=None)
results = np.genfromtxt(
output_data_path, delimiter=",", encoding=None, dtype=None, names=True, case_sensitive="lower"
)
input_data_path = "../../../examples/basic/input/timeseries_import.csv"
input_data = np.recfromcsv(input_data_path, encoding=None)
input_data = np.genfromtxt(
input_data_path, delimiter=",", encoding=None, dtype=None, names=True, case_sensitive="lower"
)

# Get times as datetime objects
times = [datetime.strptime(x, "%Y-%m-%d %H:%M:%S") for x in results["time"]]
Expand Down
4 changes: 3 additions & 1 deletion doc/examples/pyplots/cascading_channels_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

# Import Data
data_path = "../../../examples/cascading_channels/reference_output/timeseries_export.csv"
record = np.recfromcsv(data_path, encoding=None)
record = np.genfromtxt(
data_path, delimiter=",", encoding=None, dtype=None, names=True, case_sensitive="lower"
)

# Get times as datetime objects
times = [datetime.strptime(x, "%Y-%m-%d %H:%M:%S") for x in record["time"]]
Expand Down
45 changes: 37 additions & 8 deletions doc/examples/pyplots/channel_pulse_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,46 @@
output_dir = Path("../../../examples/channel_pulse/reference_output/").resolve()

# Import Data
rtc_tools_record = np.recfromcsv(output_dir / "timeseries_export_inertial_wave.csv", encoding=None)
rtc_tools_semi_impl_record = np.recfromcsv(
output_dir / "timeseries_export_inertial_wave_semi_implicit.csv", encoding=None
rtc_tools_record = np.genfromtxt(
output_dir / "timeseries_export_inertial_wave.csv",
delimiter=",",
encoding=None,
dtype=None,
names=True,
case_sensitive="lower",
)
rtc_tools_conv_acc_record = np.recfromcsv(
output_dir / "timeseries_export_saint_venant.csv", encoding=None
rtc_tools_semi_impl_record = np.genfromtxt(
output_dir / "timeseries_export_inertial_wave_semi_implicit.csv",
delimiter=",",
encoding=None,
dtype=None,
names=True,
case_sensitive="lower",
)
rtc_tools_conv_acc_upwind_record = np.recfromcsv(
output_dir / "timeseries_export_saint_venant_upwind.csv", encoding=None
rtc_tools_conv_acc_record = np.genfromtxt(
output_dir / "timeseries_export_saint_venant.csv",
delimiter=",",
encoding=None,
dtype=None,
names=True,
case_sensitive="lower",
)
rtc_tools_conv_acc_upwind_record = np.genfromtxt(
output_dir / "timeseries_export_saint_venant_upwind.csv",
delimiter=",",
encoding=None,
dtype=None,
names=True,
case_sensitive="lower",
)
hec_ras_record = np.genfromtxt(
output_dir / "HEC-RAS_export.csv",
delimiter=",",
encoding=None,
dtype=None,
names=True,
case_sensitive="lower",
)
hec_ras_record = np.recfromcsv(output_dir / "HEC-RAS_export.csv", encoding=None)

# Get times as datetime objects
times = [datetime.strptime(x, "%Y-%m-%d %H:%M:%S") for x in rtc_tools_record["time"]]
Expand Down
Loading