Skip to content

docs: clarify src_paths root semantics - #2709

Closed
ump45nose wants to merge 1 commit into
PyCQA:mainfrom
ump45nose:c03
Closed

ump45nose wants to merge 1 commit into
PyCQA:mainfrom
ump45nose:c03

Conversation

@ump45nose

Copy link
Copy Markdown

Summary

Clarifies the semantics of the src_paths option in the configuration reference, as requested in #2365.

The previous description ("Add an explicitly defined source path (modules within src paths have their imports automatically categorized as first_party)") does not say how a path matches, which leaves three things ambiguous:

  1. Each entry is a root directory, not a prefix. With src_paths = src, an import is first party only when the module or package behind it lives directly inside src/. src/py_compile is first party; src itself is not.
  2. Setting the option replaces the built-in defaults instead of extending them. When src_paths is unset, isort silently uses both <project root>/src and the project root. Declaring only src therefore stops a flat ./package layout from being classified as first party, which is surprising for anyone who adds the option expecting it to be additive.
  3. Relative entries resolve against the config file that declares them (or the working directory on the CLI), and globs are expanded from there.

The new text also documents the one exception to point 1: a root that shares its name with the imported module. With src_paths = src, import src is still first party rather than a package nested inside src.

Related issue

Closes #2365

Changes

docs/configuration/options.md — extended the "Src Paths" section. Docs-only change, no behaviour is altered.

Verification

I verified each documented claim against the actual classifier instead of relying on the issue description, using isort.place.module() against a fixture tree (src/pkg, src/other, rootpkg):

src_paths unset (falls back to src/ + project root):
   pkg        -> FIRSTPARTY
   pkg.mod    -> FIRSTPARTY
   rootpkg    -> FIRSTPARTY
   src        -> FIRSTPARTY

src_paths = ['src']:
   pkg        -> FIRSTPARTY
   rootpkg    -> THIRDPARTY     <-- flat layout is lost, as documented
   src        -> FIRSTPARTY     <-- the name-sharing exception

src_paths = ['src', '.']:
   pkg        -> FIRSTPARTY
   rootpkg    -> FIRSTPARTY     <-- both layouts work

Environment: Python 3.13, isort at branch main (d93953f).

Because this is a prose-only edit to a generated reference page, there is no test to add or run. I did not regenerate docs/configuration/options.md with scripts/build_config_option_docs.py: regenerating at the current HEAD already produces a ~150-line unrelated diff, because the committed page has drifted from its generator (backticked CLI flags, a relative ./profiles.md link, an updated skip default). I kept this PR focused on the wording and left that pre-existing drift alone; the clarification should also be mirrored into the generator's description_mapping whenever that drift is fixed, otherwise it will be lost on the next regeneration.

@DanielNoord DanielNoord closed this Oct 5, 2026
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 this pull request may close these issues.

src_path semantics needs clarification

2 participants