A stupid-simple1 Conan installer / runner, inspired by gradlew.
1 This README is longer than the script itself.
Isolated development environments keep me sane. Conan can already manage project level dependencies like CMake, ninja, or protoc.
But how do we install Conan itself in an isolated way? The Conan documentation "strongly recommends" using virtualenvs to isolate Conan from other python dependencies. Sure, we could use docker but I find it cumbersome to wrap command line that interact with the local filesystem.
Virualenvs should be very familiar to Python developers, but Conan is a primarily C/C++ tool, and C/C++ developers should not be expected to know about Python dependency management.
This little script aims to "do the right thing" by installing Conan in a virtualenv, without needing to expose others to the concept.
This mini-project is very young and may be a silly idea in general.
Download the conanw
script and add it to your repository.
curl -O https://raw.githubusercontent.com/amrox/conanw/main/conanw
chmod +x conanw
You probably also want to add .conan-venv/
to your .gitignore
.
The first time you run conanw
it will download and install an isolated conan
. Then it will act as a simple wrapper for that Conan installation.
./conanw
conanw: Creating a new python virtual env at /Users/amrox/Projects/conanw/.conanw-venv
conanw: Installing conan ...
<conan install output>
conanw: conan active at /Users/amrox/Projects/conanw/.conanw-venv/bin/conan
Consumer commands
install Installs the requirements specified in a recipe (conanfile.py or conanfile.txt).
config Manages Conan configuration.
<rest of conan help ouput>
Subsequent runs of conanw
will just delegate directly to conan.
Generally you want to use conanw
just like conan
:
./conanw frogarian
There are a few extra features though.
./conanw --cw-check
Removes the existing virtualenv and re-installs conan
.
./conanw --cw-reinstall
Print the path to our conan
:
./conanw --cw-path
/Users/amrox/Projects/conanw/.conanw-venv/bin/conan
Print the dir which contains our conan
. Useful to add it to your PATH
./conanw --cw-dir
/Users/amrox/Projects/conanw/.conanw-venv/bin
export PATH=$(./conanw --cw-dir):$PATH
which conan
/Users/amrox/Projects/conanw/.conanw-venv/bin/conan
See also: direnv integration
By default, conanw
will just grab the latest version of Conan. If you want a specific version (or version range), you can supply a version specifier via the CONANW_CONAN_VERSION_SPEC
environment variable. This value is passed directly to pip
.
Examples:
Exact version:
CONANW_CONAN_VERSION_SPEC="==1.32.0" ./conanw --cw-check
Range:
CONANW_CONAN_VERSION_SPEC=">=1.32.0,<2" ./conanw --cw-check
The CONANW_CONAN_VERSION_SPEC
variable can also be read from an optional .conanw.conf
file:
CONANW_CONAN_VERSION_SPEC=">=1.32.0,<2"
conanw
assumes you have python3
with the venv
module. This is built in to many Python distributions. On Ubuntu you may have to do:
sudo apt-get install python3-venv
conanw
has been lightly testing in the following environments:
- macOS 10.5
- Ubuntu 18.04
I'm a huge fan of direnv and conanw
is designed to work with it.
See example .envrc
- If
conan
is installed andconanw
is invoked (without--cw-check
) it will not checkCONANW_CONAN_VERSION_SPEC
. This is to avoid surprising the user with an install/upgrade when it may not be strictly necessary. We may want an option to control this behavior, or at least print a warning. - A required Conan version can be specified in
conanfile.py
. Currentlyconanw
does not integrate with this value at all.