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

wooden-thailand-8386

10/20/2020, 5:57 PM
Hello everyone! I’m back to annoy y’all lol. So something odd is going on here… I migrated from v1 to v2 and when building a .pex of my application it can’t find the first-party libs anymore. I’m using the same version, everything is the same (code-wise) other than the pants version and required target changes on BUILD files. I even went to my other branch (with pants v1) and built it again, unzipped the
pex
file and they are pretty much the same.. have the same
.deps
the libs are there..
__init__
files where they should be… so I’m very confused.. I’ve been trying to troubleshoot this for a while but now I’m kinda puzzled/stuck.
j

jolly-midnight-72759

10/20/2020, 6:11 PM
When you say "`__init__.py` files are where they should be", do you mean in the pex the v1 built or in your repo before they are built? Also, does your
pants.toml
allow py2 and py3? If so, I have found that I need to explicitly declare my `pex_binary`'s compatibility to get the pex I am looking for.
w

wooden-thailand-8386

10/20/2020, 6:13 PM
I mean that everything looks like to be the same… files are at the same location in both cases. And no, I have my interpreter_constraints set to
>=3.7,<3.8
but I can give that a shot
h

hundreds-father-404

10/20/2020, 6:16 PM
try
zip_safe=False
in the
pex_binary
(formerly
python_binary
) target also
w

wooden-thailand-8386

10/20/2020, 6:20 PM
Nope, didnt work 😞
😕 1
That’s what I have for my
pex_binary
Copy code
pex_binary(
  name = "rasa_bot_pex",
  entry_point = "rasa",
  dependencies = [
    # We don't have any import statements (nor python files).
    # Inference won't work here.
    "libs/rasa_services",
    "libs/rasa_clue_components",
    "libs/rasa_toolbox",
  ],
  output_path="rasa_bot.pex",
  compatibility = "CPython>=3.7,<3.8",
  zip_safe=False,
)
👍 1
the difference on v1 BUILD and v2 is that now I only have those first-party libs declared under dependencies.. the rest pants magically figures it out. Oh and I added the zip_safe and compatibility now.
👍 1
Is there any way that I can run that
.pex
and open the python interpreter (or ipython) so I can try to manually import and debug things?
j

jolly-midnight-72759

10/20/2020, 6:25 PM
You mean run the project in a
repl
? Isn't that the same thing?
pants repl --shell=ipython project/src/python/rasa_bot:rasa_bot_pex
Did you use
diff -r dir1 dir2
to compare the pex's from v1 and v2?
h

hundreds-father-404

10/20/2020, 6:26 PM
You can use
./pants run path/to:pex
, but it’s slightly different in that the source files won’t go into that pex, only third party deps will go in
f

fast-nail-55400

10/20/2020, 6:27 PM
you can also run the pex with
PEX_INTERPRETER=1
to get a repl
🤩 2
w

wooden-thailand-8386

10/20/2020, 6:28 PM
No, I did not use
diff
but I should have used it.
@jolly-midnight-72759 didnt know I could do that, pretty cool. @fast-nail-55400 yup, that’s exactly what I was looking for!
interesting… it actually imported it 😕 on repl
j

jolly-midnight-72759

10/20/2020, 6:34 PM
Did you move the pex to a python venv or another box? If you are using your regular python interpreter and PEX doesn't create a chroot/venv, then the missing libraries might be on your path.
h

hundreds-father-404

10/20/2020, 6:34 PM
What do you mean it actually imported it?
w

wooden-thailand-8386

10/20/2020, 6:35 PM
ran a basic:
from my_lib import MyClass
and it found it and imported it.
when I run the
.pex
directly it gives me a ModuleNotFoundError
No, @jolly-midnight-72759, did not. Just using good old pyenv with py3.7 and running
./rasa_bot.pex
j

jolly-midnight-72759

10/20/2020, 6:36 PM
Does
from my_lib import MyClass
work when you use that same py3.7's repl (sans pex)?
👍 1
w

wooden-thailand-8386

10/20/2020, 6:37 PM
yes
well, actually no, I have to do a
poetry shell
(or poetry run) first to have that under my venv
h

hundreds-father-404

10/20/2020, 6:39 PM
Oh, Thales, compare the
PEX-INFO
file from before and after also. Iirc, it’s at the top level of the unzipped pex
👍 1
w

wooden-thailand-8386

10/20/2020, 6:39 PM
wait
Copy code
{
  "asctime": "2020-10-20 14:39:54,452",
  "module": "run",
  "funcName": "serve_application",
  "lineno": 193,
  "message": "Starting Rasa server on <http://localhost:5005>"
}
what kind of wizardry is this?
h

hundreds-father-404

10/20/2020, 6:40 PM
I don’t know hah, what’s the context of this?
w

wooden-thailand-8386

10/20/2020, 6:41 PM
that’s the expected output lol
1
j

jolly-midnight-72759

10/20/2020, 6:43 PM
Was that run within the
poetry shell
?
w

wooden-thailand-8386

10/20/2020, 6:43 PM
I have a theory, let me test something here and I’ll get back with some sort of reasonable explanation
🔬 2
👍 1
No, that was actually me running the .pex that wasnt working before lol
magic 1
magic
Alright so it was my lack of attention. It was failing to import a first-party lib but the actual error was not finding a 3rdparty dependency. One of them pants wasnt able to find due to weird naming convention so I had to add it to
module_mapping
and then everything kinda worked. It wasn’t happening on v1 because I was explicitly adding all my dependencies.
👖 1
h

hundreds-father-404

10/20/2020, 7:10 PM
Ahh. Thanks for the update!
w

wooden-thailand-8386

10/20/2020, 7:10 PM
this little culprit here
Copy code
"python-json-logger": ["pythonjsonlogger"]
🙃 1
4 Views