Ale*_*vey 3 python setuptools setup.py
我正在尝试从 Git 存储库中的源代码构建 pip 包,该存储库具有多个共享公共包的包。(我不允许更改此 Git 存储库的结构。)
\n结构是:
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 common\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 run_helpers\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 aws.py\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 s3.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 components\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 redshift_unload\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 redshift_unload\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 run.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 setup.py\nRun Code Online (Sandbox Code Playgroud)\n我的setup.py如下:
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 common\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 run_helpers\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 aws.py\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 s3.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 components\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 redshift_unload\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 redshift_unload\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 run.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 setup.py\nRun Code Online (Sandbox Code Playgroud)\n看看这里的其他答案,到目前为止我尝试过的事情包括:
\npackages=而不是使用find_packages().where="../../"到find_packages()find_packages() + find_packages(where="../../") in the packages=` 行。packages_dir一线。当我运行时pip install .,包安装得很好,但是当我运行已安装的 python 脚本时,我得到:
from setuptools import setup, find_packages\n\nsetup(\n ...\n packages=find_packages(),\n package_dir={"": "."},\n entry_points={\n "console_scripts": ["redshift_unload=redshift_unload.run:main"]\n }\n)\nRun Code Online (Sandbox Code Playgroud)\n做了什么工作:
\ncommon目录移动到components/redshift_unload,那么它就可以正常工作。但我不能这样做。我还尝试在其位置放置一个符号链接,但似乎也不起作用。有办法让这项工作发挥作用吗?
\n我相信我已经找到了最好的解决方案。
根据这里的评论,我得出的结论是,我想做的事情并非有意或不受支持。
但是,我发现以下解决方法效果很好:
from pathlib import Path
from shutil import rmtree, copytree
from setuptools import setup, find_packages
src_path = Path(os.environ["PWD"], "../../common")
dst_path = Path("./common")
copytree(src_path, dst_path)
setup(
...
packages=find_packages(),
package_dir={"": "."},
entry_points={
"console_scripts": ["redshift_unload=redshift_unload.run:main"]
}
)
rmtree(dst_path)
Run Code Online (Sandbox Code Playgroud)
这里的关键见解是,当打包发生在临时目录中时, 的值os.environ["PWD"]可供进程使用,这样可以临时复制公共目录,然后再次清理(使用shutil函数copytree和rmtree)到将找到的位置在调用find_packages()该函数之前。setup()
| 归档时间: |
|
| 查看次数: |
1522 次 |
| 最近记录: |