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

Add --unowned-dependency-behavior option for Python #13491

Merged
merged 17 commits into from
Nov 11, 2021

Conversation

thejcannon
Copy link
Member

As discussed in Slack, adding a way to flag deps that are silently unowned.

@thejcannon
Copy link
Member Author

I'll try and add some unit tests soon. Local testing shows it works! 🎉

# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

_STDLIB_MODULES = [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any modules that were removed from previous versions and might not appear? 🤔

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric-Arellano will likely have thoughts on this. We actually... removed per-interpreter-version lists a while back in #12818. But that was because we were using it to filter things, rather than to backstop a validation like this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this is an ever-growing list unless there's a good reason why it shouldn't be.

My question here is basically I just dumped the std library list form 3.10 because it was easy, so is there anything that needs to be added because 3.10 doesn't have them (anymore).

Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks a lot.

register(
"--unowned-dependency-behavior",
type=UnownedDependencyUsage,
default=UnownedDependencyUsage.DoNothing,
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good+safe initial default, but I'm very interested in how many false positives you get with this... if we're able to make it warn by default in a future release, that would be great.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Will report back later on our monorepo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far it's just found a bunch of questionable imports, things that belong in module_mapping, and imports I hadn't realized we had that'll need some finagling.

An example of the last one was a dependency on an in-house compiled C extension module. Or funny import tricks like:

try:
    import foo
except ImportError:
    import bar

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just finished with the monorepo. Nothing too surprising. The only one that got me was an import like foo.bar.baz being unowned. I added a BUILD file to ./foo/bar (no BUILD files any higher) and declared a python_requirement with module "baz" (just to silence the warning, wouldn't pass the test) and still saw the error.

Instead I had to declare the module as "foo.bar.baz". Not sure if that change makes sense, or works around Pants' shortcomings in some way 🤔

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a BUILD file to ./foo/bar (no BUILD files any higher) and declared a python_requirement with module "baz" (just to silence the warning, wouldn't pass the test) and still saw the error.

I think that this makes sense... python_requirement targets do not have source roots applied, so foo.bar would not have been prefixed onto baz in this case.

Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

stuhood added a commit that referenced this pull request Nov 9, 2021
Unfortunately, it looks like `--no-print-stacktrace` broke in a critical location a while back, resulting in unnecessary noise. See for example: #13491 (comment)

Fix, and add an integration test. Also fixes the location of the `exceptions.log`, and removes `ExceptionSink` `Ctrl+C` tests, since `Ctrl+C` is now directly handled by the engine (fixes #12108).

[ci skip-rust]
[ci skip-build-wheels]
stuhood added a commit to stuhood/pants that referenced this pull request Nov 9, 2021
Unfortunately, it looks like `--no-print-stacktrace` broke in a critical location a while back, resulting in unnecessary noise. See for example: pantsbuild#13491 (comment)

Fix, and add an integration test. Also fixes the location of the `exceptions.log`, and removes `ExceptionSink` `Ctrl+C` tests, since `Ctrl+C` is now directly handled by the engine (fixes pantsbuild#12108).

[ci skip-rust]
[ci skip-build-wheels]
stuhood added a commit to stuhood/pants that referenced this pull request Nov 9, 2021
Unfortunately, it looks like `--no-print-stacktrace` broke in a critical location a while back, resulting in unnecessary noise. See for example: pantsbuild#13491 (comment)

Fix, and add an integration test. Also fixes the location of the `exceptions.log`, and removes `ExceptionSink` `Ctrl+C` tests, since `Ctrl+C` is now directly handled by the engine (fixes pantsbuild#12108).

[ci skip-rust]
[ci skip-build-wheels]
stuhood added a commit that referenced this pull request Nov 9, 2021
Unfortunately, it looks like `--no-print-stacktrace` broke in a critical location a while back, resulting in unnecessary noise. See for example: #13491 (comment)

Fix, and add an integration test. Also fixes the location of the `exceptions.log`, and removes `ExceptionSink` `Ctrl+C` tests, since `Ctrl+C` is now directly handled by the engine (fixes #12108).

[ci skip-rust]
[ci skip-build-wheels]
stuhood added a commit that referenced this pull request Nov 9, 2021
Unfortunately, it looks like `--no-print-stacktrace` broke in a critical location a while back, resulting in unnecessary noise. See for example: #13491 (comment)

Fix, and add an integration test. Also fixes the location of the `exceptions.log`, and removes `ExceptionSink` `Ctrl+C` tests, since `Ctrl+C` is now directly handled by the engine (fixes #12108).

[ci skip-rust]
[ci skip-build-wheels]
@stuhood
Copy link
Sponsor Member

stuhood commented Nov 9, 2021

We can probably land this whenever it's green in CI. If you need help with that, let me know!

@thejcannon
Copy link
Member Author

Oh I wouldn't want that until I've added tests 😁 💪

Also I think we still want the whitelist support.

@thejcannon thejcannon marked this pull request as ready for review November 9, 2021 22:27
@thejcannon
Copy link
Member Author

Dropped the "Draft" status after adding tests. 🚀

@thejcannon
Copy link
Member Author

Actually, I want to add a few more tests, for some good coverage 👍

@thejcannon
Copy link
Member Author

Officially good to go!

@stuhood stuhood changed the title WIP: Add --unowned-dependency-behavior option Add --unowned-dependency-behavior option Nov 10, 2021
Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

CONTRIBUTORS.md Outdated Show resolved Hide resolved
register(
"--unowned-dependency-behavior",
type=UnownedDependencyUsage,
default=UnownedDependencyUsage.DoNothing,
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a BUILD file to ./foo/bar (no BUILD files any higher) and declared a python_requirement with module "baz" (just to silence the warning, wouldn't pass the test) and still saw the error.

I think that this makes sense... python_requirement targets do not have source roots applied, so foo.bar would not have been prefixed onto baz in this case.

@stuhood stuhood changed the title Add --unowned-dependency-behavior option Add --unowned-dependency-behavior option for Python Nov 10, 2021
@stuhood stuhood enabled auto-merge (squash) November 10, 2021 22:34
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Co-authored-by: Stu Hood <stuhood@gmail.com>
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Co-authored-by: Stu Hood <stuhood@gmail.com>
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Co-authored-by: Stu Hood <stuhood@gmail.com>
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
thejcannon and others added 9 commits November 10, 2021 16:20
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
[ci skip-rust]
[ci skip-build-wheels]
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.

3 participants