Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use single shiv zipapp/pyz for multiple python scripts #230

Closed
sudarshanvm opened this issue Nov 24, 2022 · 1 comment
Closed

How to use single shiv zipapp/pyz for multiple python scripts #230

sudarshanvm opened this issue Nov 24, 2022 · 1 comment

Comments

@sudarshanvm
Copy link

Suppose I have 3 files : requirements.txt, module1.py and module2.py
I need to bake a single shiv executable with all the dependencies specified inside requirements.txt and later I want to use the same shiv executable for running module1.py as well as module2.py

can we do something like:

  • bake shiv using shiv requirements.txt -o shiv.pyz
  • to run module1.py, export SHIV_ENTRY_POINT=module1:main and then ./shiv.pyz should run the module1 script
  • to run module2.py, export SHIV_ENTRY_POINT=module2:main and then ./shiv.pyz should run the module2 script

does this work? do we have any alternative to do that?

Thanks, Sudarshan

@lorencarvalho
Copy link
Contributor

Hi @sudarshanvm,

A pyz created with shiv should work exactly as you describe. In fact, internally at LinkedIn we sometimes package multiple CLIs that share a set of dependencies this way. Another option is to use the pyz as the shebang for a script, like so:

$ shiv httpx -o httpx.pyz --quiet
$ cat << EOF > tryme.py
> #!/usr/bin/env httpx.pyz
>
> import httpx
> url = "https://shiv.readthedocs.io"
> response = httpx.get(url)
> print(f"Got {response.status_code} from {url}!")
>
> EOF
$ chmod +x tryme.py
$ ./tryme.py
Got 200 from https://shiv.readthedocs.io!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants