Determine version of package to install via bash command's output in Poetry

Question:

I am trying to install a Python package via Poetry whose version to install should be determined based on the output (~return value) of a Bash command.

Is it possible doing something (in the pyproject.toml) along the lines of:

[tool.poetry.dependencies]
python = "^3.8"
this-package = "^$(path-to-executable --version)"

where $(path-to-executable --version) is the bash command call that would output a version?

Ideally, without having to run a script/Makefile/"""something""" on top of Poetry (as this Git thread seems to point to)

Specifically, this is because I’m trying to install GDAL. We don’t use too advanced features, so pretty much any version would do. However, the Python package to be installed depends heavily on the version of the Gdal’s executable (and its libraries) that is installed in the system. Which can be determined running gdal-config --version in a terminal. In my case (Ubuntu 18.02), that command returns 2.2.3, but in never Ubuntu will return something higher.

So, I’m trying to make the dependency resolution in Poetry’s pyproject.toml a liiiiitle bit dynamic: Whomever is trying to install my package would still need to install libgdal-dev and other dependencies, but I’d like it to be a tiiiiiny bit dynamic so they don’t have to edit the pyproject.toml file to fill up their version of Gdal. Also, this is for internal use, so it only needs to work in Linux-like systems (no Windows or Apple)

Thank you in advance!

Asked By: BorrajaX

||

Answers:

I’m also trying to keep the pyproject.toml GDAL version in sync with the installation, but I’m doing it the other way around: use the version from Poetry to install the system library.

Unfortunately Poetry doesn’t yet have a way to get just the package version, but after a bit of finagling I ended up with this: sudo apt-get --assume-yes install libgdal-dev="$(poetry show gdal | tr --delete ' ' | grep '^version:' | cut --delimiter=':' --fields=2)*". It gets the version which will be installed; it doesn’t need to be already installed. (Fortunately Poetry doesn’t format the output with ANSI colour codes when passing to a pipe.)

Answered By: l0b0