Skip to main content

A simple library for building command-line arguments

Project description

Quickstart

argcomb (argument combiner) is a simple utility that allows you to build complex command-line arguments in a modular fashion.

To install it:

pip install argcomb

Suppose we want to run the following combination of commands (e.g., if you're doing a hyperparameter sweep):

echo train --eta 0.1 --num-iters 5 --greedy
echo train --eta 0.1 --num-iters 5
echo train --eta 0.1 --num-iters 10 --greedy
echo train --eta 0.1 --num-iters 10

You can write the following argcomb program (called example1.py in this repo):

from argcomb import *

run(
    "echo", "train",
    arg("eta", 0.1),
    selarg(None, "num-iters", 5, 10),
    sel(None, [], arg("greedy")),
)

Here run takes a (hierarchical) list of arguments to be concatenated. Special functions like sel allow us to specify the selection/iteration over multiple possible values in place (as opposed to having a big for loop on the outside).

To run it:

# Actually executes the commands
python example1.py

# Print out the commands rather than execute them
python example1.py -n

We can also use environment variables (e.g., @mode) to parametrize the runs. For example:

from argcomb import *

run(
    "echo", "train",
    let_if_undefined("@mode", "slow"),  # Set default
    sel("@mode", {
        "fast": [arg("num-iters", 5), arg("greedy")],
        "slow": arg("num-iters", 10),
    }),
    arg("output", fmt("@mode.out")),
)

To run it:

python example.py             # slow (default)
python example.py @mode=fast  # fast

Development

Handy commands:

# Install environment
virtualenv -p python3.7 venv
venv/bin/pip install -r requirements.txt

# Format code (skip `example*.py`)
venv/bin/black -t py37 argcomb test_argcomb.py

# Do type checking
venv/bin/python -m mypy argcomb test_argcomb.py example*.py

# Run unit tests
venv/bin/python -m pytest test_argcomb.py

# Build PyPI package and deploy it
venv/bin/python setup.py sdist
venv/bin/twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argcomb-1.0.1.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file argcomb-1.0.1.tar.gz.

File metadata

  • Download URL: argcomb-1.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for argcomb-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c5d884f80e3c2071f6d5b910960d666a16dbac5e7f3b5d6fd5b800ae0d78e77e
MD5 5548561fe679a0c8348b6e2190d8482d
BLAKE2b-256 de66e8fd90b282bc6153f89718967dd19d786485c9570b97b15a8dfc4337c8d9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page