社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Git

写入设置。py在install_中使用git repo需要检测已安装的

Betterthan Kwora • 4 年前 • 2059 次点击  

我有一个带有git+ssh依赖项的包,如下所示:

setup(
    name="setuprequires",
    version="0.1",
    packages=["setuprequires"],
    install_requires=[
        r"hello-world @ git+ssh://git@github.com/hello/hello-world.git#egg=hello-world"
    ],  
)

(我正在追踪最新的答案。) here 关于git回购依赖关系。)

但是,我想跳过安装 hello-world 如果它已经安装在我当前的环境中。然而,如果我跑 pip install -e . 两次,第二次仍将克隆 你好,世界 .相比之下,如果我刚刚 install_requires=[r"hello-world"] ,它会正确地检测到这个要求已经得到满足。

在我看来 git+ssh 无法很好地检测已经满足的需求。我认为 #egg=hello-world 会解决这个问题的。我错过什么了吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131215
文章 [ 1 ]  |  最新文章 4 年前
Peter Badida
Reply   •   1 楼
Peter Badida    5 年前

要检测存储库是最新的(或使用了某个提交),您需要首先克隆它,因此,要使缓存存在,即使它试图从缓存中获取它,您仍然需要首先克隆它。

在第一次克隆之后 应该 将其与现有的克隆存储库进行比较。

由于您还没有指定任何提交,我猜它仍然会因此而被拉。看见 Git._should_fetch() 类方法。

相反,请尝试指定要使用的提交/标记, as mentioned in the docs ,它应该开始缓存:

git+https://git.example.com/MyProject.git@<hash>#egg=MyProject
git+https://git.example.com/MyProject.git@<tag>#egg=MyProject
git+ssh://git.example.com/MyProject.git@<hash>#egg=MyProject
git+ssh://git.example.com/MyProject.git@<tag>#egg=MyProject

编辑:

我注意到,如果使用分支,缓存就会被破坏。不是 refs/... ,所以它不是显式的远程分支拉取,也不是散列。然而,对于提交散列,它可以完美地工作,并将创建的控制盘存储在 --cache-dir 然后在第2次+执行 pip install 命令( bug created )

例子:

from setuptools import setup

setup(
    name="testing-git",
    install_requires=[
        # cached properly
        "requests @ git+ssh://git@github.com/psf/requests.git@cd4762d5a3b56d8933d1d9c1dff365fc5db4c768#egg=requests-3.0"
        # not cached
        # "requests @ git+ssh://git@github.com/psf/requests.git@3.0#egg=requests-3.0"
    ]
)