我将setuptools
用于python打包,在其中我以setup.py文件中的常用方式定义控制台脚本入口点:
setup.py
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(...
name='my_project',
entry_points={'console_scripts':['my_entry_name=my_package.scripts.my_python_script:main'
]},
...
)
安装软件包后,我可以从这样的批处理文件中调用此入口点:
my_CURRENT_batch_file.command
#!/bin/bash
cd "$(dirname "$0")" # set the working directory as the command file locations
~/anaconda3/envs/my_env_name/bin/entry_point_name <my script args>
虽然这可行,但虚拟环境的使用使我在入口点调用之前包含了所有路径信息,在我看来,这确实破坏了入口点应该提供给脚本使用者的简单性。有没有办法让setuptools
在系统范围内注册入口点,以便我可以在没有这样的路径的情况下调用入口点?:
my_DESIRED_batch_file.command
#!/bin/bash
cd "$(dirname "$0")" # set the working directory as the command file locations
entry_point_name <my script args>
没有虚拟环境带来的复杂性,控制台脚本入口点使脚本使用者可以使用脚本,而不必知道脚本的安装位置或编写的语言。即使在以下情况下,我也希望保持这种简单性:在虚拟环境中打包。
我尝试过的-安装软件包后,我在虚拟环境中找到了实际的入口点文件:
/anaconda3/envs/my_env/bin/my_entry_name
并将此文件的副本放置在主bin路径中:
/anaconda3/bin/my_entry_name
并且发现我可以根据需要在没有路径的情况下调用入口点,但是我不想让脚本使用者去做这是一个手动步骤。为此,是否有一种方法可以使setuptools
将入口点文件放置在常规bin路径中,而不是环境bin或其他一些自动方式中?
我的设置