RobotPajamas / suspenders

Keep those Pants up
MIT License
14 stars 2 forks source link

unhandled default import in BUILD #132

Open kdowney-talos opened 4 days ago

kdowney-talos commented 4 days ago

Even after generating LSP files, I get an (invalid) warning about referencing python_artifact() from python_distribution(), as shown in this screenshot:

undefined_python_artifact

Maybe that symbol is missing? The targets themselves are correctly picked up.

This is with v0.0.3 pre-release on latest VSCode with pants 2.23.0.

sureshjoshi commented 3 days ago

Thanks for the report. Is python_artifact available as a top-level function? There were a handful of functions that caused grief when I was writing the pyi file, maybe that was one of them.

kdowney-talos commented 3 days ago

Yep that appears to be the issue -- in all the examples Pants has it as a top-level function, but it flags as unimported.

sureshjoshi commented 3 days ago

Okay, thanks, I'll look into it. I had made a bunch of Suspenders improvements on one of my computers that I accidentally wiped, thinking I'd already pushed all my code. So, have to go back and re-write all that stuff. 🤦🏽

I'll take a look at this as well.

kdowney-talos commented 3 days ago

Thanks. If there is any way I can help lmk. I was starting on a buck2 VSCode plugin when I switched to Pants.

sureshjoshi commented 3 hours ago

Whelp, that's the problem 😄

Screenshot 2024-12-04 at 15 28 23

kdowney-talos commented 3 hours ago

I looked in Pants source code, and it's in pants.backend.python.macros.python_artifact. PythonArtifact isn't visible to the LSP either, so what's the workaround?

sureshjoshi commented 3 hours ago

Using a few backends, and some JQ, I can see there aren't many type_hints that aren't clean python, but they need to be handled.

pants help-all | jq '.. | .type_hint? // empty'

"str | http_source | pants.core.target_types.per_platform[pants.core.target_types.http_source]"
"PythonArtifact"

And in Pants mainline, there are a few JVM type_hint instances. Very few overall.

I'm going to dig around and see if I'm missing some extracted types, and in the short term, I'll probably just hardcode a list of fixes. The goal is that Pants itself handles all of this, and I'm prototyping some ideas to have a faster LSP interaction, as using the command line is really slow.

sureshjoshi commented 3 hours ago

In looking at it, the more fundamental issue is that the stuff in https://www.pantsbuild.org/stable/reference/build-file-symbols/ aren't exported in the script, but more than that, they're not well defined in the help either.

That might be something to look into and improve on the Pants side.

sureshjoshi commented 2 hours ago

@kdowney-talos I PRd a bit of a hack solution, where we export the rest of the build symbols, and then I added a PythonArtifact stub, and have the python_artifact/setup_py return that.

In reality, those are basically dict wrappers, so it's all a bit strange from the start.