如何在托管在Nexus上的私有的PyPI repo中指定依赖项?

本文介绍了如何在托管在Nexus上的私有的PyPI repo中指定依赖项?的处理方法,对大家解决问题具有一定的参考价值

问题描述

我无法在私有的PyPI存储库(托管在Sonatype Nexus存储库管理器,Voss 3.17.0-01上)中的包上生成依赖于包的python轮子。

如果我使用pip,我可以搜索并安装该程序包;我的问题是尝试让setup.py执行相同的操作。从各种命令的输出来看,我认为问题可能是由于存储库提供的包链接中的相对路径造成的。

搜索类似的问题,其中大多数与私有git存储库有关。我能找到的看起来最相关的问题是Equivalent for `--find-links` in `setup.py`。评论正文指出
在setuptools上下文中,dependency_links选项接受...包含直接下载链接的网页的URL

但是,提供链接页面是为了支持报价不再包含该文本(是否被较新版本替换?)

所以这可能就是问题所在--而且我尝试做事情的方式不受支持。如果是这样的话,有没有人能建议一种可行的方法?

或者,这可能是安装工具中的错误,或者我们Nexus的错误配置问题-如果有人可以证实或驳斥这些理论-并再次建议一种可行的方法-我将不胜感激。

以下是我的设置和各种命令的输出,显示了哪些命令有效,哪些命令无效:

  1. 设置环境:

    mkdir depends-fail
    cd depends-fail
    python3 -m venv venv
    source activate venv/bin/activate
    pip install --upgrade pip
    pip install wheel        # So we can use bdist_wheel build option.
    
  2. 确认当前PIP版本:

    (venv) $ pip --version
    pip 21.0.1 from /tmp/depends-fail/venv/lib/python3.6/site-packages/pip (python 3.6)
    
  3. 确认setupTools版本:

    (venv) $ python -c "import setuptools as s; print(s.version.__version__)"
    39.0.1
    
  4. depends-fail目录中,创建这个最小的setup.py文件,它将演示问题:

     from setuptools import setup
     setup(
       name='failed-dependencies',
       install_requires=['data-feed-ping>=0.5'],
       dependency_links=[
         'http://nexus.example.local/nexus/repository/pypi-playground-public/simple/data-feed-ping',
       ]
    )
    
  5. 确认我们的依赖项在我们的专用存储库中可用:

     (venv) $ pip search --trusted-host nexus.example.local 
     >  -i http://nexus.example.local/nexus/repository/pypi-playground-public/pypi 
     >  data-feed-ping
    

    响应确认包在本地可用:

    ⋮
    Starting new HTTP connection (1): nexus.example.local:80
    http://nexus.example.local:80 "POST /nexus/repository/pypi-playground-public/pypi HTTP/1.1" 200 239
    data-feed-ping (0.5)  - Determine response times of data feeds.
    
  6. 以下是我们尝试构建和测试最小程序包(它是触发依赖项下载的测试选项)时发生的情况:

    (venv) $ python setup.py bdist_wheel test
    

    包生成时没有问题-但找不到依赖项:

        running bdist_wheel
        running build
        ⋮
        removing build/bdist.linux-x86_64/wheel
        running test
        Searching for data-feed-ping>=0.5
    (1) Reading http://nexus.example.local/nexus/repository/pypi-playground-public/simple/data-feed-ping
    (2) Downloading http://nexus.example.local/nexus/repository/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336
        error: Can't download http://nexus.example.local/nexus/repository/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336: 
        404 Repository not found
    
  7. (2)中的下载链接和版本散列来自在(1)处读取的索引URL的内容-让我们看看该文件是什么样子:

    (venv) $ curl http://nexus.example.local/nexus/repository/pypi-playground-public/simple/data-feed-ping
    
    <html lang="en">
    <head><title>Links for data-feed-ping</title><meta name="api-version" value="2"/></head>
      <body><h1>Links for data-feed-ping</h1><!-- links to previous versions -->
        <a href="../../packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336" rel="internal">data_feed_ping-0.5-py3-none-any.whl</a><br/>
      </body>
    </html>
    

索引URL确实提供了到所需版本的数据馈送ping包的链接,并且安装脚本正确地从该链接获取了MD5摘要(请参见脚本输出中的(2))。但是,安装脚本随后会尝试从无效的URL下载该文件。

在我看来,问题似乎是索引链接提供的相对路径。如果我们从索引URL(1)开始:

http://nexus.example.local/nexus/repository/pypi-playground-public/simple/data-feed-ping

并添加下载的相对路径:

../../packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336

我得到以下绝对路径:

http://nexus.example.local/nexus/repository/pypi-playground-public/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336

我已确认该绝对路径指向我想要的包:

(venv) $ wget http://nexus.example.local/nexus/repository/pypi-playground-public/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336

--2021-04-01 16:44:18--  http://nexus.example.local/nexus/repository/pypi-playground-public/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl
Resolving nexus.example.local (nexus.example.local)... 192.168.24.136
Connecting to nexus.example.local (nexus.example.local)|192.168.24.136|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19066 (19K) [application/zip]
Saving to: ‘data_feed_ping-0.5-py3-none-any.whl’
data_feed_ping-0.5-py3-none-any 100%[==========================================>]  18.62K  --.-KB/s    in 0s
2021-04-01 16:44:18 (76.3 MB/s) - ‘data_feed_ping-0.5-py3-none-any.whl’ saved [19066/19066]

如果我尝试使用pip直接下载包,并指定安装脚本使用的相同索引URL:

,我也没有问题
   (venv) $ pip install --trusted-host nexus.example.local 
   >  --index-url http://nexus.example.local/nexus/repository/pypi-playground-public/simple 
   >  data-feed-ping

   Looking in indexes: http://nexus.example.local/nexus/repository/pypi-playground-public/simple
Collecting data-feed-ping
   Downloading http://nexus.example.local/nexus/repository/pypi-playground-public/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl (19 kB)
   Requirement already satisfied: requests in ./venv/lib/python3.6/site-packages (from data-feed-ping) (2.25.1)
   ⋮
   Installing collected packages: data-feed-ping
   Successfully installed data-feed-ping-0.5

推荐答案

您应该只使用pip(或任何其他安装程序)来安装Python项目。例如,通过调用python setup.py install进行安装是一种过时的做法(通常不起作用)。因此,您可能应该删除setup.pydependency_links参数,并指示您的用户使用正确的pip标志进行安装,正如您在问题末尾所示:

python -m pip install --trusted-host nexus.example.local 
   >  --index-url http://nexus.example.local/nexus/repository/pypi-playground-public/simple 
   >  data-feed-ping

以同样的方式python setup.py test:也是过时的/不推荐的,您可能会被很好地建议转移到更现代的测试运行程序(我想到的是pytest,但可能还有其他的,可能是Nose)。

这篇关于如何在托管在Nexus上的私有的PyPI repo中指定依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1173

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1071

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this-&gt;id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:809

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this-&gt;id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:900

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:931

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:879

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:865

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:834

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1735

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1309