标签#

通过将 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 上的终端)执行以下步骤

构建和上传包#

  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 Client 上传命令将您的测试包上传到 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. 您可以将标签 <USERNAME>/label/test 提供给您的测试人员,其中 <USERNAME> 是您的用户名。

  3. 一旦他们完成测试,您可能希望将 test 包复制回您的 main 标签

    anaconda label --copy test main
    

    您还可以从您的仪表板 https://anaconda.org/USERNAME/conda-package 管理您的包标签,其中 <USERNAME> 是您的用户名。

    您的版本 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>