Conversation
| [tool.isort] | ||
| profile = "black" |
There was a problem hiding this comment.
I've used isort and quite like it, but I've found different isort versions to apply the sort styles rather inconsistently (specifically the standard lib/firstparty/thirdparty sections, see https://pycqa.github.io/isort/#custom-sections-and-ordering). Does this "black" profile keep things simple?
There was a problem hiding this comment.
Does this "black" profile keep things simple?
No, profile = "black" is equivalent to the following settings:
multi_line_output: 3
include_trailing_comma: True
force_grid_wrap: 0
use_parentheses: True
ensure_newline_before_comments: True
line_length: 88
As for section orders, the default order (https://pycqa.github.io/isort/docs/configuration/options/#sections) is:
('FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER')
Do you mean the default values change in different isort versions?
There was a problem hiding this comment.
I think there was a point where they separated well known third-party libaries (e.g. numpy and pandas) from other third-party libraries. Maybe that has changed now with newer isort versions, but I'm not too sure.
Do you think we should add other configuration options? I'm looking at xarray's at pydata/xarray#4518 and they have some extra ones besides black.
There was a problem hiding this comment.
OK, I will look at these options later.
There was a problem hiding this comment.
Most of our examples import some of the four packages: pygmt, numpy, pandas and xarray.
Currently, isort sorts them like
import numpy as np
import pandas as pd
import xarray as xr
import pygmt
because numpy, pandas, and xarray are known third-party packages, and pygmt is first-party package (not sure if I understand it correctly).
I don't think I like it. We can add options:
known_third_party = "pygmt"
force_to_top = "pygmt
so that they will be sorted like:
import pygmt
import numpy as np
import pandas as pd
import xarray as xr
There was a problem hiding this comment.
After reading through all the isort options, I added the following ones to pyproject.toml, similar to pydata/xarray#4518:
skip_gitignore = true
force_to_top = "pygmt"
known_third_party = "pygmt"
the only exception is default_section = THIRDPARTY, as I don't understand what it is, and adding it doesn't change the codes at all.
There was a problem hiding this comment.
I have to remove force_to_top, otherwise pylint will complain.
Description of proposed changes
This PR adds
isortto automatically sort imports.Notes:
profile = "black"is added topyproject.tomlfor compatibility betweenblackandisort, which requires isort>=5pylintalso depends onisort. Thus when we install pylint,isortis already installed.References:
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Notes
/formatin the first line of a comment to lint the code automatically