echoing-midnight-41324
01/27/2025, 1:21 AMshell_command. Why can't I run it using pants run :mycommand? I need to use this instead of run_shell_command because the latter doesn't run the command inside pants' sandbox.careful-address-89803
01/27/2025, 4:15 AMpants run is that it's for things that happen inside of the current workdir. So run_shell_command would be for things that you want to run in the workdir (eg maintenance commands and utilities). shell_command is intended for steps that are part of the build process, which is why it has output_files and output_directories.
Our doc on running shell commands is a little thin; please let us know how we can improve it!square-psychiatrist-19087
01/27/2025, 10:18 AMshell_command and produce output files use export-codegen goalechoing-midnight-41324
01/27/2025, 3:56 PMexport-codegen during development? Semantically, it doesn't make a lot of sense.
I guess another option would be to use run_shell_command + sourcing the exported python venv, but that would include all dependencies (instead of the ones connected with execution_dependencies).
Eventually, it would be cool to have some kind of sandbox option on run_shell_command... just a thought.echoing-midnight-41324
01/27/2025, 3:59 PMpants run goal. If you need to run it without starting the build process, use the pants export-codegen goal"square-psychiatrist-19087
01/27/2025, 4:02 PMshell_command is that it is not supposed to have side effects. For example, you have a text file in pants and you want to produce a new file by filtering rows with grep, this is what you do with a shell_command. Similarly, adhoc_tool is used for the same kind of thing but is more powerful, because it can run any runnable target, e.g. you can build a python pex then run it to produce a new output file.
If you want some sort of side effect, you need to use something else like run_shell_command or maybe docker_image or just manually run a shell scriptechoing-midnight-41324
01/27/2025, 4:03 PMexport-codegen. Because my command is a dev server, expects user interaction, and doesn't produce any files. It just exited without running the server...echoing-midnight-41324
01/27/2025, 4:03 PMsquare-psychiatrist-19087
01/27/2025, 4:04 PMSo there's no great way to reduce the number of deps (i.e. I need to load the python venv)?I'm not sure I understand the question
square-psychiatrist-19087
01/27/2025, 4:05 PMechoing-midnight-41324
01/27/2025, 4:05 PMechoing-midnight-41324
01/27/2025, 4:06 PMsource venv/bin/activateechoing-midnight-41324
01/27/2025, 4:06 PMsquare-psychiatrist-19087
01/27/2025, 4:06 PMpex_binary, it will include all necessary dependencies without problems with venvsechoing-midnight-41324
01/27/2025, 4:07 PMechoing-midnight-41324
01/27/2025, 4:08 PMflask --app main --debug run command, so I'd have to convert that into a standalone python file somehowsquare-psychiatrist-19087
01/27/2025, 4:10 PMflask.run(debug=True)echoing-midnight-41324
01/27/2025, 4:14 PMechoing-midnight-41324
01/27/2025, 4:15 PMsquare-psychiatrist-19087
01/27/2025, 4:15 PM# run.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
if __name__ == "__main__":
app.run(debug=True)square-psychiatrist-19087
01/27/2025, 4:15 PM# pants.toml
[GLOBAL]
pants_version = "2.23.0"
backend_packages = [
"pants.backend.python",
]
[python]
enable_resolves = true
default_resolve = "python-default"
interpreter_constraints = [">=3.12,<3.13"]square-psychiatrist-19087
01/27/2025, 4:15 PM# BUILD
python_requirement(name="flask", requirements=["flask"])
python_sources()
pex_binary(name="app", entry_point="run.py")echoing-midnight-41324
01/27/2025, 4:15 PMsquare-psychiatrist-19087
01/27/2025, 4:16 PM$ pants run :app
* Serving Flask app 'run'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on <http://127.0.0.1:5000>
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 782-899-796echoing-midnight-41324
01/27/2025, 4:16 PMsquare-psychiatrist-19087
01/27/2025, 4:18 PMBut and issue I'm anticipating: pants only lets you run one command at a time, right?
If I need to run multiple python servers, would I need to use a python based multiplexer, or would it still be possible to use mprocs?That's a good question, short answer is yes, pants doesn't have tools to run multiple things at once
square-psychiatrist-19087
01/27/2025, 4:21 PMechoing-midnight-41324
01/27/2025, 4:22 PM