why is pants deleting content from my init.py file...
# general
e
why is pants deleting content from my init.py files?
Copy code
$ wc -l __init__.py
     125 
$ wc -l /Users/amckenna/code/python-commons/.pants.d/pyprep/path/to/__init__.py
       0
w
it’s likely creating empty ones in places where none existed in targets
e
but one does exist
w
do you have targets that own those
__init__.py
files?
e
yes
w
and they show up in
./pants filedeps
for the thing you are running?
e
rglobs('*.py') should get init.py files right?
w
yea, it should. but good to confirm that you see it in filedeps
if you do, it’s probably worth filing a bug there describing what you’re seeing, and mentioning which version you’re on
e
do builds not include submodules by default or something?
If I add a BUILD file in the subdirectory suddenly everything works
w
hm
pants does not have any particular logic for git submodules…
e
it's not a submodule
I'm talking about python modules
w
mm
so, no, “modules below some module” in a hierarchy are not included by default… only target dependencies or globs would pull something in
e
rglobs doesn't pull in subdirectories?
w
rglobs should be sufficient to do the latter thing
e
I thought that was the difference between globs and rglobs
w
it does.
did you confirm that you weren’t seeing it in filedeps?
e
it's there in filedeps
w
both before and after adding the BUILD file…?
e
definitely before
w
that’s very odd. that would just be a bug, i think.
possibly related to how we try to inject init files in cases where they don’t already exist
a repro would be really appreciated in a ticket. we’ve been discussing adding/adjusting magic there.
sorry for the trouble.
e
ok thanks
h
Including which Pants version and if this is using the V1 execution engine or V2. The code paths are different between them
e
0.23, on v1 afaik
it seems like tests and module files are being put in the same directory for testing?
is this correct?
w
if they are in the same module, yea.
e
ok well then I'm guessing the init from the test directory is overwriting the other one
w
mm. yuck. yea.
in v2 that will result in an error iff they don’t have identical content.
e
removing the blank init files from the test dirs solves the problem
🙌 2
h
Ah yes... To clarify, this reflects a real-world Python problem that isn't unique to Pants. If you have two colliding modules in different source roots that one will necessarily shadow the other, it's just how importing works.
If this worked before now it's presumably because the "good" file happened to be picked.
But possibly we should warn about this when we merge the chroot.
w
yea, v2 will/does.