云客户?
免费开始>
在MyJFrog >中升级
云有什么新>







概述

Artifactory全力支持PyPI存储库提供:

  1. 提供PyPI包从Artifactory到皮普来自所有存储库类型的命令行工具。
  2. 为托管在Artifactory本地存储库中的PyPI包计算元数据。
  3. 访问远程PyPI存储库(例如https://pypi.org/)透过远程存储库它提供代理和缓存功能。
  4. 从一个URL访问多个PyPI存储库的能力虚拟存储库
  5. 兼容性setuptools以及它的前身distutils用于上传PyPI包的库。


在Windows上运行

要在Windows上使用Artifactory PyPI存储库,请确保s .et Python和Pip所需的环境变量。

注意,在Windows平台上,% % \ pip \ pip.ini回家取代了pip.conf以下部分描述的文件,应该可以通过HOME路径访问。


配置

局部存储库

要创建一个新的PyPI本地存储库,请从政府模块选择存储库|存储库|本地并点击新建本地存储库并设置包类型PyPI。

页面内容

远程存储库

一个远程存储库在Artifactory中定义的缓存代理,用于在远程URL上管理的注册中心,例如https://pypi.python.org/

从远程存储库请求的工件(例如.whl文件)将根据需要缓存。您可以从远程存储库缓存中删除下载的构件,但是您不能手动将构件部署到远程PyPI存储库。

要创建一个存储库来代理远程PyPI存储库,请遵循以下步骤:

  1. 政府模块下存储库|存储库|远程,并点击新的远程存储库
  2. 设置包类型PyPI然后进入库的关键价值。

  3. URL和注册URL设置取决于您是代理公共外部PyPI存储库,还是托管在另一个Artifactory服务器上的PyPI存储库。
    对于一个公共的、外部的PyPI存储库:改变URL字段https://files.pythonhosted.org/,并设置注册网址字段https://pypi.org/



    对于托管在另一个Artifactory实例上的PyPI存储库:中设置远程存储库的PyPI API URL注册网址字段。例如,代理一个名为“python项目,由Artifactory实例托管https://my.remote.artifactory/artifactory/,你会设置注册网址https://my.remote.artifactory/artifactory/api/pypi/python-project如下图所示:


    PyPI远程存储库URL

    你不应该包括api / pypi/简单在PyPI远程存储库URL这些后缀在访问远程存储库时由Artifactory添加。

    如果使用自定义PyPI远程存储库,则需要确保它具有简单的索引(目录列表风格)可以访问< URL > /简单

  4. 点击保存&完成

    远程Artifactory

    如果远程存储库也是由Artifactory服务器管理的,那么您需要在注册网址字段。例如,http://my.remote.artifactory/artifactory/api/pypi/python-project

虚拟存储库

Artifactory中定义的虚拟存储库聚合来自本地和远程存储库的包。
这允许您从为虚拟存储库定义的单个URL访问本地托管的PyPI包和远程代理的PyPI存储库。
要定义虚拟PyPI存储库,请从政府模块,转到存储库|存储库|虚拟,设置其包类型的基础本地和远程PyPI存储库基本设置选项卡,单击保存&完成



从Artifactory使用pip解决

安装皮普命令行工具参考PIP文档页.我们建议使用virtualenv在安装PIP时分离您的环境。

使用pip和Artifactory的有效SSL证书

pip只在包的下载URL是具有有效SSL证书的受信任主机时才使用来自本地缓存的包(即来自运行pip客户机的机器)。这意味着,如果您的Artifactory实例没有使用有效的SSL证书运行,那么对包的请求总是首先到达Artifactory,即使包存在于本地缓存中。


显示可用于配置的代码段皮普而且setup . py要使用您的PyPI存储库,请选择存储库,然后单击给我介绍。


在命令行上指定存储库

指数的URL

当通过Artifactory访问PyPI存储库时,存储库URL应该以…为前缀api / pypi在路上。这适用于所有人皮普命令和distutilsurl包括pip安装。

当使用皮普来解析它必须指向的PyPI包/pypi// .简单的

例如,如果您使用Artifactory独立或作为本地服务,您将使用以下URL访问您的PyPI存储库:

http://localhost:8081/artifactory/pypi /<库关键> /简单的

或者,如果您正在使用Artifactory Cloud, URL将是:

https:// < server name > .jfrog.io / artifactory /pypi /<库关键> /简单的


一旦pip被安装,它可以用来指定存储库的URL来解析:

使用完整的存储库URL安装
$ PIP install frog-bar -i http://localhost:8081/artifactory/api/pypi/pypi-local/simple

Nginx和Apache使用反向代理的默认配置片段包含X-JFrog-Override-Base-Url默认情况下。如果在您的环境中没有使用反向代理,则需要手动向请求添加报头,例如:

-H "X-JFrog-Override-Base-Url: http://$ART_HOST"

除了手动添加头,你还可以在端口8081上运行请求,或者在请求的末尾添加斜杠(/):

http:// $ ART_HOST / artifactory / api / pypi / pypi-virtual /简单/

使用凭证

由于它的设计,pip不支持从文件中读取凭据。例如,凭证可以作为URL的一部分提供http://<用户名>:<密码> @localhost: 8081 / artifactory / api / pypi pypi-local /简单密码可以省略(使用前面的冒号),在这种情况下,将提示用户交互式地输入凭据。

配置文件方式

不同存储库的别名可以通过pip配置文件指定,~ / .pip / pip.conf.该文件包含每个存储库的配置参数,例如:

~ / .pip / pip.conf
[global] index-url = http://user:password@localhost:8081/artifactory/api/pypi/pypi-virtual/simple

如需更多资料,请参阅PIP用户指南

使用需求文件

需求文件包含要安装的包的列表。通常这些是当前包的依赖项。对象可以手动创建或使用皮普冻结命令。索引URL可以在文件的第一行指定,例如:

——index-url http://localhost:8081/artifactory/api/pypi/pypi-local/simple PyYAML==3.11 argparse==1.2.1 frog-bar==0.2 frog-fu==0.2a nltk==2.0.4 wsgirf ==0.1.2



发布到Artifactory

使用distutils或setuptools

Setuptools vs. distutils和python版本

Artifactory不知道你是否使用setuptoolsdistutils,以及项目使用的Python的版本或实现。

下面的指令是为Python 2.7和setuptools在心里的。使用Python的不同版本,或者不同的工具热情,distutils其他的可能需要对下面的说明进行细微的修改。

上传到Artifactory使用setup . py脚本的支持方式与上传到PyPI类似。首先,需要为用户添加Artifactory作为索引服务器。

有关使用说明setuptools来打包Python项目并创建一个setup . py脚本,请参考setuptools文档而且本教程项目

创建$HOME/。pypirc文件

要上传到Artifactory,需要为每个存储库创建一个条目$ HOME / .pypirc如下:

[distutils] index-servers = local pypi [pypi] repository: https://pypi.org/pypi username: mrBagthrope password: notToBeSeen [local] repository: http://localhost:8081/artifactory/api/pypi/pypi-local username: admin password:密码

注意,URL不是以/简单

HOME环境变量

setuptools要求.pypirc文件可在$ HOME / .pypirc,使用首页环境变量。

在类unix系统上,这通常由您的系统设置为/home/yourusername /但在某些环境中,如构建服务器,您将不得不手动设置它。

在Windows上必须手动设置。

上传认证的PyPI包到JFrog Artifactory

上传认证的PyPI包到JFrog Artifactory:

  1. 创建.pypirc使用下面的代码创建文件,并从JFrog Artifactory为用户名添加访问令牌pypiadmin

    [distutils] index-servers = private-repository [private-repository] repository = https://soleng.jfrog.io/artifactory/api/pypi/demo-pypi-local username = pypiadmin password =eyJ2ZXIiOiIyIiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYiLCJraWQiOiJsYkpadzNJUU13WXBBSWNRa01RRjN0dlA2Yml5M3dWcXdrQ0txUkxLaXhRIn0.eyJleHQiOiJ7XCJyZXZvY2FibGVcIjpcInRydWVcIn0iLCJzdWIiOiJqZmFjQDAxZTlycTMza3ljMHQxMWtwangybmcwemo1XC91c2Vyc1wvcHlwaWFkbWluIiwic2NwIjoiYXBwbGllZC1wZXJtaXNzaW9uc1wvYWRtaW4iLCJhdWQiOiIqQCoiLCJpc3MiOiJqZmZlQDAwMCIsImV4cCI6MTY4OTY5ODA5MywiaWF0IjoxNjU4MTYyMDkzLCJqdGkiOiJiZWY1YWY5Ni0zNTkyLTRiOTQtYWYyNS1kZmIxY2U1ZGU4YzIifQ.NI5OXpw0NHs7Asd3f_sY3tMyzM-2_07c3WyWEpbJrDPxO8eKoLRp10vGEF8Jo3HyRQ0H7Ybzf2-Cn8wf9yFMo4UGlgxGfm7_yc24xWVLCINjg0B2A5YRSvAetwdT2wgVPvEMUqCPSCU4_SGgGg606lIDxxImRfgZWwFn-wHfU8b8dCV7EV4dXGvH7iVb33W2JguE9KIQFP7lKkQlaErO6pGFNuPfOx1JbJllHh0oRpAPzvykda2i6Q2q3ZCObJZ9Rp8NqZYQfEm42YtIaOvAlE5fGepZgDjzHaaLcztJDHoR-BWjMiDfP0LRThHASo7F52t8p3vsZHW5NEov_trFrQ
  2. 复制.pypirc文件到“用户”文件夹。
      • 对于macOS用户,在下面创建文件% USERPROFILE %
      • 对于Windows用户,在下面创建文件c: \用户\ <名称>
  3. 验证setup . py文件包含以下所有字段。它应该是自动创建的,但如果不是,请将该文件添加到您的根文件夹,包含以下内容。

    # !/usr/bin/env python from setuptools导入setup setup(name='demo-python-example', version='1.0', description='使用JFrog产品构建python项目的项目示例',author='JFrog', author_email='jfrog@hth华体会最新官方网站m.si-fil.com', packages=['helloworld'], install_requires=['PyYAML>3.11', 'nltk'],)
  4. 创建一个PyPI包。

    Py setup.py sdist bdist_wheel

    输出示例如下。

    C:\Users\johnk\helloworld>py setup.py sdist bdist_wheel running sdist running egg_info写入demo_python_example。蛋-info\PKG-INFO writing dependency_links to demo_python_example.egg-info\dependency_links.txt writing requirements to demo_python_example.egg-info\requires.txt writing top-level names to demo_python_example.egg-info\top_level.txt reading manifest file 'demo_python_example.egg-info\SOURCES.txt' writing manifest file 'demo_python_example.egg-info\SOURCES.txt' warning: sdist: standard file not found: should have one of README, README.rst, README.txt, README.md running check creating demo-python-example-1.0 creating demo-python-example-1.0\demo_python_example.egg-info creating demo-python-example-1.0\helloworld copying files to demo-python-example-1.0... copying setup.py -> demo-python-example-1.0 copying demo_python_example.egg-info\PKG-INFO -> demo-python-example-1.0\demo_python_example.egg-info copying demo_python_example.egg-info\SOURCES.txt -> demo-python-example-1.0\demo_python_example.egg-info copying demo_python_example.egg-info\dependency_links.txt -> demo-python-example-1.0\demo_python_example.egg-info copying demo_python_example.egg-info\requires.txt -> demo-python-example-1.0\demo_python_example.egg-info copying demo_python_example.egg-info\top_level.txt -> demo-python-example-1.0\demo_python_example.egg-info copying helloworld\app.py -> demo-python-example-1.0\helloworld Writing demo-python-example-1.0\setup.cfg Creating tar archive removing 'demo-python-example-1.0' (and everything under it) running bdist_wheel running build running build_py C:\Users\johnk\installs\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( installing to build\bdist.win-amd64\wheel running install running install_lib creating build\bdist.win-amd64\wheel creating build\bdist.win-amd64\wheel\helloworld copying build\lib\helloworld\app.py -> build\bdist.win-amd64\wheel\.\helloworld running install_egg_info Copying demo_python_example.egg-info to build\bdist.win-amd64\wheel\.\demo_python_example-1.0-py3.10.egg-info running install_scripts creating build\bdist.win-amd64\wheel\demo_python_example-1.0.dist-info\WHEEL creating 'dist\demo_python_example-1.0-py3-none-any.whl' and adding 'build\bdist.win-amd64\wheel' to it adding 'helloworld/app.py' adding 'demo_python_example-1.0.dist-info/METADATA' adding 'demo_python_example-1.0.dist-info/WHEEL' adding 'demo_python_example-1.0.dist-info/top_level.txt' adding 'demo_python_example-1.0.dist-info/RECORD' removing build\bdist.win-amd64\wheel C:\Users\johnk\helloworld>
  5. 上传包到JFrog Artifactory。

    Py setup.py sdist upload -r private-repository

    输出示例如下。

    C:\Users\johnk\helloworld>py setup.py sdist bdist_wheel running sdist running egg_info写入demo_python_example。蛋-info\PKG-INFO writing dependency_links to demo_python_example.egg-info\dependency_links.txt writing requirements to demo_python_example.egg-info\requires.txt writing top-level names to demo_python_example.egg-info\top_level.txt reading manifest file 'demo_python_example.egg-info\SOURCES.txt' writing manifest file 'demo_python_example.egg-info\SOURCES.txt' warning: sdist: standard file not found: should have one of README, README.rst, README.txt, README.md running check creating demo-python-example-1.0 creating demo-python-example-1.0\demo_python_example.egg-info creating demo-python-example-1.0\helloworld copying files to demo-python-example-1.0... copying setup.py -> demo-python-example-1.0 copying demo_python_example.egg-info\PKG-INFO -> demo-python-example-1.0\demo_python_example.egg-info copying demo_python_example.egg-info\SOURCES.txt -> demo-python-example-1.0\demo_python_example.egg-info copying demo_python_example.egg-info\dependency_links.txt -> demo-python-example-1.0\demo_python_example.egg-info copying demo_python_example.egg-info\requires.txt -> demo-python-example-1.0\demo_python_example.egg-info copying demo_python_example.egg-info\top_level.txt -> demo-python-example-1.0\demo_python_example.egg-info copying helloworld\app.py -> demo-python-example-1.0\helloworld Writing demo-python-example-1.0\setup.cfg Creating tar archive removing 'demo-python-example-1.0' (and everything under it) running bdist_wheel running build running build_py C:\Users\johnk\installs\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( installing to build\bdist.win-amd64\wheel running install running install_lib creating build\bdist.win-amd64\wheel creating build\bdist.win-amd64\wheel\helloworld copying build\lib\helloworld\app.py -> build\bdist.win-amd64\wheel\.\helloworld running install_egg_info Copying demo_python_example.egg-info to build\bdist.win-amd64\wheel\.\demo_python_example-1.0-py3.10.egg-info running install_scripts creating build\bdist.win-amd64\wheel\demo_python_example-1.0.dist-info\WHEEL creating 'dist\demo_python_example-1.0-py3-none-any.whl' and adding 'build\bdist.win-amd64\wheel' to it adding 'helloworld/app.py' adding 'demo_python_example-1.0.dist-info/METADATA' adding 'demo_python_example-1.0.dist-info/WHEEL' adding 'demo_python_example-1.0.dist-info/top_level.txt' adding 'demo_python_example-1.0.dist-info/RECORD' removing build\bdist.win-amd64\wheel C:\Users\johnk\helloworld>
  6. 您的包已成功上传到JFrog平台。通过导航到查看应用程序>Artifactory>工件寻找包裹。

上传

在创建.pypirc文件和setup . py脚本在你的项目的根,你可以上传你的鸡蛋(tar.gz)包如下:

~/python_project $ python setup.py sdist上传-r local

如果你正在使用车轮(whl),你可以按以下方式上传你的软件包:

~/python_project $ python setup.py bdist_wheel upload -r local .py

如果你想同时使用鸡蛋(tar.gz)和车轮(whl),可按以下方式上载:

~/python_project $ python setup.py sdist bdist_wheel upload -r local .py

在哪里当地的你的书里有这部分的名字吗.pypirc指向Artifactory PyPI存储库的文件。

默认的上传

默认情况下,两者setuptools而且distutils将上传至https://pypi.org/pypi如果未指定存储库。

'register'命令应该省略

当直接上传至pypi.org文档说明您的包必须先注册通过调用python setup . py登记。

当上传到Artifactory时,这既不需要也不支持应该省略

通过Web UI或REST方式手动发布

PyPI包也可以使用Web UI或者是Artifactory REST API.为了让Artifactory正确地将这些包作为PyPI包来处理,它们必须被上传pypi.name而且pypi.version属性。

自动提取属性

在索引新上传的包时,Artifactory将自动尝试从保存在文件中的包元数据中提取所需的属性。注意,并不是所有受支持的文件都可以提取。

目前,只有邮政编码焦油tgztar.gztar.bz2而且whl可以为元数据提取文件。

此外,索引在60秒的静默期后开始,从最后一次上传到当前存储库开始计算。


搜索PyPI包

使用脉冲

Artifactory支持搜索使用皮普搜索命令在本地、远程和虚拟存储库中执行。例如:

皮普搜索
$ pip搜索青蛙-fu——索引http://localhost:8081/artifactory/api/pypi/pypi-virtual/青蛙-fu - 0.2a安装:0.2a(最新)$ pip搜索irbench——索引http://localhost:8081/artifactory/api/pypi/pypi-virtual/ irbench -图像检索基准。

在这个例子中frog-fu是本地安装的包,而irbenchpypi.org类聚合的两个存储库pypi-virtual存储库。

指定索引

在使用search命令时,应该显式地指定索引(不使用/简单在最后),因为PIP将忽略index-url变量pip.conf文件。

Artifactory搜索

PyPI包也可以使用Artifactory的Property Search进行搜索。所有PyPI包都有这些属性pypi.namepypi.version而且pypi.summary由上传客户端设置,或稍后在索引支持的文件类型时设置。


查看PyPI包元数据

Artifactory允许您直接从UI查看PyPI包的选定元数据。

工件模块树浏览器,向下钻取选择要检查的文件。元数据显示在PyPI信息选项卡。

PyPI信息


使用带有自定义注册表后缀的远程存储库

你可以设置一个自定义后缀,而不是像DevPi那样设置默认的简单后缀。

设置devpi注册表后缀到服务器后缀:

在URL和注册表URL中使用根URL。例如:http://m.devpi.net

为了进行搜索,在索引URL中包含所需的范围(如devpi举个例子根/ pypi).

$ PIP搜索frog-fu——索引http://localhost:8081/artifactory/api/pypi/devpi/root/pypi/

要安装,在索引url中包含所需的作用域(就像在devpi示例中一样)根/ pypi

$ PIP install frog-bar -i http://localhost:8081/artifactory/api/pypi/devpi/root/pypi/simple



观看录像



  • 没有标签
版权所有©2023 JFrog Ltd。