Gillespie
Gillespie

Reputation: 6561

setup.py put top level module in subdirectory

I have a project that looks like this:

tool.py
utils/
    tool2.py
    tool3.py

I would like to bundle these into a distribution such that I can call tool or tool2 or tool3 from the command line. But so far I can't figure out how to make setup.py include the scripts under utils/ without creating a new utils python module. Basically I want to do this in setup.cfg without changing my directory layout:

[options.entry_points]
console_scripts =
    tool = tool:main
    tool2 = tool2:main
    tool3 = tool3:main

If I flatten my project directory so that all 3 are in the root directory, it works, but there are potentially many utility tools that I don't want spamming up the root directory. But it seems like if I put them under utils that setup.py wants to create them as submodules under a utils module.

One potential workaround is to just do:

[options]
scripts =
    tool.py
    utils/tool2.py
    utils/tool3.py

but then you have to always type the .py suffix to invoke from the commandline whereas I would prefer to leave it off so it feels more "command-liny".

Is what I'm trying to do possible?

Upvotes: 0

Views: 332

Answers (1)

Gillespie
Gillespie

Reputation: 6561

I worked around the issue by doing something like:

[options]
scripts =
    dist_scripts/tool
    dist_scripts/tool2
    dist_scripts/tool3

Where dist_scripts/tool was a relative softlink to tool.py, etc. Seems to work fine.

Upvotes: 1

Related Questions