-1

Let's say we have a small bash project, with no more than a handful of files, and it depends on jq and curl.
Can we, perhaps by adding a bit of wrapper Python code, make such a bash project pip installable?

For example, could we make the following bash project installable with pip?

#!/usr/bin/env bash

source dir/some_file.bash       # Sources some trivial bash code

# Here we make use of our dependencies:
curl --silent wttr.in/Paris?format=j1 | jq .current_condition

./other_dir/another_file.bash   # Executes some trivial bash code

To clarify: The call pip install our_project, should completely install our project, including its dependencies.

melvio
  • 762
  • 6
  • 24
  • 1
    Do you expect installing your program with pip to also install jq and curl? (If not, why mention them?) – Charles Duffy Aug 13 '21 at 19:26
  • 1
    (you can package your bash script in a Python wrapper, but since neither curl or jq are packaged that way, you won't be able to have pip install them -- whereas if you used [Nix](https://nixos.org/) as your packaging format, that _could_ install your non-Python-native dependencies -- including bash itself, for that matter, if the local OS doesn't provide a new enough one). – Charles Duffy Aug 13 '21 at 19:27
  • 1
    To provide a pointer that'll put you in the direction of answering your own question (without adding an answer, because I think abusing pip this way is a horrible idea and don't intend to support it), see the `package_data` attribute in `setup.py`. – Charles Duffy Aug 13 '21 at 19:29
  • 2
    Assuming you are aiming at Ubuntu, you need to look at the Debian tools to build your own `.deb` package. It's not hard, and it can automatically fetch dependencies. – Tim Roberts Aug 13 '21 at 19:36
  • 1
    Thanks @Charles. Great comment. I have modified the question to address your remark. I'm completely willing to accept an answer that says: "please don't do this because you'll run into issue x,y,z". That way, when others search for this question, they learn why they shouldn't do this. Sometimes the best answer is: "No, try this instead." ;-) – melvio Aug 13 '21 at 19:39
  • 1
    ...or a `.spec` file to build a RPM for Fedora/CentOS/etc, or a `PKGBUILD` to build a native package for Arch Linux, etc. – Charles Duffy Aug 13 '21 at 19:39
  • That said, the Python standard library provides alternatives to both curl and jq, so if you were willing to make your shell script call into Python, you could eliminate the need to install non-Python tools. – Charles Duffy Aug 13 '21 at 19:51
  • 1
    Yes, it's possible. Not advisable, but possible. Create an [sdist](https://docs.python.org/3/distutils/sourcedist.html) and in its `setup.py` create a [post-install script](https://stackoverflow.com/a/36902139/7976758). In that post-install script you can do anything including installing non-Python dependencies. Install your non-Python scripts as [`package_data`](https://stackoverflow.com/search?q=%5Bsetuptools%5D+%22package_data%22) – phd Aug 13 '21 at 21:23
  • @phd, ...that works if pip is pointing to a sdist and thus invoking a setup.py; not so much if it's trying to install a wheel. I don't remember offhand if eggs support post-install scripts -- but either way, the code at hand would need to figure out _how_ to install packages for the active Linux distro (if in fact the host OS is Linux at all), it's really just kicking the can down the road; somewhere, you still need to have knowledge of how to install packages on whatever distro is in use. – Charles Duffy Aug 13 '21 at 21:47
  • @phd, ...btw, I did mention package_data [in an earlier comment](https://stackoverflow.com/questions/68777470/can-a-bash-project-be-made-pip-installable?noredirect=1#comment121548730_68777470). – Charles Duffy Aug 13 '21 at 21:48
  • 1
    @CharlesDuffy Yep, the 1st link in my comment clearly explains that post-install only works with sdists, not wheels. Eggs are no longer supported by `pip` so they out of the picture completely. – phd Aug 13 '21 at 22:04

1 Answers1

1

No, pip install does not install non-Python dependencies such as jq or curl. It is designed only to install Python projects -- and while you can bundle your bash script inside a Python project, jq and curl are not bundled that way.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Upvoted because you are trying to discourage a bad idea. @Charles, can I persuade you to nuance your answer? For example, by incorporating @phd comment *"Create an `sdist` and in its `setup.py` create a post-install script"*, and your response *"the code at hand would need to figure out how to install packages for the active Linux distro"*. IMHO, this is a strong reason to find a more suitable package management solution. Likely one that you or @TimRoberts suggested. Regardless, I appreciate your good intentions @Charles. – melvio Aug 14 '21 at 06:19