Skip to content

Change isort config and turn on isort in CI #4288

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

Closed
JelleZijlstra opened this issue Jun 28, 2020 · 1 comment · Fixed by #4290
Closed

Change isort config and turn on isort in CI #4288

JelleZijlstra opened this issue Jun 28, 2020 · 1 comment · Fixed by #4290

Comments

@JelleZijlstra
Copy link
Member

While trying to land isort in CI in #3329, I discovered that the behavior of our current isort config depends on whether some modules (e.g., typing_extensions) are installed in the runtime environment where isort is run. This is bad because it means that contributors running isort locally may get different behavior depending on what libraries they happen to have installed in their local environment.

I'm guessing that this has to do with isort's behavior of sorting imports into "sections" of standard library, third-party, and first-party imports. Looking at https://github.com/timothycrosley/isort/wiki/isort-Settings, maybe we need to set default_section? Perhaps we should also mark typing-extensions and _typeshed as "standard library" because in the context of typeshed, they essentially are part of the standard library.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jun 28, 2020

The two options I can see are:

  • Set virtual_env to some random folder. This should hopefully guarantee that isort isn't dependent on contributors' environments.
  • Set default_section to THIRDPARTY, so that whether or not isort detects a library the resulting section is hopefully the same. This might have slightly worse ordering though?

I'm in favour of explicitly marking those as "standard library".

JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue Jun 29, 2020
Fixes python#4288.

- Default imports to THIRD_PARTY, so in effect we merge the FIRST_PARTY and THIRD_PARTY stubs. This means
  import order is no longer affected by whether typing_extensions is installed locally.
- Treat typing_extensions and _typeshed as standard library modules.

Note that isort master is very different from the latest release; we'll have to do something
different if and when the next isort release comes out.
hauntsaninja pushed a commit that referenced this issue Jun 29, 2020
Fixes #4288.

- Default imports to THIRD_PARTY, so in effect we merge the FIRST_PARTY and THIRD_PARTY stubs. This means import order is no longer affected by whether typing_extensions is installed locally.
- Treat typing_extensions, _typeshed and some others as standard library modules.

Note that isort master is very different from the latest release; we'll have to do something
different if and when the next isort release comes out.
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 a pull request may close this issue.

2 participants