2 questions: (1) Is there a recepie how multiple ...
# general
f
2 questions: (1) Is there a recepie how multiple “pants run”… could be ran concurrently? (2) Is there a way to auto-refresh “pants run” if something changed in code?
g
1. Yes, using
PANTS_CONCURRENT=true
. See caveats here though: https://www.pantsbuild.org/docs/reference-global#concurrent 2. Yes, but depends on the target. On some targets you can set
restartable=True
in your BUILD file and it should work: https://www.pantsbuild.org/docs/reference-python_sources#coderestartablecode. I tend to to use a method which combines
pants --loop package ...
with another subprocess to pick up the produced artifact and runs it outside pants. It depends a bit on the semantics.
❤️ 1
As an example; this is a shim we use to iterate on mdbook docs in our repo:
Copy code
import http.server
import os
import socketserver
import subprocess
import threading
from functools import partial

def pants(*args):
    return subprocess.check_output(
        [
            "pants",
            *args,
        ],
        env=os.environ
        | {
            "PANTS_CONCURRENT": "true",
        },
    )


class Server(socketserver.TCPServer):
    allow_reuse_address = True


def build_docs():
    pants("--loop", "package", "docs:docs")


def main():
    threading.Thread(target=build_docs).start()

    Handler = partial(http.server.SimpleHTTPRequestHandler, directory="dist/docs/book/")
    server = Server(("", 8000), Handler)
    server.allow_reuse_address = True

    with server as httpd:
        httpd.serve_forever()


main()
This technically isn't parallel, it's nested - we use
pants run scripts/docs.py
(through the alias
pants serve-docs
). The ones where we do use parallel work are much longer unfortunately. 😛
👍 1