https://pantsbuild.org/ logo
#general
Title
# general
c

cuddly-window-48195

06/12/2020, 5:18 PM
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

witty-crayon-22786

06/12/2020, 5:21 PM
that is likely due to the configuration for source roots changing a bit: sorry about that
c

cuddly-window-48195

06/12/2020, 5:24 PM
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

witty-crayon-22786

06/12/2020, 5:25 PM
in the example above, do you have a
BUILD
file at
lib/python_logger/src/
?
c

cuddly-window-48195

06/12/2020, 5:25 PM
yes
w

witty-crayon-22786

06/12/2020, 5:25 PM
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

cuddly-window-48195

06/12/2020, 5:27 PM
ok, I’ll give that a try
w

witty-crayon-22786

06/12/2020, 5:28 PM
@cuddly-window-48195: oh, also: what version is this?
c

cuddly-window-48195

06/12/2020, 5:28 PM
1.28
w

witty-crayon-22786

06/12/2020, 5:28 PM
got it: thanks. there have been a few more changes in 1.29.x … lemme see if they are relevant
h

happy-kitchen-89482

06/12/2020, 5:29 PM
👀
w

witty-crayon-22786

06/12/2020, 5:30 PM
…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

happy-kitchen-89482

06/12/2020, 5:31 PM
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

cuddly-window-48195

06/12/2020, 5:31 PM
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

witty-crayon-22786

06/12/2020, 5:31 PM
ah… so
hm.
good to know, heh 😃 we should maybe change that.
h

happy-kitchen-89482

06/12/2020, 5:32 PM
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

witty-crayon-22786

06/12/2020, 5:32 PM
@cuddly-window-48195: did you already have an existing
pants.ini
file?
h

happy-kitchen-89482

06/12/2020, 5:32 PM
Also I should update the docs to include marker files.
w

witty-crayon-22786

06/12/2020, 5:45 PM
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

cuddly-window-48195

06/12/2020, 5:47 PM
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

witty-crayon-22786

06/12/2020, 5:48 PM
today we think 😃
c

cuddly-window-48195

06/12/2020, 5:48 PM
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

witty-crayon-22786

06/12/2020, 6:05 PM
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

cuddly-window-48195

06/12/2020, 7:02 PM
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

witty-crayon-22786

06/12/2020, 7:03 PM
yea… in 1.28 you should see deprecation warning for it?
sorry about that. the idea was to remove special cases.
c

cuddly-window-48195

06/12/2020, 7:04 PM
No deprecation warning, but removing special cases sounds good. 👍 Thanks for the work you’re doing; I’m excited for v2!
w

witty-crayon-22786

06/12/2020, 7:05 PM
… hm. that’s odd. sorry about that. i think that the deprecation might only trigger in some limited cases.
h

happy-kitchen-89482

06/12/2020, 11:28 PM
Change for the source root defaults: https://github.com/pantsbuild/pants/pull/10043
🎉 1