spkenv / spk

A Package Manager for high velocity software environments, built on spfs.
https://spkenv.dev
Apache License 2.0
34 stars 5 forks source link

Support Shebang Invocation #18

Open rydrman opened 3 years ago

rydrman commented 3 years ago

It would be great if there was a subcommand or option which would allow spk to be referenced directly in a shebang line, for example:

#!/usr/local/bin/spk env python/3 -- python

print("Hello from spk python!")

Currently shebang only allows for one argument, so this gets called as spk "env python/3 -- python" script.py which would need to be recognized and re-parsed by the spk command line in order to function as expected

alexxbb commented 2 years ago

Something along this lines?

#!/usr/bin/bash

""":"
echo "Im in bash"
spk env python/3 -- python $0
":"""
rydrman commented 2 years ago

From the meeting today: we like the idea, can we provide consistent behavior that is predictable?

  1. spk-interpreter as a separate binary
  2. if the subcommand contains a space, then assume it's an argument list and parse it

Let's go with option number 2 (re-parse if a space is in there)

lgritz commented 2 years ago

Just to clarify @alexxbb's comment, since we talked about it today on the SPI internal chat:

He's not proposing that instead of Ryan's shebang idea. He's pointing out that as a workaround for this today, you can take a python script you have already and lightly edit it like this to make it run itself inside a particular spk environment (by disguising it as a bash script that launches the env, then runs the remainder of its contents as python):

#!/usr/bin/bash
""":"
spk env python/3.7 openimageio/=2.3.9.1 -- python $0
":"""

import OpenImageIO as oiio
... rest of python script, running python 3.7 and importing openimageio 2.3.9.1 from spk ...