Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pants doesn't detect sources roots unless root_pattern=["/"] #21700

Open
mnowotnik opened this issue Nov 29, 2024 · 4 comments
Open

Pants doesn't detect sources roots unless root_pattern=["/"] #21700

mnowotnik opened this issue Nov 29, 2024 · 4 comments
Labels

Comments

@mnowotnik
Copy link

Describe the bug
On MacOS root_pattern needs to be set to ["/"]. Any other value causes "No source root found for '.'" error.

Pants version
2.23.0

OS
MacOS

Additional info
/src/foo_lib/BUILD

python_sources(
    name="foo_lib",
    sources=["foo.py"],  # Include only source files
)

python_tests(
    name="foo_lib_tests",
    dependencies=[":foo_lib"],  # Test depends on the library
    sources=["test_foo.py"],    # Include only test files
)

/pants.toml

[GLOBAL]
pants_version = "2.23.0"
backend_packages = [
    "pants.backend.python",
    "pants.backend.docker",
    "pants.backend.shell",
    "pants.backend.experimental.python.lint.ruff.check"
]

[python]
interpreter_constraints = [">=3.7"]


[source]
root_patterns = ["/src"]

/BUILD

shell_sources(
    name="0",
)
python_sources(
    name="root",
)

image

Works without an issue if root_patterns = ["/"].

@mnowotnik mnowotnik added the bug label Nov 29, 2024
@mnowotnik
Copy link
Author

No issue on Pop_OS Linux
image

@huonw
Copy link
Contributor

huonw commented Dec 2, 2024

Sorry for the trouble. Could you make a fully standalone reproducer for the issue you're seeing?

For instance, a git repo we can clone and execute ourselves, or a script like the one in #21228?

@mnowotnik
Copy link
Author

mnowotnik commented Dec 2, 2024

@huonw So I made a repo and couldn't reproduce this. BUT I noticed that it fails if there's any Python file (matching *.py) in the project's root directory. If I remove it, suddenly everything works. Is it intended?

@huonw
Copy link
Contributor

huonw commented Dec 17, 2024

Ah, I think every python script is expected to have a source-root that includes it.

So, maybe root_patterns = ["/src", "/"] would be desirable, to cover the "normal" files in src as well as any top-level scripts. Does that help?

That said, it's peculiar that this behaviour would differ on different platforms.

(Thanks for waiting)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants