-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add ruff #100
base: main
Are you sure you want to change the base?
Add ruff #100
Conversation
fix: pyproject.toml
@@ -103,7 +100,9 @@ jobs: | |||
- name: Install Python dependencies | |||
run: | | |||
python -m pip install --upgrade pip | |||
pip install -r requirements.txt | |||
mkdir _static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this here to avoid the warning?
WARNING: html_static_path entry '_static' does not exist
[tool.ruff.lint] | ||
# Enable checks for Pycodestyle, Pyflakes, Bugbear, Docstrings and Import sorting | ||
select = ["E", "F", "B", "D", "I"] | ||
ignore = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD all these errors occur, currently disabled so we could merge the current state.
As proposed we can enable and fix them one by one in step 3. Some are easy to auto-fix
@@ -0,0 +1,56 @@ | |||
"""Extract the names int the [project.optional-dependencies] section of a pyproject.toml file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where to put the script. Let me know whether you prefer it somewhere else.
I don't like the need for such a script in the 1st place but there seems to be no generic way like pip install .[all]
when using pyproject.toml
. Using this scripts avoids repeating dependencies which would be hard to maintain in the long run, e.g.
pip install .[mysql,knx,dmx,midi,mqtt,pulse,telegram,file_persistence]
So for me the script is the better choice.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #100 +/- ##
==========================================
- Coverage 83.26% 81.84% -1.42%
==========================================
Files 42 42
Lines 5636 5636
Branches 768 768
==========================================
- Hits 4693 4613 -80
- Misses 741 823 +82
+ Partials 202 200 -2 ☔ View full report in Codecov by Sentry. |
import mido | ||
import shc.interfaces.midi | ||
from shc.datatypes import RangeUInt8 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to move the import here.
Avoids the pip uninstall python-rtmidi
to skip those tests. Not sure whether this is really the best logic as this happens quietly and might not be noticed if skipped accidently.
@@ -18,6 +18,7 @@ | |||
mido_backend_error = str(e) | |||
|
|||
|
|||
@unittest.skipUnless(mido_backend_available, "mido MIDI backend is not available: {}".format(mido_backend_error)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is new to skip this test as well. Other @unittest.skipUnless
changes is a typo fix only ("available").
|
||
def test_midi(self): | ||
import shc.interfaces.midi # noqa: F401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to remove this one. Well it is tested in test_midi.py
which is skipped in the pipeline.
Is my current proposal sufficient or do you feel like we need this test here? Then we rollback to your approach and install midi
but uninstall python-rtmidi
which is kind of confusing to me. Maybe we should split the dependency then.
As for the failed code coverage report, I suggest we fix it once we have the test strategy for the _rtmidi.SystemError: MidiInAlsa::initialize: error creating ALSA sequencer client object. |
Hi @mhthies, don't want to push you (seriously not). Just want to make sure we're on the same page. I would like you to make a 1st review and provide some feedback. I know not all checks are passing right now but the fix would depend on the result of our discussion. Feel assigned as reviewer to this PR 😉 No rush, I'm also quite busy right now. |
Sorry, @jo47011, I'm currently quite busy with work, christmas preparations and another freetime project which is due in the first week of January, so I couldn't take the time for an appropriate review of the changes, yet. However, thanks already for all the work you put into this PR! :) Regarding the configuration of ruff's formatting and linting, I'd like to stay as close as possible to the default configuration of the linting tools, unless there are single rules that really annoy me – which I have to check. On the other hand, I'd also like to stick to the Python default-provided tools like Setuptools, to avoid additional dependencies, unless they are able to solve actual problems that otherwise require workarounds. |
Replace all the original project setup, linting, etc. with ruff.
Taking it step by step. We could have a PR for each step to simplify code reading and discussions.
Ruff: Introduce ruff.
We disable all linting errors that we get so we can focus on the project setup 1st.
Formatting: We agree on some parameters, see
[tool.ruff.format]
inpyproject.toml
. Then we reformat the code (replacesblack
):ruff format .
Then we can also add a format check to the build workflow.
Linting: We agree on which parameter we want to enable and which we want to ignore in future, see
[tool.ruff.lint]
inpyproject.toml
, e.g.;invoke like this:
ruff check --fix .
Setuptools
toHatchling
further down the road. Provides for some more advanced environment management and other nice features.BTW I think there was a bug in your previous setup.cfg:
I fixed it in the
pyproject.toml
. If it was intentional we need to change it back.We should also discuss the skipping of the tests in
test_midi.py
. There where skipped becausepython-rtmidi
was not installed butmidi
was. Does this make sense? I changed the logic slightly and now catch the exception as well if modulemidi
is not loaded. See my comments in the code for details.