PyCQA / PyCQA/isort

Namespaced packages in a repo with a shared `.isort.cfg` are misidentified as third-party

Open
#1,704 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
7k
Forks
687
Avg merge
4h 56m
Merged PRs (30d)
2

Description

Consider a git repo that contains two namespaced packages, my.first.library and my.second.library, with a single shared .isort.cfg:

root
  .git/
  .isort.cfg
  my_first_library/
    my/
      first/
        library/
          __init__.py
  my_second_library/
    my/
      second/
        library/
          __init__.py

The fact of containing two libraries is actually incidental; AFAICT the issue is the extra directory in there. But probably the most common use case for this would be a monorepo containing multiple libraries.

In this case, running isort . inside my_first_library/ will erroneously identify imports from my.first.library as third-party. The same is true in my_second_library/ with imports from my.second.library. Copying .isort.cfg into my_first_library/ is sufficient to solve this, but in our case we have a monorepo with dozens and dozens of python libraries and would rather not duplicate our .isort.cfg if we don't have to. A symlink also works, but we're hoping for a built-in solution.

I know this is a serious edge case, but is there any way to give isort a hint about where the root directory of the package is to help it identify first-party packages?

Note that this works fine for non-namespaced packages, so it has the feel of a bug, but it's also probably low priority.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported layout by running isort . from each library directory with the shared .isort.cfg; then trace the package and configuration-root detection used for first-party classification. Done means namespaced imports are recognized as first-party without duplicating or symlinking the configuration, while non-namespaced behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.