Skip to main content

No project description provided

Project description

yaclipy

Yet another python command-line interface…

This is similar to python-fire with a few important distinctions:
  • Parameter types are defined by the function definition and not by what was given on the command line

  • Sub commands are given explicitly. This gives the ability to show and create documentation for sub commands without executing them. You can still call methods of the returned values though.

  • Better documentation of the commands.

Define functions and annotate them with a @CLI decorator. Then those functions can be called from the command line.

Get Started

Create a file named cli.py (or anything) with the following code. Make it executable: chmod +x cli.py.

#!/usr/bin/env python
import os, sys
from subprocess import call # Just in case the system python is crazy-old
from os.path import join, abspath, split, exists

VENV_DIR='.python' # This can be moved if needed

def abort(*reason):
    print('\n'+'!'*75,'\nERROR:', *reason)
    print('Look above for the specific error.','\n'+'!'*75,'\n')
    import shutil
    shutil.rmtree(VENV_DIR, ignore_errors=True)
    sys.exit(1)

os.chdir(split(abspath(__file__))[0]) # Make the cwd the same as this file
if sys.prefix == sys.base_prefix: # Not in the virtual env
    new = not exists(VENV_DIR)
    if new and call(['python3', '-m','venv',VENV_DIR]):
        abort("Couldn't create python3 virtual environment at", VENV_DIR)
    os.environ['PATH'] = join(VENV_DIR,'bin') + os.pathsep + os.environ['PATH']
    if new and call(['python', '-m', 'pip', 'install', 'yaclipy']):
        abort("Couldn't install yaclipy into the virtual environment")
    os.execvp('python', ['python', './cli.py'] + sys.argv[1:])

# Now we are running in the virtual environment.  Turn control over to yaclipy
from yaclipy.boot import bootstrap
bootstrap(sys.argv[1:])

This file simply bootstraps a project-local virtual environment VENV_DIR, installs yaclipy into it and then turns control over to yaclipy.

Next create a requirements.txt file which holds the package dependencies that need to be installed into the virtual environment.

# *NOTE*
# If you edit this file then delete the `requirements.lock`
# file and run `./cli.py` to update the new dependencies

PyYAML
numpy
# etc...

Finally, you can start using cli.py.

$ ./cli.py -h

Installation

Don’t install this package manually. Instead use the bootstrapping method show in Get Started.

$ pip install yaclipy # Don't do this!
https://img.shields.io/pypi/v/yaclipy.svg https://img.shields.io/pypi/pyversions/yaclipy.svg

Test

$ hatch shell
$ pytest

License

yaclipy is distributed under the terms of the MIT license.

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

yaclipy-0.0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yaclipy-0.0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file yaclipy-0.0.1.tar.gz.

File metadata

  • Download URL: yaclipy-0.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for yaclipy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 61f833c52ce7d1dff1ac3cb108634a4dad680248a126dbb40bdb10dc05e4141d
MD5 0239e4b2c7cbf44b1d5717b30434b99e
BLAKE2b-256 ceba4799776f2bbfddd7efb213b7c47a5492ba6cd8c170e783bf657c4a14740c

See more details on using hashes here.

File details

Details for the file yaclipy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: yaclipy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for yaclipy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8fdb1ff3cb88b8391876e9ceba1f65ce9d661b126dc68474044001051ab3b63e
MD5 d0b5a32aa43885ae93c88b3189c3d5cf
BLAKE2b-256 6c9bc8baf22ac09e2ffa2289e4212eb1b36de51bd3ec62aa99e327976c86b8f8

See more details on using hashes here.

Supported by

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