And possibly similar to above, is there a CLI comm...
# development
w
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
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
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
Huh?
w
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
Right, you could peek the target name then filter the result
w
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
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
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
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
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
We should sync up 👀
w
So sad right now....
😅 1
c
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
Oh neat, I never knew you could
peek
multiple targets - always assumed it was a 1 target kinda thing
game changer
👍 1
c
list output would’ve been a hint 😉
w
Ha! Didn't even notice
🙃 1
c
w
👍
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
Attach a debugger and poke around a
Target
instance?
c
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
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
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
Oh! That's dope
c
or there abouts, maybe it’s still just the path to the directory…
e
Isn't grep just fine for this?
w
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