Skip to content

Implement #2750: Run black+isort on gen_exports results - #2759

Merged
jakkdl merged 11 commits into
python-trio:masterfrom
TeamSpen210:gen_export-run-linters
Aug 26, 2023
Merged

jakkdl merged 11 commits into
python-trio:masterfrom
TeamSpen210:gen_export-run-linters

Conversation

@TeamSpen210

Copy link
Copy Markdown
Contributor

This makes gen_exports run both linters on the generated files, improving the formatting a little.

I ran black via subprocess because its API doesn't provide a nice way to fetch configuration from pyproject.toml etc to maintain consistency, while also processing an in-memory string. Still doesn't remove the redundant parentheses, but oh well.

@TeamSpen210
TeamSpen210 requested a review from jakkdl August 17, 2023 08:13
@codecov

codecov Bot commented Aug 17, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #2759 (56cfafd) into master (0c108f9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2759   +/-   ##
=======================================
  Coverage   98.94%   98.94%           
=======================================
  Files         113      113           
  Lines       16843    16870   +27     
  Branches     3036     3041    +5     
=======================================
+ Hits        16665    16692   +27     
  Misses        123      123           
  Partials       55       55           
Files Changed Coverage Δ
trio/_tests/tools/test_gen_exports.py 100.00% <100.00%> (ø)
trio/_tools/gen_exports.py 100.00% <100.00%> (ø)

@jakkdl jakkdl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great!

@TeamSpen210

Copy link
Copy Markdown
Contributor Author

Adding this caused all the pypy tests to fail, since we don't even install black/isort there. I just skipped the tests there, the module is an internal tool that only needs to run on one version.

@jakkdl

jakkdl commented Aug 17, 2023 •

Copy link
Copy Markdown
Member

needs pragma: no cover on the exceptions

@TeamSpen210

Copy link
Copy Markdown
Contributor Author

Hmm actually I could just add tests for those cases - mock out isort to produce an error, send in an invalid file to make black fail.

@jakkdl

jakkdl commented Aug 17, 2023

Copy link
Copy Markdown
Member

Hmm actually I could just add tests for those cases - mock out isort to produce an error, send in an invalid file to make black fail.

sure .. but do we need thorough tests on an internal code generation tool? :p

@A5rocks A5rocks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couple of nitpicks, looks good otherwise.

Comment thread trio/_tools/gen_exports.py Resolved
Comment thread trio/_tools/gen_exports.py Resolved
Comment on lines +137 to +138
traceback.print_exception(type(exc), exc, exc.__traceback__)
sys.exit(1)

@A5rocks A5rocks Aug 19, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why can't we re-raise? Or even raise RuntimeError("Failed to run isort!") from exc!

(same for black)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think that results in a nonzero exit code, I wanted to make sure CI etc fails.

@A5rocks A5rocks Aug 19, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FWIW it does, it seems!

a5@hostname:/tmp$ python3 t.py
Traceback (most recent call last):
  File "t.py", line 1, in <module>
    raise Exception("hi!")
Exception: hi!
a5@hostname:/tmp$ echo $?
1

(at least on my Ubuntu WSL env...)

@A5rocks

A5rocks commented Aug 19, 2023

Copy link
Copy Markdown
Contributor

builds.sr.ht is back!?!

@jakkdl

jakkdl commented Aug 25, 2023

Copy link
Copy Markdown
Member

I'll merge this unless somebody thinks otherwise, re-raising the exception instead of printing traceback seems like a minor enough problem not worth stalling over

@jakkdl
jakkdl merged commit 4c53941 into python-trio:master Aug 26, 2023
@TeamSpen210
TeamSpen210 deleted the gen_export-run-linters branch August 26, 2023 23:26
@jakkdl jakkdl mentioned this pull request Sep 13, 2023
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.

3 participants