I'm trying to set up some docs via `mkdocs` I have...
# general
s
I'm trying to set up some docs via
mkdocs
I have a BUILD file in
docs
Copy code
file(
    name="mkdocs_yml",
    source="mkdocs.yml",
)

files(
    name="docs",
    sources=["docs/*.md"],
)

pex_binary(
    name="serve",
    entry_point="mkdocs",
    args=["serve", "-f", "docs/mkdocs.yml", "--no-livereload"],
    restartable=True,
    dependencies=[
        ":mkdocs_yml",
        ":docs",
        "//:reqs#mkdocs"
    ]
)
and a directory structure like
Copy code
docs/
  mkdocs.yml
  docs/
    index.md
When I run
pants --loop run docs:serve
I expect pants to restart
mkdocs serve
if I make a change to
docs/index.md
but that's not the case. If I manually cancel ``pants run docs:serve`` and restart it I can see my changes so I know things are wired up correctly. I'm using v2.17.0
TIL you can run a requirement. I'll just do
pants run //:reqs#mkdocs -- serve -f docs/mkdocs.yml
instead
c
Yup, pretty cool. Worth noting it that the requirement must provide a
__main__
module in it’s package for it to work though. So it won’t work with all requirements.
e
Hrm, that's unfortunate its still like that. Binding to the console script makes more sense. Hopefully most tools with a console script support
-m <root-package>
.
Yeah, a console script is your brand if you present a CLI. Here's one popular one, although this is a weird way to run it: Current:
Copy code
$ pex ruff -m ruff -- -h
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
...
  File "/home/jsirois/.pex/installed_wheels/8e087b24d0d849c5c81516ec740bf4fd48bf363cfb104545464e0fca749b6af9/ruff-0.0.292-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl/ruff/__main__.py", line 34, in <module>
    ruff = find_ruff_bin()
  File "/home/jsirois/.pex/installed_wheels/8e087b24d0d849c5c81516ec740bf4fd48bf363cfb104545464e0fca749b6af9/ruff-0.0.292-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl/ruff/__main__.py", line 30, in find_ruff_bin
    raise FileNotFoundError(path)
FileNotFoundError: /home/jsirois/.local/bin/ruff
Console Script binding:
Copy code
$ pex ruff -c ruff -- -h
Ruff: An extremely fast Python linter.

Usage: ruff [OPTIONS] <COMMAND>

Commands:
  check   Run Ruff on the given files or directories (default)
  rule    Explain a rule (or all rules)
  config  List or describe the available configuration options
  linter  List all supported upstream linters
  clean   Clear any caches in the current directory and any subdirectories
  help    Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Log levels:
  -v, --verbose  Enable verbose logging
  -q, --quiet    Print diagnostics, but nothing else
  -s, --silent   Disable all logging (but still exit with status code "1" upon detecting diagnostics)

For help with a specific command, see: `ruff help <command>`.
h
Hmm, with
restartable=True
you should get auto-restarting when deps change. Can you put up a small repo on github that reproduces the error? Would be good to capture your exact config and so on.
s
If I change files and file to resources and resource the
loop
command behaves as expected. Is that expected behavior?
https://github.com/yjabri/pants-restartable edit - since there's nothing interesting here I'm going to delete the repo
Admittedly I missed the resources fix in the original repo. I just tried again and it seems to take 10+ seconds
h
Yes, that makes sense in that the files are not baked into the pex, I should have noticed that
in fact I'm surprised they were visible when you ran the pex, might have been by sheer chance that they were available by the right path relative to the CWD
And that 10+ seconds is because you're rebuilding a new .pex every time
You can avoid this when you
pants run path/to/main.py
instead of
pants run path/to:pex
, but in your case there is no main.py, since you're just building a pex directly from a third-party wheel
s
Okay one mystery down - The reason that it was slow in the original repo but not the new minimal one is because I had an extra dependency on "mkdocs-material" (via a mapping in the root BUILD). I get that the files aren't baked into the Pex but I'm surprised that files don't even show up in the sandbox when I run
Copy code
$ pants --keep-sandboxes=always run docs:serve
20:37:42.28 [INFO] Preserving local process execution dir /tmp/pants-sandbox-BhJYIN for interactive process
INFO    -  Building documentation...
INFO    -  Cleaning site directory
INFO    -  Documentation built in 0.04 seconds
INFO    -  [20:37:42] Serving on <http://127.0.0.1:8000/>
But you're right, it still works if you remove the files/file targets and dependencies so this was just luck it even worked in the first place. Edit - I had some incorrect assumptions about how sandboxes worked. After working through this example, I think I have a better grasp! Thanks for all of the help