Hi, I’m getting a `ModuleNotFoundError` with v2 wh...
# general
c
Hi, I’m getting a
ModuleNotFoundError
with v2 when I try to
./pants run
a particular Python target (the module not found is a package in our repo). It seems that the pex files are layed out differently between v1 and v2 (or else I’ve misconfigured things?), but the v1 puts the dependency package (“ns_python_logger”) in the root directory while v2 puts it under a path that mirrors our repo (“lib/python_logger/src/ns_python_logger”).
w
that is likely due to the configuration for source roots changing a bit: sorry about that
c
Thanks for the link. I read the page, but it’s not clear to me how to make this work without reconfiguring the whole repo.
Or maybe I just have to make a source root entry for each individual package in our repo?
w
in the example above, do you have a
BUILD
file at
lib/python_logger/src/
?
c
yes
w
ok. so one of the behaviors in v1 that i’m not sure was preserved was that a target was its own source root if it wasn’t below a source root
if you have a convention* that python sources are located at the root of directories called
src
, then you might be able to install that as a pattern
cc @happy-kitchen-89482
ie:
Copy code
[source]
root_patterns = [
  'src',
]
c
ok, I’ll give that a try
w
@cuddly-window-48195: oh, also: what version is this?
c
1.28
w
got it: thanks. there have been a few more changes in 1.29.x … lemme see if they are relevant
h
👀
w
…so, yes. it did change a bit further in 1.29.x i think. @cuddly-window-48195: 1.29.0 will likely be released today, so you might consider trying out
1.29.0rc4
h
Yeah, so that pattern might work, or if not you can explicitly mark source roots with an empty dummy file (like "SOURCE_ROOT"), if you first set:
Copy code
[source]
marker_filenames: ["SOURCE_ROOT"]
c
Ok, I’ll bump up to 1.29. I started with the configuration file here: https://github.com/pantsbuild/example-python/blob/master/pants.toml Which had
root_patterns = [ '/' ]
.
w
ah… so
hm.
good to know, heh 😃 we should maybe change that.
h
We changed it to that recently, because "repo root is python source root" is not uncommon.
Probably should add a comment there saying "you'll have to configure your own roots, here's a link to the docs"
w
@cuddly-window-48195: did you already have an existing
pants.ini
file?
h
Also I should update the docs to include marker files.
w
it might not be clear, but
pants.ini
files can be converted into
pants.toml
files, and if you bump version-at-a-time you’ll get lots of (hopefully helpful) deprecation warnings
so if you already had an install of pants, it’s likely that converting your config would be a good place to start
c
Sorry, I didn’t see the new notifications. I did have a pants.ini file previously; I was getting errors so I decided to try starting with the example file and working backwards to our old configuration.
Is 1.29.0 not yet released?
w
today we think 😃
c
I’m only seeing an rc4 and then a 1.30.0.dev0
ah, cool. exciting!
So I’m now getting this error after trying to upgrade to 1.29.0.rc4:
Copy code
/Users/cweber/.cache/pants/setup/bootstrap-Darwin-x86_64/1.29.0_py36/bin/python: can't open file '/Users/cweber/.cache/pants/setup/bootstrap-Darwin-x86_64/1.29.0_py36/bin/pants': [Errno 2] No such file or directory
Oops, never mind. forgot to save the config file.
w
so, based on this feedback, we’re actually going to try and improve the sourceroot defaults a bit! so 1.29.0 won’t be today: maybe monday
👍 1
thanks for reporting
but in the meantime, i do suspect that
Copy code
[source]
root_patterns = [
  'src',
]
will help in this case
c
Sorry for the long delay, this did help; however, it only seems to work for 1.28.0. With 1.29.0rc4, I got this error:
Copy code
17:51:47:253 [ERROR] 1 Exception encountered:

  InvalidFieldException: Unrecognized field `source=ns_cli_deploy/cli.py` in target apps/cli_deploy/src:lexio-deploy. Valid fields for the target type `python_binary`: ['_transitive', 'always_write_cache', 'compatibility', 'dependencies', 'description', 'emit_warnings', 'entry_point', 'ignore_errors', 'inherit_path', 'no_cache', 'platforms', 'provides', 'scope', 'shebang', 'sources', 'tags', 'zip_safe'].
“source” is now “sources” in 1.29?
w
yea… in 1.28 you should see deprecation warning for it?
sorry about that. the idea was to remove special cases.
c
No deprecation warning, but removing special cases sounds good. 👍 Thanks for the work you’re doing; I’m excited for v2!
w
… hm. that’s odd. sorry about that. i think that the deprecation might only trigger in some limited cases.
h
Change for the source root defaults: https://github.com/pantsbuild/pants/pull/10043
🎉 1