Skip to content

Conversation

@DrPaulSharp
Copy link
Contributor

Closes #657

The pre-commit hook provided here introduces the same functionality to SasModels as SasView/sasview#3573 does to SasView.

In addition, the recurrent linting errors in the TwoYukawa code are resolved here. Once this PR is merged, any branch based on main from this point will not see further corrections to this code if it has not been modified.

@llimeht
Copy link
Contributor

llimeht commented Oct 16, 2025

Given that merging #648 has left us with broken CI, other work on sasmodels is now blocked (see #679, #680). To fix that, either need to land this PR to reformat the offending code or back out #655. Do we have a timeline for one or other?

@DrPaulSharp
Copy link
Contributor Author

Given that merging #648 has left us with broken CI, other work on sasmodels is now blocked (see #679, #680). To fix that, either need to land this PR to reformat the offending code or back out #655. Do we have a timeline for one or other?

I've asked that this PR be reviewed as a priority, but nobody has been available to review it recently. My preference is to get this PR merged as soon as possible.

@butlerpd butlerpd requested review from rozyczko and removed request for pkienzle October 17, 2025 13:40
Copy link
Member

@rozyczko rozyczko left a comment

Choose a reason for hiding this comment

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

Changes look good, minor questions raised for consideration.

# Run the linter, applying any available fixes
- id: ruff-check
stages: [ pre-commit, pre-push ]
args: [ --fix-only ]
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we just report the issue, rather than try fixing them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The --fix-only flag restricts ruff to checking only for linting errors where it has an automatic fix available. If any are found, they are applied, and the commit is stopped. The developer can then check what has been changed by those automatic fixes, and then proceed with the commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that these fixes will be applied in the CI if they are not done locally.

# Run the linter, applying any available fixes
- id: ruff-check
stages: [ pre-commit, pre-push ]
args: [ --fix-only ]
Copy link
Member

Choose a reason for hiding this comment

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

If we ARE fixing then maybe it makes sense to add formatting as well?

- id: ruff-format
  stages: [ pre-commit, pre-push ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given the current state of the code, adding formatting would result in a large number of changes, substantially increasing the burden for developers and PR reviewers. I am keen to introduce formatting at a later stage but this will require work done to go through the codebase, and applying formatting to what is there already.

columnize
matplotlib
numpy
pre-commit
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we also add this dependency in pyproject.toml?

Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of comments on this one:

  • while it was once murky, PEP517 (and friends) now give very clear separation between:
    • "build-system requires" (build-dependencies, what is required to build the wheel),
    • run-time dependencies (what is needed to import and use the module), and
    • tools that are useful for the developer but unneeded at build-time or run-time.
  • tools like pytest, ruff are in that 3rd category for developer tools: they are neither required for the build process nor at runtime.
  • as part of that separation,
    • build-dependencies must be in the pyproject.toml [build-system]requires entry.
    • runtime-dependencies must be in the pyproject.toml [project]dependencies, but that can be broken out (as sasmodels does) as a dynamic field into the build_tools/requirements.txt file (and some other files in the same directory for optional runtime dependencies for additional features).
    • other tools useful for developers don't have a defined place, but requirements-dev.txt is common (and it could reference the other files to include them; note that hatch-requirements-txt doesn't follow -r directives, but requirements-dev.txt is never used by hatch and only via pip).

So...

  • pre-commit is not a requirement to build the wheel: it's not needed for python -m build but is a local tool that helps developers; it shouldn't be in pyproject.toml
  • pre-commit is not needed to use the sasmodels module: it's not needed for import sasmodels; ... to work; it shouldn't be in requirements.txt

(I also doubt that siphash24 is a runtime dependency of sasmodels and it should also come out of that file)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given these comments, I have introduces a requirements-dev.txt and added pre-commit to it. I have also added the line dev = [ "build_tools/requirements-dev.txt" ] to the [tool.hatch.metadata.hooks.requirements_txt.optional-dependencies] section of the pyproject.toml, as in SasView. I will leave the decision about siphash24 to someone else.

- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
version: "latest"
Copy link
Member

Choose a reason for hiding this comment

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

According to https://github.com/astral-sh/ruff-action , latest is the default. This directive might not be necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

Without that there, we'd get an unwanted annotation on every CI run that it's using the latest version, that might not be what we want, and we should specify a version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @llimeht stated, in spite of it being the default, this proved to be an issue in the SasView repo, see SasView/sasview#3605 and SasView/sasview#3608

@DrPaulSharp DrPaulSharp merged commit 430b74f into master Oct 20, 2025
20 checks passed
@DrPaulSharp DrPaulSharp deleted the local-hooks branch October 20, 2025 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a pre-commit hook for git so that ruff is run before committing.

4 participants