Skip to content

amrox/conanw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

conanw

A stupid-simple1 Conan installer / runner, inspired by gradlew.

1 This README is longer than the script itself.

Why?

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.

Warning

This mini-project is very young and may be a silly idea in general.

Quick Start

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.

Basic Usage

Generally you want to use conanw just like conan:

./conanw frogarian

There are a few extra features though.

Install Conan without actually running conan

./conanw --cw-check

Re-install Conan

Removes the existing virtualenv and re-installs conan.

./conanw --cw-reinstall

Get information about the Conan install

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

Controlling the Conan version

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"

Requirements & Compatibility

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

Tips and Tricks

direnv integration

I'm a huge fan of direnv and conanw is designed to work with it.

See example .envrc

Known Issues and Future Work

  • If conan is installed and conanw is invoked (without --cw-check) it will not check CONANW_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. Currently conanw does not integrate with this value at all.

License

MIT

About

conan installer / runner wrapper

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages