-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Sort init import #10801
Sort init import #10801
Conversation
@@ -2170,7 +2166,7 @@ | |||
TFLxmertPreTrainedModel, | |||
TFLxmertVisualFeatureEncoder, | |||
) | |||
from .models.marian import TFMarian, TFMarianMTModel | |||
from .models.marian import TFMarianModel, TFMarianMTModel |
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.
Completely unrelated to this PR, renamed that object to its proper name.
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.
Nice catch!
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.
Very nice! LGTM
@@ -2170,7 +2166,7 @@ | |||
TFLxmertPreTrainedModel, | |||
TFLxmertVisualFeatureEncoder, | |||
) | |||
from .models.marian import TFMarian, TFMarianMTModel | |||
from .models.marian import TFMarianModel, TFMarianMTModel |
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.
Nice catch!
Makefile
Outdated
python utils/style_doc.py src/transformers docs/source --max_len 119 | ||
python utils/style_doc.py src/transformers docs/source --max_len 119 --check_only |
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.
If I'm not mistaken, this prevents your style_doc.py
to do changes when used with make fixup
, is that voluntary?
python utils/class_mapping_update.py | ||
|
||
# this target runs checks on all files | ||
quality: | ||
black --check $(check_dirs) | ||
isort --check-only $(check_dirs) | ||
python utils/custom_init_isort.py --check_only |
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.
I would put this in the extra_quality_checks
too so that it runs with make fixup
Co-authored-by: Lysandre Debut <lysandre@huggingface.co>
To address your comments on the To have |
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.
Your changes LGTM. I agree with you that @stas00's review would be welcome before we merge.
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.
LGTM
Added another small tweak suggestion
Makefile
Outdated
python utils/check_copies.py | ||
python utils/check_table.py | ||
python utils/check_dummies.py | ||
python utils/check_repo.py | ||
python utils/style_doc.py src/transformers docs/source --max_len 119 | ||
python utils/class_mapping_update.py |
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.
should we create a new target for all the auto-generation items so it's loud-n-clear? It'd be something like:
autogenerate_code: deps_table_update
python utils/class_mapping_update.py
as these aren't style or quality
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.
Oh I hadn't realized class_mapping_update
was writing things. It should also disappear from make quality
then to go with the others in extra_style_checks
.
For me:
make fixup
-> applies the styling patches and checks everything passes quickly
make style
-> applying styling patches and other auto-generated code
make quality
-> only checks, does not write anything
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.
I only ever use make fixup
- the initial design was that fixup
= style+quality
on only modified files.
So it was created before we added 2 items that generated code, so if others prefer the quick version then fixup
should include the autogenerate target too.
Actually, is there is a situation where fixup
won't do the right thing already? When does one need to run the full make style
?
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.
class_mapping_update
doesn't do anything if the relevant file hasn't changed so it's blazingly fast
we can do the same for deps_table_update
so it'd be instant 99% of the time, as currently it always runs.
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.
Yes fixup
is style+quality
on only modified files. My problem is that some processes that modify files have been added to extra-quality-checks
which is run by quality
on top of fixup
. So fixup
runs extra-quality-checks
as well as extra-styling-checks
to do both, I don't want to change that part.
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.
See latest version for my proposal:
extra-quality-checks
common processes for quality and fixup, checks that are fast or need to run on all files, not changing any fileextra-style-checks
common processes for style and fixup, checks that are fast or need to run on all files, changing files if necessarystyle
style all files + other checks that are "writing" the right thingquality
check all files + other checks (in check only mode)fixup
same asstyle
+quality
but only on modified files.
* Initial script * Add script to properly sort imports in init. * Add to the CI * Update utils/custom_init_isort.py Co-authored-by: Lysandre Debut <lysandre@huggingface.co> * Separate scripts that change content from quality * Move class_mapping_update to style_checks Co-authored-by: Lysandre Debut <lysandre@huggingface.co>
What does this PR do?
Not a high-priority item but I get bored at nights and I like writing those kinds of scripts 😅
So this PR adds a script to properly sort the import inside
_import_structure
because people have been absolutely ruthless and putting their objects in any kind of random order. That's not very feng-shui so I'm bringing back harmony by having the same sort as isort applied to all__init__
that contain an_import_structure
.