2024-09-28 21:25:33 发布
网友
我想弄清楚如何让一个模块独立运行(作为CLI)和作为另一个模块的子模块运行(作为API)。你知道吗
最小示例:http://www.filedropper.com/submoduleconfusion-master
对于文件结构:
假设有一个函数位于SubmoduleConfusion.mod_a.mod_a中,那么我将使用from mod_a.mod_a import f
SubmoduleConfusion.mod_a.mod_a
from mod_a.mod_a import f
由于modèa也可以作为自己的独立模块运行
from mod_a import f
最好的办法是使模块pip可安装(添加设置.py外部(从模块路径向上1步),带有控制台脚本的入口点。你知道吗
https://github.com/jtara1/misc_scripts/tree/master/misc_scripts/templates
我用这个模板设置.py以及设置.cfg在我创建的大部分模块中。它使用setuptools\u scm,它将使用项目的git版本(标记)来定义项目中的版本设置.py. 你知道吗
换句话说,您需要在尝试安装模块或上载模块之前git tag 0.1.0和git push tags。你知道吗
git tag 0.1.0
git push tags
我的设置.py还将推断模块的名称与父目录的名称相同(github项目名称)
所以目录应该是这样的
我的\u模块
当前在中的设置函数中定义的别名设置.py,以后可能会将其移动到变量
https://github.com/jtara1/misc_scripts/blob/master/misc_scripts/templates/setup.py#L113
最好的办法是使模块pip可安装(添加设置.py外部(从模块路径向上1步),带有控制台脚本的入口点。你知道吗
https://github.com/jtara1/misc_scripts/tree/master/misc_scripts/templates
我用这个模板设置.py以及设置.cfg在我创建的大部分模块中。它使用setuptools\u scm,它将使用项目的git版本(标记)来定义项目中的版本设置.py. 你知道吗
换句话说,您需要在尝试安装模块或上载模块之前
git tag 0.1.0
和git push tags
。你知道吗我的设置.py还将推断模块的名称与父目录的名称相同(github项目名称)
所以目录应该是这样的
我的\u模块
当前在中的设置函数中定义的别名设置.py,以后可能会将其移动到变量
https://github.com/jtara1/misc_scripts/blob/master/misc_scripts/templates/setup.py#L113
相关问题 更多 >
编程相关推荐