-
Notifications
You must be signed in to change notification settings - Fork 52
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
Better grouping of imports #13
Comments
isort has a lot of customization (see https://pycqa.github.io/isort/docs/configuration/custom_sections_and_ordering.html and https://github.com/PyCQA/isort/blob/main/isort/settings.py#L137). The more customization we would want to adopt, the more work this will be. One must also consider that we'd have to convert the isort functions to use the pyflyby internal classes representing imports and other Python code constructs. [time estimate: 50 hrs] |
Sounds good to proceed (sorry I missed that this was waiting for feedback) |
This add some test for what was requested in deshaw#13 and implemented in deshaw#263
A couple of notes following #287 as there was some issues with isort.:
I'm not sure this will work in practice, as from the top example shows: input
Output:
The developer means to have (numpy, scipy) in it's own group. If we do follow the logic proposed, then the output lexicographically ordered will be the following with "sympy" relagated into simple imports at the bottom.
There are also questions with respect to comments, do the comments separate two grouping import, or do they mark a single block. That is to say:
Should we
I'm inclined to go with the second and assume the second group of blank lines is a group separation in most case. |
So from reflexion and trying we can't So a blocks like
Will after reformat have blanks lines due to the
Thus we need the comment to apply to multiple blocks with blank lines. |
I'm guessing there might be a need to special case |
This tries to implement some of the rule of import sorting as requested in deshaw#13 using custom logic, This was originally fixed in deshaw#263 using isort, but reverted and re-requested as of deshaw#287
This tries to implement some of the rule of import sorting as requested in deshaw#13 using custom logic, This was originally fixed in deshaw#263 using isort, but reverted and re-requested as of deshaw#287
This tries to implement some of the rule of import sorting as requested in deshaw#13 using custom logic, This was originally fixed in deshaw#263 using isort, but reverted and re-requested as of deshaw#287
This tries to implement some of the rule of import sorting as requested in deshaw#13 using custom logic, This was originally fixed in deshaw#263 using isort, but reverted and re-requested as of deshaw#287
This tries to implement some of the rule of import sorting as requested in deshaw#13 using custom logic, This was originally fixed in deshaw#263 using isort, but reverted and re-requested as of deshaw#287
yes. Any further update on this PR? |
#329 added the I don't remember if it it unconditionally adds blank lines after future but will check. |
pyflyby makes imports nice when adding to an existing import line. E.g. if "from m1 import x" exists, and "from m1 import y" needs to be added, then it merges it into "from m1 import x, y".
Pyflyby also sorts import line within one "block".
Currently it considers a blank line to separate import blocks and doesn't merge such blocks.
However, code that's carelessly maintained tends to drift into states like this:
We should change the algorithm to automatically beautify this. Pyflyby has already trained people to ignore whatever's in the import stanza. So pyflyby should take greater ownership of it.
Proposal1.
We would get:
Proposal2.
Some people like to have pkg1 show up after all the other imports, because they work in pkg1, or have stdlib imports show up before all the other imports.
Add support for something like this:
In ~/.pyflyby/*.py:
__import_sections__ = [ ['os','sys'], '*', 'pkg1']
These proposals are not mutual exclusive.
Proposal1 is higher priority than Proposal2.
The text was updated successfully, but these errors were encountered: