Packaging A Docopt CLI Application

242 Views Asked by At

I want to package my Docopt app which consist of one class file and an other file which imports the class file and implements Docopt (https://gist.github.com/itsnauman/4d9e40459ff56106edcf). How should I package it so that I only enter the package's name $ package_name --help and it executes?

1

There are 1 best solutions below

0
On

You will need a setup.py file in the root folder of your project. It has to contain something in the line of:

from setuptools import setup

setup(
    name = "mypackage",
    version = "0.1",
    description = "Description",
    packages = ["mypackage"],
    long_description = "",
    namespace_packages = ['mypackage'],
    scripts = ['scripts/script.py'] )

You could just include the docopt source in your mypackage folder, as docopt is not very long, and this will remove the dependency also.

The folder structure for this example should look like:

project-root/
    mypackage/
        __init__.py
        myclass.py
    scripts/
        script.py

In script.py you would then do:

from mypackage import myclass

From the project root you can now run: python setup.py install or python setup.py develop.