标签#

通过将Anaconda.org的标签应用于开发中、测试中和生产中的代码,组织您的代码并促进开发周期——而不影响非开发用户。使用Anaconda Client,开发者可以创建如labels/dev用于开发,labels/test用于测试,或其他仅在用户搜索时指定标签才能找到的标签。

以下搜索示例使用了一个命名空间travis

https://anaconda.org/travis/labels/main

默认搜索的标签

https://anaconda.org/travis

与默认标签相同,使用main隐式

https://anaconda.org/travis/labels/dev

包含开发中的包

https://anaconda.org/travis/labels/test

包含准备测试的包

https://anaconda.org/travis/labels/any-custom-label

任何你想使用的标签

使用标签使您的包私有化#

以下步骤指导您使用test标签,该标签允许您上传文件而不影响您的生产质量包。如果没有--label选项,标签默认为main

使用 Anaconda Prompt(在 macOS/Linux 上为 Terminal)执行以下步骤:

构建并上传包#

  1. 从一个conda包开始。在这个例子中,我们使用了一个小的公共conda测试包

    git clone https://github.com/Anaconda-Platform/anaconda-client/
    cd anaconda-client/example-packages/conda/
    
  2. 通过运行以下命令打开 meta.yaml 文件:

    nano meta.yaml
    
  3. 将版本号更改为 2.0。要保存并关闭 meta.yaml 文件,请按 Ctrl+X,然后按 Y。

  4. 要构建包,请关闭自动客户端上传,然后运行conda build命令:

    conda config --set anaconda_upload no
    conda build .
    

    提示

    您可以通过添加--output选项来检查生成的文件被放置在何处:

    conda build . --output
    
  5. 使用Anaconda客户端上传命令将您的测试包上传到Anaconda.org。

    添加 --label 选项,后跟您的标签(在本例中为 test),这会告诉 Anaconda.org 仅对指定该标签的用户可见上传内容:

    # Replace </PATH/TO/PACKAGE_NAME> with the correct file path and package name
    anaconda upload </PATH/TO/PACKAGE_NAME>.tar.bz2 --label test
    

现在你可以看到,即使你搜索 conda main,你也看不到 2.0 版本的测试包。这是因为你需要告诉 conda 去寻找你新的 test 标签。

测试包的可发现性#

  1. 添加--override参数,该参数告诉conda不要使用~/.condarc文件中的任何通道。如果不指定标签和包名,2.0版本将无法被发现:

    # Replace <USERNAME> with your username
    conda search --override --channel <USERNAME> conda-package
    

    一旦指定了标签和包,就可以找到 2.0

    # Replace <USERNAME> with your username
    conda search --override --channel <USERNAME>/label/test conda-package
    
  2. 你可以给你的测试人员标签 /label/test,其中 是你的用户名。

  3. 一旦他们完成测试,你可能想要将test包复制回你的main标签:

    anaconda label --copy test main
    

    你也可以在你的仪表板上管理你的包标签,地址是 https://anaconda.org/USERNAME/conda-package,其中 是你的用户名。

    您的版本 2.0 现在在 main 中:

    # Replace <USERNAME> with your username
    conda search --override --channel <USERNAME> conda-package
    

如果您使用 anaconda-client 1.7 或更高版本,您可以使用 anaconda move 将包从一个标签移动到另一个标签:

# Replace <OLD> with the old label
# Replace <NEW> with the new label
# Replace <SPEC> with the package to move. SPEC can be either "user/package/version/file" or "user/package/version", in which case it moves all files in that version.
anaconda move --from-label <OLD> --to-label <NEW> <SPEC>