proud-dentist-22844
06/16/2022, 1:27 AMPexFromTargetsRequest @bitter-ability-32190! That worked perfectly for one of the local scripts I need to run in my pants plugin. But, I'm struggling with the other script.
It is a python script named st2-generate-schemas - note the dashes - so, I can't figure out how how to get PEX to run the script. Using --no-process-cleanup, I can see that my VenvPex includes bin/st2-generate-schemas and st2common/ which is a module used by the script.
If I do PexFromTargetsRequest(..., main=ConsoleScript("st2-generate-schemas")), I get pex_builder errors because nothing has that entry point registered. Same thing if I do ConsoleScript("bin/st2-generate-schemas").
If I do PexFromTargetsRequest(..., main=EntryPoint("st2-generate-schemas") , then it silently does nothing. But when I run it manually with __run.sh, I see the ImportError: No module named st2-generate-schemas.
Leaving off main= doesn't work either, because then it pex just opens a repl.
It's not an entry point, and it's not importable as a module. How do I run this script?hundreds-father-404
06/16/2022, 1:30 AMproud-dentist-22844
06/16/2022, 1:30 AMhundreds-father-404
06/16/2022, 1:31 AMproud-dentist-22844
06/16/2022, 1:31 AMproud-dentist-22844
06/16/2022, 1:33 AMproud-dentist-22844
06/16/2022, 1:34 AMenough-analyst-54434
06/16/2022, 1:36 AMConsoleScript is for the console script concept from setuptools. This is not that. That leaves EntryPoint which must be a valid Python module (and maybe function in that module) which this is not. So, as things stand, the - naming won't work with Pants or Pex.hundreds-father-404
06/16/2022, 1:37 AMfrom bin import my_script
if __name__ == "__main__":
my_script.main()
We use a custom Poetry launcher:
https://github.com/pantsbuild/pants/blob/1c65b9c7ee88606eb288e22fa1bc5c3267751082/src/python/pants/backend/python/subsystems/poetry.py#L36-L47
https://github.com/pantsbuild/pants/blob/1c65b9c7ee88606eb288e22fa1bc5c3267751082/src/python/pants/backend/python/goals/lockfile.py#L210-L221
But that import won't work. So I'm naively wondering if you can somehow load it as a resource, like pkgutil.get_data(). Or, pre-process the executable file to use underscoresproud-dentist-22844
06/16/2022, 1:39 AM- script from its logic then. Thanks for validating that it doesn't work the way I was attempting.proud-dentist-22844
06/16/2022, 1:39 AMproud-dentist-22844
06/16/2022, 1:40 AMenough-analyst-54434
06/16/2022, 2:41 AMproud-dentist-22844
06/16/2022, 2:42 AMenough-analyst-54434
06/16/2022, 4:21 AMenough-analyst-54434
06/17/2022, 6:56 AMproud-dentist-22844
06/17/2022, 2:48 PMenough-analyst-54434
06/17/2022, 3:35 PMproud-dentist-22844
07/02/2022, 12:31 AM--exe arg for kebab-scripts. What might the UX look like in pants? (once that elbow grease has been applied)
We already have ConsoleScript and EntryPoint, so maybe Executable? So:
PexFromTargetsRequest(..., main=Executable("bin/st2-generate-schemas")) ?bitter-ability-32190
07/02/2022, 12:32 AMpex_binary is script, so maybe that? šproud-dentist-22844
07/02/2022, 12:33 AMproud-dentist-22844
07/02/2022, 12:33 AMbitter-ability-32190
07/02/2022, 12:34 AMproud-dentist-22844
07/02/2022, 12:44 AM-m, -e, `--entry-point`: EntryPoint -- a module or module:func reference
⢠-c, --script, `--console-script`: ConsoleScript -- this references the name of a console_scripts entry point
⢠--exe, --executable, `--python-script`: SomethingNewHere any python script
The key difference is that for EntryPoint and ConsoleScript, the python file must be importable. I have some kebab-case python scripts (st2-generate-schemas) that cannot be imported because of the dash. So, the new pex feature makes it possible to run those scripts via pex.bitter-ability-32190
07/02/2022, 12:46 AMmain on the target and lean into objects farther in BUILD filesproud-dentist-22844
07/02/2022, 12:51 AMmain= comes from (it already exists like that on the PexFromTargetsRequest.
Maybe we would need a new executable field on pex_binary target to expose this to users as well. š¤proud-dentist-22844
07/02/2022, 12:53 AMscript field, and track down where it is used to add executable everywhere it is needed.bitter-ability-32190
07/02/2022, 1:38 AMmain as a union type, we should make the target sikilarbitter-ability-32190
07/02/2022, 1:38 AMbitter-ability-32190
07/02/2022, 1:42 AMbitter-ability-32190
07/02/2022, 1:44 AMPyScript?proud-dentist-22844
07/02/2022, 4:21 AMproud-dentist-22844
07/02/2022, 4:21 AMExecutable, but maybe a more verbose PythonExecutableScript would be better... anyway.