Skip to content

Package not identified as first party when name has a dash #16712

@bepuca

Description

@bepuca

Summary

First party package is not identified as such when sorting imports if it has dashes in the name and the code is parallel to the actual package folder which has an underscore in the name. For instance, on tests files.

(unsure if by design or a bug)

Context

  • I am using uv workspaces.
  • Some of the packages have dashes in their names.
  • I am using ruff for sorting imports
  • A minimal folder structure
packages/
├── pyproject.toml
└── example-package/
    ├── src/
    │   └── example_package/
    │       ├── __init__.py
    │       └── dummy.py
    ├── tests/
    │   └── test_dummy.py
    └── pyproject.toml

pyproject.toml

[project]
name = "tmp-iywsagbejg"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
    "example_package",
]

[tool.uv.workspace]
members = ["packages/*"]

[tool.uv.sources]
example_package = { workspace = true }

[tool.ruff]
lint.select = ["I"]

example-package/pyproject.toml

[project]
name = "example-package"
version = "0.1.0"
description = "Example package"
dependencies = [
    "requests",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

dummy.py

import requests

import example_package


def myfun():
    example_package.main()
    print(requests.__version__)
    return 42

test_dummy.py

import example_package
import requests


def test_myfun():
    print(example_package.dummy.myfun(), requests.__version__)

Expected

When I run:

vx ruff check --fix .

I would expect that example-package is always identified as first party when sorting imports and so order of imports is consistent.

Actual behavior

It is only detected as first party if inside a folder with underscores and not dashes in the name. Thus, for tests (if I want them to live outside the src folder) the imports are sorted differently. (see example files above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    isortRelated to import sortingquestionAsking for support or clarificationuvIncompatibility between Ruff and uv

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions