-
-
Notifications
You must be signed in to change notification settings - Fork 636
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
Move testinfra code from tests/python/pants_tests
to src/python/pants/testutil
#8400
Move testinfra code from tests/python/pants_tests
to src/python/pants/testutil
#8400
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huzzah!
This is not true in general, although it might be true for the It would be good to make sure that we're not doing this only for the above reason. In general: yea, I agree, test helper code is still a library, and so that could be a good reason to do this. |
I agree! I realized that regardless of trying to chroot those Python ITs, I think this is a good change to make. If we're moving in the direction of all tests living in Another big benefit of this new scheme is that it centralizes all util code into one root folder. It makes discovery much easier of all the different base classes we can use, for example.
Haven't looked closely at this yet because I'm not sure yet it's necessary. If this approach falls through, will look more closely. But, yes, to reiterate, regardless of chrooting ITs, I think this is a good change to make. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I can't figure out how to land this due to the wheel building shards. The issue looks like:
The validation in pants/src/python/pants/backend/python/tasks/setup_py.py Lines 246 to 306 in ea2e46f
The key function for finding potential owners looks at ancestor and sibling targets: pants/src/python/pants/backend/python/tasks/setup_py.py Lines 126 to 155 in ea2e46f
Reading this code, especially line 149 |
ca33f3b
to
72fa0e5
Compare
Correct. I read quickly but I think the fundamental issue is maintaining backward compat. As such, just introduce 2 distributions. The new distribution exports |
src/python/pants/testinfra/BUILD
Outdated
@@ -13,36 +12,18 @@ python_library( | |||
'src/python/pants/testinfra/engine:engine_test_base', | |||
'src/python/pants/testinfra/subsystem', | |||
], | |||
# TODO(???): Once we remove `pants_test:testinfra`, reclaim the wheel name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't. In any language an atfiact name really needs to map to its contents and not lose the mapping. It allows version resolution to work. If you provide the same contents under multiple distribution names, the resolver is unaware and can place old==1.0.0 and new==1.2.3 in the same claspath/pythonpath, etc and now you have a 1st in path silent wins rest silently fail situation. This is a very real problem in jvm land, it would be great not to do this ourselves.
src/python/pants/testinfra/BUILD
Outdated
provides=pants_setup_py( | ||
name='pantsbuild.pants.testinfra', | ||
name='pantsbuild.pants.testinfra.new_namespace', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider just 'pantsbuild.pants.tests' or '''pantsbuild.pants.testsupport' - not as good names but probably good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like testsupport
or testutil
(tests
sounds like it contains actual tests).
tests/python/pants_tests
to src/python/pants/testinfra
tests/python/pants_tests
to src/python/pants/testutils
This solves the problem of a duplicate wheel name
a002ca0
to
9340764
Compare
Ready for re-review. I decided not to change Instead, we simply use a new wheel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I prefer util
, singular, and that's a more common usage in our codebase:
386
statler:[~/src/pants][master]$ git grep "util" | wc -l
3213```
build_graph=build_graph, build_configuration=build_configuration, | ||
address_mapper=address_mapper, console_outstream=console_outstream, | ||
workspace=workspace, scheduler=scheduler) | ||
from pants.testutils.base.context_utils import TestContext as TestContext # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the need for the apparently redundant aliasing? Afaict its not needed technically - a proof:
$ cat a/b/c/d.py
from os import path
import sys
def func():
return 42
$ cat e/f/g.py
from a.b.c.d import func, path, sys
print(f'{func()} {sys.executable} {path.basename(sys.executable)}')
$ python -c 'import e.f.g'
42 /usr/bin/python python
If it's for emphasis that these imports are just for re-exporting symbols in a new namespace a boilerplate comment on each file seems more savory (subjective), than a bunch of isort suppressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iirc, I believe we have a MyPy lint to require explicit exports in this style.
The noqa is to suppress pycodestyle saying that we don’t use the import. We would need those no matter what.
(On my phone cleaning old apartment - pardon me not confirming this all)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha. OK, I'm happy to see this change, so not a huge deal, but a pretty explicit statement of all this then would be:
from a import b
...
from foo.bar import Baz
b = b
...
Baz = Baz
That seems pretty clearly to be importing for the purpose of re-export in the current __name__
space with no violations of any linter's sensibilities.
I'll underscore though that I'm happy enough with all this.
tests/python/pants_tests
to src/python/pants/testutils
tests/python/pants_tests
to src/python/pants/testutil
Problem
We are in the process of moving our tests to live within the
src
directory, rather thantests
(#7489). We should consequently have our core utility code live insrc
.Further, the current utils are spread out across several folders, which makes discovery more difficult.
Solution
Create a new
pants/testutil
namespace with all of the files used by thepants.testinfra
wheel. Specifically, it has this directory structure:We can't yet delete the equivalent files in
pants_test
due to a public API, so we instead have those files simply re-export the implementation inpants/testutils
.Does not move some util code
There are several util files not exposed to the
pantsbuild.testinfra
wheel, likeengine/scheduler_test_base.py
. To reduce the scope of this PR, we keep those there for now. Presumably, they will be able to be moved intopants/testinfra
without a deprecation cycle.Creates new wheel
pantsbuild.pants.testutil
We had to create a new package, rather than using
pantsbuild.pants.testinfra
, due to rules about ownership of files (#8400 (comment)).In a followup, we will deprecate
pantsbuild.pants.testinfra
.Result
We can now either use
pants.testutil
or the conventionalpants_test
imports. Both have the same functionality.In a followup PR, we will deprecate the
pants_test
version.