rhythmic-butcher-20315
06/05/2024, 10:01 PMpants roots
like this:
import subprocess
roots_output = subprocess.check_output(["./pants", "roots"], text=True)
print(roots_output)
And I used to run it using pants run name_of_script.py
The issue is that, after I updated my repo to pants 2.20, the pants roots
command inside my script is returning:
21:57:15.40 [ERROR] 1 Exception encountered:
Engine traceback:
in `run` goal
NoSourceRootError: No source root found for `.`. See <https://www.pantsbuild.org/2.20/docs/using-pants/key-concepts/source-roots> for how to define source roots.
This only happens if I'm calling my script using pants run
. I didn't want to depend on the system's python path as I am not always sure if python is called python
or python3
or something else. Is this an issue someone else reported or is this intended? Any ideas how to fix this or any workarounds?fast-nail-55400
06/05/2024, 10:12 PMfast-nail-55400
06/05/2024, 10:13 PMrhythmic-butcher-20315
06/05/2024, 10:15 PMpants roots
, it returns tons of folders that we're using as sources. The issue is that, for some reason, when I running pants roots
inside a script that's being called by pants run
, it can't find the root sources. This started happening in pants 2.20.rhythmic-butcher-20315
06/05/2024, 10:15 PMrhythmic-butcher-20315
06/05/2024, 10:31 PMPANTS_CONCURRENT=True pants run scripts/generate-env-file.py
using pants 2.18 and then using pants 2.20/2.21.
Here's what happens:fast-nail-55400
06/05/2024, 10:32 PMfast-nail-55400
06/05/2024, 10:33 PMrhythmic-butcher-20315
06/05/2024, 10:33 PMrhythmic-butcher-20315
06/05/2024, 10:33 PMfast-nail-55400
06/05/2024, 10:33 PMrhythmic-butcher-20315
06/05/2024, 10:34 PMrhythmic-butcher-20315
06/05/2024, 10:40 PM.env
file for vscode users. This relied on the pants roots
command. It's not a big deal tbh. I can just write it in bash and it'll probably work fine.
I am more interested in knowing if this is a regression or a intentional change.rhythmic-butcher-20315
06/05/2024, 10:56 PMfast-nail-55400
06/05/2024, 11:43 PMgit log release_2.20.0.dev7..release_2.20.0a0 -- src/python/pants/backend/python
fast-nail-55400
06/05/2024, 11:44 PMPANTS_SOURCE
env var to pants
invocation to run from Pants sources.)fast-nail-55400
06/05/2024, 11:48 PMrhythmic-butcher-20315
06/10/2024, 3:13 PMfast-nail-55400
06/10/2024, 4:19 PMrhythmic-butcher-20315
06/10/2024, 11:22 PMcommit 882ffe64f69089b33a6541ba000bbc4638c48d9d (HEAD)
Author: Jacob Floyd <cognifloyd@gmail.com>
Date: Fri Feb 9 10:20:41 2024 -0600
Add support for the pex `--executable` argument (#20497)
This PR adds support for `pex --executable <path to script>` added in
pex [2.1.93](<https://github.com/pantsbuild/pex/releases/tag/v2.1.93>):
<https://github.com/pantsbuild/pex/pull/1807>
With this change, users should be able to do `pants run
bin/my-python-script.py`.
Closes #18290
---------
Co-authored-by: Benjy Weinberger <benjyw@gmail.com>
rhythmic-butcher-20315
06/11/2024, 1:18 AMcreate_python_source_run_request
located in src/python/pants/backend/python/goals/
. The PR adds the executable=field_set._executable_main()
field to the _create_python_source_run_request
call. Removing this brings us back to the previous behavior, but I am not sure what this is doing and if should be changed.
I already fixed this issue on my end by running my scripts as shell scripts instead of using pants. If this is a regression, I think this is the place where we should check, but if it's nothing too important to the team, I think we can ignore it 🤷 .fast-nail-55400
06/11/2024, 1:48 AMproud-dentist-22844
06/11/2024, 1:55 AMproud-dentist-22844
06/11/2024, 2:15 AMgenerate-env-file.py
because -
is not a valid character for a python identifier.
I'm confused in part because I added the executable feature specifically to handle scripts with -
.
I tried renaming your script to use _
instead of -
which works by bypassing the new pex --executable
feature. Inspecting the sandbox now...proud-dentist-22844
06/11/2024, 2:36 AMpants
to use a different path: PANTS_BUILDROOT_OVERRIDE=/home/cognifloyd/g/github/mikaelsouza/pants-root-issue
proud-dentist-22844
06/11/2024, 2:36 AMexecutable
instead of entry_point
triggers a source root error.proud-dentist-22844
06/11/2024, 2:48 AM/
to the list of source patterns, it gets farther, but stil dies before actually executing the script. 😞proud-dentist-22844
06/11/2024, 3:23 AMpants run
integration test I wrote (uhm. Actually, I copy/paste/modified from another test) for this feature tests running a pex_binary, not a python_source. I didn't realize I missed testing that 😕 Sorry.proud-dentist-22844
06/11/2024, 3:45 AM_
instead of -
.proud-dentist-22844
06/11/2024, 5:13 AMproud-dentist-22844
06/17/2024, 10:34 PMpex --executable
bugs. I've tagged it to be backported to 2.20 (the version the executable feature was introduced in).proud-dentist-22844
06/19/2024, 4:40 PMrhythmic-butcher-20315
07/03/2024, 5:28 PMproud-dentist-22844
07/27/2024, 3:40 AM