云客户?
免费开始>
在MyJFrog中升级>
云的新功能>





概述

人工完全支持PyPI存储库提供:

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


在Windows上运行

要在Windows上使用Artifactory PyPI存储库,请确保设置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和Registry 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服务器管理,则需要指向它的PyPI API URL注册网址字段。例如,http://my.remote.artifactory/artifactory/api/pypi/python-project

虚拟存储库

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



使用pip从人工解决

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

使用具有pip和Artifactory的有效SSL证书

只有当包的下载URL是具有有效SSL证书的受信任主机时,pip才使用本地缓存中的包(即运行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安装frog-bar -i http://localhost:8081/artifactory/api/pypi/pypi-local/simple

使用凭证

由于它的设计,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.2 nltk==2.0.4 wsgiref==0.1.2



向Artifactory发布

使用distutils或setuptools

Setuptools vs. distutils和python版本

人工对你是否使用是不可知的setuptoolsdistutils,以及项目使用的Python版本或实现。

下面的指令是为Python 2.7和Python编写的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用户名:mrBagthrope密码:notToBeSeen [local] repository: http://localhost:8081/artifactory/api/pypi/pypi-local用户名: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用户名= pypiadmin密码=eyJ2ZXIiOiIyIiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYiLCJraWQiOiJsYkpadzNJUU13WXBBSWNRa01RRjN0dlA2Yml5M3dWcXdrQ0txUkxLaXhRIn0.eyJleHQiOiJ7XCJyZXZvY2FibGVcIjpcInRydWVcIn0iLCJzdWIiOiJqZmFjQDAxZTlycTMza3ljMHQxMWtwangybmcwemo1XC91c2Vyc1wvcHlwaWFkbWluIiwic2NwIjoiYXBwbGllZC1wZXJtaXNzaW9uc1wvYWRtaW4iLCJhdWQiOiIqQCoiLCJpc3MiOiJqZmZlQDAwMCIsImV4cCI6MTY4OTY5ODA5MywiaWF0IjoxNjU4MTYyMDkzLCJqdGkiOiJiZWY1YWY5Ni0zNTkyLTRiOTQtYWYyNS1kZmIxY2U1ZGU4YzIifQ.NI5OXpw0NHs7Asd3f_sY3tMyzM-2_07c3WyWEpbJrDPxO8eKoLRp10vGEF8Jo3HyRQ0H7Ybzf2-Cn8wf9yFMo4UGlgxGfm7_yc24xWVLCINjg0B2A5YRSvAetwdT2wgVPvEMUqCPSCU4_SGgGg606lIDxxImRfgZWwFn-wHfU8b8dCV7EV4dXGvH7iVb33W2JguE9KIQFP7lKkQlaErO6pGFNuPfOx1JbJllHh0oRpAPzvykda2i6Q2q3ZCObJZ9Rp8NqZYQfEm42YtIaOvAlE5fGepZgDjzHaaLcztJDHoR-BWjMiDfP0LRThHASo7F52t8p3vsZHW5NEov_trFrQ
  2. 复制.pypirc文件到您的Users文件夹。
      • 对于macOS用户,创建下面的文件% USERPROFILE %
      • 对于Windows用户,在下面创建文件c: \用户\ <名称>
  3. 验证setup . py文件包含以下所有字段。它应该是自动创建的,但如果不是,那么用以下内容将文件添加到根文件夹中。

    #!/usr/bin/env python from setuptools import setup setup(name='demo-python-example', version='1.0', description='使用JFrog产品构建python项目的项目示例',author='JFrog', author_email='hth华体会最新官方网站jfrog@m.si-fil.com', packages=['helloworld'], install_require =['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 writing demo_python_example. C:\Users\johnk\helloworld>py setup.py蛋-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。

    setup.py sdist upload -r private-repository

    下面显示一个示例输出。

    C:\Users\johnk\helloworld>py setup.py sdist bdist_wheel running sdist running egg_info writing demo_python_example. C:\Users\johnk\helloworld>py setup.py蛋-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文件和asetup . py在你的项目的根脚本,你可以上传你的鸡蛋(tar.gz)包如下:

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

如果你使用wheel ()whl),你可以上传你的软件包如下:

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

或者如果你想用两种鸡蛋(tar.gz)和轮子(whl),你可以按以下方式上传:

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

在哪里当地的这节课的名字是你的吗.pypirc指向您的Artifactory PyPI存储库的文件。

默认的上传

默认情况下,两者都是setuptoolsdistutils将上传到https://pypi.org/pypi如果没有指定存储库。

register命令应该省略

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

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

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

PyPI包也可以使用Web UI或者是人工REST API.为了使Artifactory正确地处理这些包,它们必须与PyPI包一起上传pypi.namepypi.version属性。

自动提取属性

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

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

此外,索引在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是本地安装的包,而irbench被发现于pypi.org,这两个存储库都由pypi-virtual存储库。

指定索引

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

Artifactory搜索

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


查看PyPI包的元数据

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

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

PyPI信息


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

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

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

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

要进行搜索,请在索引URL中包含所需的范围(如devpi例如,它可以是根/ pypi).

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

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

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



观看视频



  • 没有标签
版权所有©2022 JFrog Ltd.