Hey! I'm trying to configure an existing repositor...
# general
a
Hey! I'm trying to configure an existing repository with pants V2. One of our dependencies is
h2o_pysparkling_2.4
which needs to be mapped using
module_mapping
. However, the
.
in the package name seems to prevent pants to understand how to do the mapping. Is this intended behaviour? If not, any idea how to get around this?
h
Hello! Welcome! Oh that's tricky. Most of us are afk today for MLK day in the US, but to debug, you would want to play around with setuptools in a REPL and it's pkg_resources.Requirement type. Use Requirement.parse() - Pants uses the property .project_name as the key for the mapping
a
Thanks for the quick response! So you are saying I should look for the
project_name
as defined by the 3rd party dependency I'm trying to import? Or should I let pants build a
setup.py
file and figure out how it tries to resolve the dependency?
h
We want to understand how pkg_reources.Requirement understands that requirement string because that is how Pants will represent it internally. Specifically, the property project_name will be the key in the module mapping Once we understand how setuptools/pkg_resources works by playing with it in a REPL, we will understand how to get this working with Pants
a
Thanks, I'll try to play around with that a little bit then! Pretty new to pants though, so hope I can figure this out 🙂
h
Okay I got access to a computer for a little 🙂 Here, I'm using Pex as a CLI tool to create a REPL with the relevant third party dep loaded into it. Independently of Pants, Pex is awesome for experiments like this
Copy code
❯ pex setuptools
Python 3.9.1 (default, Jan  8 2021, 12:11:08)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from pkg_resources import Requirement
>>> req = Requirement.parse("h2o_pysparkling_2.4")
>>> req.project_name
'h2o-pysparkling-2.4'
So, this suggests to me that the key in your
module_mapping
dictionary should be
'h2o-pysparkling-2.4'
. Could you please try that?
🙌 1
a
Thanks @hundreds-father-404, that worked! I'm just started to uncover the great work of
pex
, so thanks for sharing the example 😄 Might be good to add this as a note to the docs, as this might be the case for more 3rd party requirements 😛
❤️ 1