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

Move ruff, coverage, and pytest configs to pyproject.toml #3557

Merged
merged 12 commits into from
Nov 27, 2023

Conversation

Saransh-cpp
Copy link
Member

Description

I've left cibuildwheel as of now as keeping its config in the CI files seems more accessible.

Fixes #3478

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@kratman
Copy link
Contributor

kratman commented Nov 25, 2023

Missed this when I reviewed, but I think the errors are because "--rcfile=.coveragerc" needs to be removed from the noxfile for coverage

@agriyakhetarpal
Copy link
Member

Also, the tests for the example notebooks are failing too. I think the pytest meta path finder is looking for all installable packages in the root directory, and the git-cloned pybind11 is also regarded as one. We should be able to exclude that path for the time being until pybind11 is added as a build-time dependency (#3480).

pyproject.toml Outdated
@@ -174,6 +174,8 @@ pybamm = [

[tool.setuptools.packages.find]
include = ["pybamm", "pybamm.*"]
# TODO: remove once https://github.com/pybamm-team/PyBaMM/issues/3480 is resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but do we have and process for periodically checking TODOs to make sure we are taking care of them over time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a good idea to add a workflow to do that. I don't remember the name exactly, but there is a pre-commit hook too that can check for # TODO: and # FIXME: comments.

Copy link
Member

@agriyakhetarpal agriyakhetarpal Nov 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this # TODO: comment in specific should not be added imo, I remember that when I worked on this part of the configuration it was also trying to install the tests, examples, and the benchmarks folders treating them as packages, because they are not namespace packages. Including just pybamm and the modules under it is the most reasonable solution; we should look to configure this from pytest instead.

pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated
Comment on lines 228 to 242
[tool.pytest]
# Use pytest-xdist to run tests in parallel by default, exit with
# error if not installed
required_plugins = [
"pytest-xdist",
]
addopts = [
"-nauto",
"-v",
]
testpaths = [
"docs/source/examples/",
]
console_output_style = "progress"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the norecursedirs configuration value should do it: https://docs.pytest.org/en/7.1.x/reference/reference.html#confval-norecursedirs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This surprisingly did not work (it should have according to the docs). Ignoring pybind11 in addopts works for me locally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it failed again on the latest commit with addopts, up to you if you want to try another option or wait for #3480 to be completed – I am almost done!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out, this wasn't a pytest+pybind11 issue. I was specifying pytest's configuration under [tool.pytest], but it should have been [tool.pytest.ini_options].

Saransh-cpp and others added 3 commits November 26, 2023 00:21
Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com>
Comment on lines +184 to +200
# "B", # flake8-bugbear
# "I", # isort
# "ARG", # flake8-unused-arguments
# "C4", # flake8-comprehensions
# "ICN", # flake8-import-conventions
# "ISC", # flake8-implicit-str-concat
# "PGH", # pygrep-hooks
# "PIE", # flake8-pie
# "PL", # pylint
# "PT", # flake8-pytest-style
# "PTH", # flake8-use-pathlib
# "RET", # flake8-return
"RUF", # Ruff-specific
# "SIM", # flake8-simplify
# "T20", # flake8-print
# "UP", # pyupgrade
"YTT", # flake8-2020
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do want to add all these rules but this PR will blow up with formatting changes if I enable all of them at once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always just review the config stuff then enable the other checks right before a final review. I do that sometimes on other projects.

Copy link
Member

@agriyakhetarpal agriyakhetarpal Nov 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we leave them for a follow-up PR?

We can always just review the config stuff then enable the other checks right before a final review. I do that sometimes on other projects.

That would work too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was figuring that we should do it all at once since we suppress these changes in git blame.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think follow-up PRs would be best here. That would also ensure that we have everyone's consensus on adding thee individual rule. For instance, we used to have isort in pybamm somewhere in the past but then it was removed on everyone's consensus. I'll open an issue for this once the PR is merged.

Copy link

codecov bot commented Nov 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2ee8da2) 99.58% compared to head (5322895) 99.58%.
Report is 124 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3557   +/-   ##
========================================
  Coverage    99.58%   99.58%           
========================================
  Files          256      256           
  Lines        20126    20131    +5     
========================================
+ Hits         20043    20048    +5     
  Misses          83       83           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thanks, @Saransh-cpp!

Copy link
Sponsor Member

@brosaplanella brosaplanella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@Saransh-cpp Saransh-cpp merged commit c86f8fe into pybamm-team:develop Nov 27, 2023
34 of 35 checks passed
@Saransh-cpp Saransh-cpp deleted the ruff-config branch November 27, 2023 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move all the extra configurations to pyproject.toml
4 participants