brettcannon, (edited )
@brettcannon@fosstodon.org avatar

With https://peps.python.org/pep-0723/ being accepted, I'm starting to think about how to implement it for https://python-launcher.app/ .

I'm leaning towards the py command implicitly detecting the block of TOML and doing the "right" thing automatically. The other option is making the functionality opt-in via a py run subcommand. I don't see enough benefit to warrant the subcommand, but I figured I would gut-check this in case I'm missing some workflow where this would be a concern.

So, which UX?

encukou,

@brettcannon What's the right thing, though?
If it's to silently create/update an isolated venv for that specific script, I'll think twice about using /// script. Especially with hefty dependencies like NumPy or Qt.
And if it asks by default, you might be turning scripts meant for unattended execution into interactive CLI apps.

brettcannon,
@brettcannon@fosstodon.org avatar

@encukou There is no "right thing", else I wouldn't be asking. 😉

And I'm not sure what "silent" means to you, but I would expect a simple spinner w/ details like what pipx shows in either scenario.

encukou,

@brettcannon That would work for me, as long as I have a few seconds where Ctrl+C rolls everything back :)

brettcannon,
@brettcannon@fosstodon.org avatar

@encukou To be clear, any installation would be into a virtual environment in your /tmp directory, so nothing is being trampled or permanently kept. So if pip does the right thing in that instance then you would get what you want.

encukou,

@brettcannon That sounds close to the right thing!
Beware that /tmp is a ramdisk by default on many modern distros. You don't want to install Tensorflow there. You probably want to use $XDG_STATE_HOME (~/.local/state), and clean it periodically.

brettcannon,
@brettcannon@fosstodon.org avatar

@encukou Thanks for the info/suggestion! Can I ask why not to use $XDG_CACHE_HOME since the loss of the virtual environment isn't detrimental?

zech,

@brettcannon I feel that any command that can do anything extra should be clearly different from the usual command.

Consider a project that comes with helper scripts. It should be clear that running those scripts may install additional dependencies and should be more closely vetted. A distinct command will serve to make that possibility more clear.

brettcannon,
@brettcannon@fosstodon.org avatar

@zech It is clear if you read the source which you should do, else the script could do something nuts like https://pip.wtf/ regardless of PEP 723 and thus the command makes no difference.

graham_knapp,
@graham_knapp@hachyderm.io avatar

@brettcannon either way I would normally expect py to run in an environment I had already built. I would want to explicitly confirm downloading and installing things, e.g. because py or py run detected the block and asked me to confirm.

brettcannon,
@brettcannon@fosstodon.org avatar

@graham_knapp Why would you expect an environment you set up to be used when the script has specified distinct requirements?

graham_knapp,
@graham_knapp@hachyderm.io avatar

@brettcannon I mean I would not expect a tool to install new things without explicit permission - "pip install" or "conda install" explicitly says please install some stuff. "py myfile.py". Even if I read the file I might not expect the comments to have the side effect of downloading, installing and running code. (thinking as a general python user, e.g. my colleagues, rather than someone who has read the pep, ie me)

graham_knapp,
@graham_knapp@hachyderm.io avatar

@brettcannon I guess I could live with auto-install with abundantly clear logging and Ctrl-C to cancel but that's cutting my own nose off. :)

brettcannon,
@brettcannon@fosstodon.org avatar

@graham_knapp To be clear, any installation would be into a virtual environment in your /tmp directory, so nothing is being trampled or permanently kept.

graham_knapp,
@graham_knapp@hachyderm.io avatar

@brettcannon I think part of my unease comes from "py" sounding like a shortcut for python (which it kind of is on Windows) and part comes from the existing "py my_script.py" command taking on a different behaviour.

brettcannon,
@brettcannon@fosstodon.org avatar

@graham_knapp To me, the command means, "make my Python code run", not just a convenient alias for the python binary.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • ngwrru68w68
  • modclub
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • GTA5RPClips
  • JUstTest
  • tacticalgear
  • normalnudes
  • tester
  • osvaldo12
  • everett
  • cubers
  • ethstaker
  • anitta
  • provamag3
  • Leos
  • cisconetworking
  • megavids
  • lostlight
  • All magazines