Skip to content
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

Different third vs first party behaviour in isort 5 (vs isort 4) #1467

Closed
AlexandreYang opened this issue Sep 8, 2020 · 3 comments
Closed

Comments

@AlexandreYang
Copy link
Contributor

AlexandreYang commented Sep 8, 2020

Hi,

It seems the behaviour changed for isort 5 related to first party, third party sections.

folder structure

$ tree .
.
├── bar/
└── code.py

code.py output for isort 5.5.1:

cmd $ isort code.py

import json

import foo

import bar

Notice the extra line between import foo and import bar

code.py output with isort 4.3.21:

cmd $ isort code.py

import json

import bar
import foo

Real life case

This this diff linked here represent the code change before (isort 4) and after using isort 5:
DataDog/integrations-core@518d8b7

@timothycrosley
Copy link
Member

Hi @AlexandreYang thanks for reporting this issue!

I believe for this exact issue in the datadog repository, you can achieve the behaviour you want simply by telling isort not to automatically try to detect based on src_path. This can be achieved by telling isort to use an empty set of src_paths in your config:

[tool.isort]
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = 'datadog_checks'
src_paths = ''

Ideally, the improvements planned to module placement for 5.6.0 would enable this to mostly work automatically, but even so if you simply want everything under datadog_checks to be considered first_party, I believe the above configuration would be preferred as it would perform better and be more explicit.

Side note: What is the best way to run isort across the repository to be consistent with how it is done in your CI? I would love to add this project to the isort integration test suite (https://github.com/PyCQA/isort/blob/develop/tests/integration/test_projects_using_isort.py#L1) so that the isort project can assure that as we make changes they don't introduce regressions.

Thanks!

~Timothy

@AlexandreYang
Copy link
Contributor Author

AlexandreYang commented Sep 9, 2020

Thanks @timothycrosley

Nice using src_paths seems to works: DataDog/integrations-core@4d7743e

It's nice to test isort against projects using it. I can make a PR to add https://github.com/DataDog/integrations-core to https://github.com/PyCQA/isort/blob/develop/tests/integration/test_projects_using_isort.py#L1

@AlexandreYang
Copy link
Contributor Author

Add Datadog integrations-core to projects to test against #1473

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

No branches or pull requests

2 participants