Skip to content

Add project-level default configuration for black to pyproject.toml#3660

Merged
blnicho merged 3 commits intoPyomo:mainfrom
sadavis1:pyproject-toml-black
Jul 16, 2025
Merged

Add project-level default configuration for black to pyproject.toml#3660
blnicho merged 3 commits intoPyomo:mainfrom
sadavis1:pyproject-toml-black

Conversation

@sadavis1
Copy link
Copy Markdown
Contributor

Fixes # (n/a)

Summary/Motivation:

Make it easier to use black and harder to accidentally mess it up

Changes proposed in this PR:

Add [tool.black] section to pyproject.toml. This will cause a command-line invocation like black . to correctly use Pyomo's black options without needing to set them yourself.

Notes:

  • Black walks up the filesystem looking for this file starting from the file being formatted, so it will still work if you run it from an unrelated working directory
  • You can also set the intended python version, but it infers this anyways based on the requires-python field under [project] above.
  • The difference between exclude and extend-exclude is that with extend-exclude it also excludes gitignored files (which are the default excluded files). This is meaningful because some of our tests generate python code and leave the gitignored, non-black-compliant files behind.
  • It's still possible to mess this up if you set conflicting command-line flags, as they override this. This is most likely to happen if you are using an ide integration and you set a conflicting option there (as this is almost certainly implemented by changing the flags).

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@jsiirola
Copy link
Copy Markdown
Member

This is great. One question: does it also mean that we can remove the command line options from the GHA testing workflows?

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.05%. Comparing base (10d6acc) to head (8f06322).
⚠️ Report is 957 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3660   +/-   ##
=======================================
  Coverage   89.05%   89.05%           
=======================================
  Files         890      890           
  Lines      102617   102617           
=======================================
+ Hits        91384    91386    +2     
+ Misses      11233    11231    -2     
Flag Coverage Δ
builders 26.64% <ø> (-0.02%) ⬇️
default 85.64% <ø> (?)
expensive 34.02% <ø> (?)
linux 86.79% <ø> (-2.02%) ⬇️
linux_other 86.79% <ø> (+0.01%) ⬆️
osx 83.08% <ø> (-0.02%) ⬇️
win 84.97% <ø> (ø)
win_other 84.97% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sadavis1
Copy link
Copy Markdown
Contributor Author

I tried on another branch and it looks like it works correctly. Should I add that to this PR too? I guess it would be redundant not to, but on the other hand there's no harm in being excessively verbose in a script.

@jsiirola
Copy link
Copy Markdown
Member

@sadavis1: yes: I think adding that to this PR makes sense. Leaving it in the driver scripts runs the risk of inconsistency (where someone later changes one and forgets to change the other).

@sadavis1
Copy link
Copy Markdown
Contributor Author

Sure. I'll also edit contribution_guide.rst in the docs so we don't instruct people to type more than they need to.

Copy link
Copy Markdown
Contributor

@mrmundt mrmundt left a comment

Choose a reason for hiding this comment

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

I love this, thank you!

@blnicho blnicho moved this from Todo to Reviewer Approved in August 2025 Release Jul 16, 2025
@blnicho blnicho merged commit 039023d into Pyomo:main Jul 16, 2025
35 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer Approved to Done in August 2025 Release Jul 16, 2025
@sadavis1 sadavis1 deleted the pyproject-toml-black branch July 16, 2025 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

5 participants