PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.53k stars 583 forks source link

1st party and 3rd party #2158

Closed 64rl0 closed 4 months ago

64rl0 commented 1 year ago

I have a project directory structure as follows:

Project_Name
|-project_name
|--__init__.py
|--file1.py
|--file2.py
|--main.py
|-tests
|-docs
|-pyproject.toml

so my isort config is in the root Project_Name/pyproject.toml and the .py files are in the subdir Project_Name/project_name/xxx.py

If I import as follows, from let's say main.py

from file1 import xyz
from file2 import abc

isort will classify file1 and file2 as third party imports as opposed to first party which are files of the same application.

If I drop the pyproject.toml into the Project_Name/project_name/, among the .py files, then it works and file1 and file2 are now addressed as first party imports.

I tried adding this to the config file known_first_party = ['project_name'] but even with that file1 and file2 are still considered as third party imports. Is there a way to leave the pyproject.toml in the root dir and still get file1 and file2 identified as first party?

64rl0 commented 1 year ago

Here is the solution: src_paths = ['project_name']