0

How can I set up my entrypoints so that I can access all functions in module1 from the command line as mod1.function_name args kwargs?

The module has a script that contains a set of functions, some with args and some with optional kwargs. I would like to be able to do the following from cli:

  • mod1.squared 5
  • mod1.squared 5 y=4
  • mod1.cubed 5

I tried adding the following to the setup.cfg file, but it returns mod1.squared command not found. Mypackage is installed in editable mode in the venv.

[options.entry_points]
console_scripts =
    mod1 = mypackage.module1.all_functions
**Example directory:**

D:.
|   .gitignore
|   LICENSE
|   pyproject.toml
|   README.md
|   setup.cfg
|   
+---.venv
+---data
+---mypackage
|   |   __init__.py
|   |   
|   +---module1
|   |   |   src.py
|   |   |   all_functions.py
|   |   |   
|   +---module2
|   |   |   src.py
|   |   |   all_functions.py
|   |   |   
|   |           
|   +---tools
|   |       tools.py
|   |               
|       
\---tests

Example contents of module1.all_functions.py:

# some other functions that rely on module1.src, ignore here
def squared(x, *, y=None):
    if y is None:
        y=1
    return (x + y) ** 2

def cubed(x):
    return (x) ** 3

Example contents of __init__.py:

from module1 import all_functions as mod1
a11
  • 3,122
  • 4
  • 27
  • 66

0 Answers0