Skip to content

FIRSTPARTY/THIRDPARTY detection when --src is specified #2429

@felixfontein

Description

@felixfontein

I noticed that isort reacts quite unreliable, and I'm wondering what to do about it, resp. whether I'm doing something wrong, or whether the FIRSTPARTY/THIRDPARTY detection in isort needs improvements.

More precisely, assume I have the following hierarchy:

parent
+- foo
   +- bar
      +- baz.py

where parent/foo/bar/baz.py looks like this:

import os

import bar
import bar.baz
import baz
import foo.baz
import parent

import foo
import foo.bar
import foo.bar.baz

import .baz as bz

parent is the checkout of my project (whose name happens to be a valid Python identifier), and my module is foo.bar.baz.

Now I'm in parent/, and run isort --diff -v --src . foo/. isort now treats parent as FIRSTPARTY. The same happens if I run isort --diff -v --src . foo/bar/baz.py. This is not what I want. (In my case, parent happens to be the name of another third-party Python module I'm importing.)

Maybe I have to use --src foo/ instead of --src .? Well, if I run isort --diff -v --src foo foo/bar/baz.py, isort no longer considers parent as FIRSTPARTY, but it does consider bar and bar.baz as FIRSTPARTY.

Now if I rename the checkout parent to par.ent (which is no longer a valid Python identifier), isort --diff -v --src . foo/ suddenly does what I want.

Is this intentional? If yes, why? Do I have to make sure that isort's --src parameter points to a directory whose name is not a valid Python identifier?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions