Skip to content

A small selection of custom PantsBuild plugins

License

Notifications You must be signed in to change notification settings

sureshjoshi/pants-plugins

Repository files navigation

pants-plugin

A small selection of custom PantsBuild plugins.

Usage

Install Pants via PantsBuild's instructions, or use brew via brew install pantsbuild/tap/pants.

Plugins

VS Code Configuration

In order to get intellisense working correctly in VS Code, here are the relevant items to look at:

pants.toml

Ensure the following:

  • pants.backend.plugin_development setup inside backend_packages
  • There is a separate resolve for your plugin directory, matching the Pants required interpreter (3.9 right now)
backend_packages = [
    "pants.backend.plugin_development",
    ...
]

[python]
enable_resolves = true
interpreter_constraints = ["==3.9.*"]
tailor_pex_binary_targets = false

[python.resolves]
pants-plugins = "build-support/lockfiles/pants-plugins.lock"
python-default = "build-support/lockfiles/python-default.lock"

[python.resolves_to_interpreter_constraints]
pants-plugins = [">=3.9,<3.10"]

requirements

In the plugin root folder, there is a BUILD file containing the following (where the resolve is the same name that you setup in pants.toml):

pants_requirements(name="pants", resolve="pants-plugins")

.vscode/settings.json

In the past, this setting appears to help the VS Code intellisense auto-complete.

{
  "python.analysis.packageIndexDepths": [
    { "name": "pants", "depth": 5, "includeAllSymbols": true }
  ]
} 

venv

Generate the lockfile (very important if pants_version changes, so you're using the updated pants wheel). Then, export the resolve and setup VS Code to use that venv.

pants generate-lockfiles --resolve=pants-plugins # This is important if you've upgraded your pants version
pants export --resolve=pants-plugins

# Use this venv in VS Code 
Wrote mutable virtualenv for pants-plugins (using Python 3.9.19) to dist/export/python/virtualenvs/pants-plugins/3.9.19

You can also symlink the exported directory to .venv or similar, as VS Code tends to automatically pick those up.

Important: Do not activate the venv and run commands, or you'll get a complaint about using the pants launcher binary.