I'd like to figure out how to have a module act independently (as CLI) and as a submodule for another module (as API).
Minimal example: http://www.filedropper.com/submoduleconfusion-master
For file structure:
Suppose there's some function that's located in SubmoduleConfusion.mod_a.mod_a
then I'd use from mod_a.mod_a import f
Since mod_a can also be run as it's own independent module,
For file structure:
from mod_a import f
The best thing to do is to make the module pip installable (add setup.py outside 1 step up from module path) with an entry point for a console script.
https://github.com/jtara1/misc_scripts/tree/master/misc_scripts/templates
I use this template setup.py and setup.cfg in most of my module I've created. It uses setuptools_scm which will use the version (tag) from git for the project to define the version within the setup.py.
In other words, you need to git tag 0.1.0
and git push --tags
before trying to install the module or upload it to be installed.
My setup.py will also infer the name of the module is the same name as the parent directory (github project name)
so the directory should look something like this
my_module
name of alias currently defined within setup function within setup.py , might move it to variable later
https://github.com/jtara1/misc_scripts/blob/master/misc_scripts/templates/setup.py#L113
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments