https://pantsbuild.org/ logo
w

wide-midnight-78598

03/22/2023, 12:17 PM
And possibly similar to above, is there a CLI command to get the BUILD file itself where a target is specified? Not the directory, but the file (e.g. if someone uses BUILD vs BUILD.pants)
b

bitter-ability-32190

03/22/2023, 1:05 PM
Is this not in
peek
?
If not maybe we should make a flag for peak akin to "give me everything" or like peek verbosity?
w

wide-midnight-78598

03/22/2023, 1:08 PM
Doesnt' appear to be, in the docs anyways - but either way,
peek
is a per-target thing I believe, not like ...
list
or
filter
b

bitter-ability-32190

03/22/2023, 1:09 PM
Huh?
w

wide-midnight-78598

03/22/2023, 1:11 PM
pants some-command
Copy code
examples/hellopython/BUILD.pants
examples/hellofastapi/BUILD
examples/hellotyper/BUILD.weirdext
Ignoring why a repo would do that, I'm trying to get the filename/path that a target belongs to .
b

bitter-ability-32190

03/22/2023, 1:12 PM
Right, you could peek the target name then filter the result
w

wide-midnight-78598

03/22/2023, 1:15 PM
Not sure if I'm following:
Copy code
⏺ oss/pants-plugins % pants peek examples/python/hellofastapi:libhellofastapi
[
  {
    "address": "examples/python/hellofastapi:libhellofastapi",
    "target_type": "python_sources",
    "dependencies": [
      "examples/python/hellofastapi/hellofastapi/__init__.py:../libhellofastapi",
      "examples/python/hellofastapi/hellofastapi/main.py:../libhellofastapi"
    ],
    "description": null,
    "overrides": null,
    "skip_autoflake": false,
    "skip_bandit": false,
    "skip_black": false,
    "skip_flake8": false,
    "skip_isort": false,
    "skip_mypy": false,
    "skip_pyupgrade": false,
    "sources": [
      "examples/python/hellofastapi/hellofastapi/__init__.py",
      "examples/python/hellofastapi/hellofastapi/main.py"
    ],
    "sources_raw": [
      "**/*.py"
    ],
    "tags": null
  }
]
What am I filtering there?
I know there is a BUILD file in the hellofastapi directory, but I don't know how it's named
I could get the possible namings from pants.toml
(also, obvs I know I could grep/sed/whatever - trying to figure out a pants-native way of doing it)
b

bitter-ability-32190

03/22/2023, 1:29 PM
Yeah I'm saying we could expose the name through peek (if it already isn't there) that's metadata on a target
And to your point you could have multiple build patterns (we did at one point) so grep/sed/whatever and pants.toml won't work always
w

wide-midnight-78598

03/22/2023, 1:32 PM
Yeah I'm saying we could expose the name through peek (if it already isn't there) that's metadata on a target
Oh yeah, for sure this.
so grep/sed/whatever and pants.toml won't work always
Reading pants.toml build patterns and dirty grep's FTW
c

curved-television-6568

03/22/2023, 2:47 PM
agree with adding more details to the peek output.
there’s also information now about the source line where the target is declared within the BUILD file
that could be useful to expose for custom tooling..
w

wide-midnight-78598

03/22/2023, 2:49 PM
You read my mind 🙂 I want to open the BUILD file and line on click of the targets in the Pants IDE window
As well as provide some context (e.g.
cc_binary
and on context menu click, you can
package
it or whatever)
This would eventually allow us to run these commands in the codelens as well, which would be seamless
b

bitter-ability-32190

03/22/2023, 2:50 PM
We should sync up 👀
w

wide-midnight-78598

03/22/2023, 2:53 PM
So sad right now....
😅 1
c

curved-television-6568

03/22/2023, 2:53 PM
thought I had an issue logged for this, but not. also related is to address https://github.com/pantsbuild/pants/pull/18383#issuecomment-1448999983
w

wide-midnight-78598

03/22/2023, 2:59 PM
Oh neat, I never knew you could
peek
multiple targets - always assumed it was a 1 target kinda thing
game changer
👍 1
c

curved-television-6568

03/22/2023, 3:00 PM
list output would’ve been a hint 😉
w

wide-midnight-78598

03/22/2023, 3:01 PM
Ha! Didn't even notice
🙃 1
c

curved-television-6568

03/22/2023, 3:56 PM
w

wide-midnight-78598

03/22/2023, 3:59 PM
👍
Interestingly, I don't even know where to get the build filename from. I assume it would be in internals.build_files, but I didn't see the name mentioned
b

bitter-ability-32190

03/22/2023, 4:02 PM
Attach a debugger and poke around a
Target
instance?
c

curved-television-6568

03/22/2023, 4:05 PM
hmm unstructured right now, as my idea at the time was for error messages and the like https://github.com/pantsbuild/pants/blob/7fca4215f67b3756bd2ac723cb4cefcf83273ab3/src/python/pants/build_graph/address.py#L60
eh… wait wrong line
w

wide-midnight-78598

03/22/2023, 4:06 PM
The file is available to the Rust engine, I think I saw that - just wasn't sure if exposed to Python... Must be somewhere though
path/to/buildfile:targetname
? That's not how parse works, is it? Isn't it the path to the folder?
c

curved-television-6568

03/22/2023, 4:08 PM
yea, the buildfile is not part of itr
hah! it’s not merged.. here I’m chasing ghosts https://github.com/pantsbuild/pants/pull/18366
If you’re in pants rule land, you can ask for an address’s
AddressFamily
that will have the BUILD file path (including filename of the thing itself I believe)
w

wide-midnight-78598

03/22/2023, 4:12 PM
Oh! That's dope
c

curved-television-6568

03/22/2023, 4:14 PM
or there abouts, maybe it’s still just the path to the directory…
e

enough-analyst-54434

03/23/2023, 3:45 PM
Isn't grep just fine for this?
w

wide-midnight-78598

03/24/2023, 4:56 AM
So, yeah, more or less - that's a workaround for my current usecase. I'm using peek to show targets in VS Code, and I would like clicking on the target or the containing "folder" to open the associated BUILD file. Normally trivial, except in the situation where the user uses a custom BUILD file pattern. So, I can either run a child process/shell that greps the location of those targets, or (what I'm doing now), grabbing the build_patterns array from help, and then checking if a file exists for each one - then opening the correct one. While I'm loathe to propose an API change to peek strictly to satisfy this use case - I have been digging around and it looks like the Pants API treats BUILD files mostly transparently
2 Views