Help Center> CloudArtifact> Getting Started> Releasing/Obtaining a Self-Hosted PyPI Component via a Build Task
Updated on 2022-09-29 GMT+08:00

Releasing/Obtaining a Self-Hosted PyPI Component via a Build Task

This section describes how to release a component to a self-hosted PyPI repo via a build task and obtain a dependency from the repository for deployment.

Prerequisites

  1. You already have a project. If no project is available, create one.
  2. You have created a self-hosted PyPI repo.

Releasing a Self-Hosted Component to a Self-Hosted PyPI Repo

  1. Download the configuration file of the self-hosted repo.

    1. Log in to the DevCloud homepage and access the self-hosted PyPI repo. Click Operation Guide.

    2. Click download Configure File under Configuration (for Publish).

    3. Save the downloaded PYPIRC file as a .pypirc file.

  2. Configure a code repository.

    1. Go to CodeHub and create a Python repository. For details, see Uploading to a Code Repository. This procedure uses the Python3 Demo template.
    2. Go to the code repository and upload the .pypirc file to it.

  3. Configure and execute a build task.

    1. On the code repository page, click Create Build Task in the upper right. The Create Task page is displayed.

      Select Blank build template and click OK.

    2. Add the Build with Setuptools action.

    3. Edit the Build with Setuptools action.
      • Select the desired tool version. In this example, python3.6 is used.
      • Delete the existing commands and run the following instead:
        # Ensure that the setup.py file exists in the root directory of the code, and run the following command to pack the project into a WHL package.
        python setup.py bdist_wheel
        # Set the .pypirc file in the root directory of the current project as the configuration file.
        cp -rf .pypirc ~/
        # Upload the component to the self-hosted PyPI repo.
        twine upload -r pypi dist/* 

        If certificate verification fails during the upload, add the following command to the first line of the preceding command to skip certificate verification:

        export CURL_CA_BUNDLE=""

    4. Click Create and Run to start the build task.

      After the task is successfully executed, go to the self-hosted repo and find the uploaded PyPI component.

Obtaining a Dependency from a Self-Hosted PyPI Repo

The following procedure uses the PyPI component released in Releasing a Self-Hosted Component to a Self-Hosted PyPI Repo as an example to describe how to obtain a dependency from a self-hosted PyPI repo.

  1. Download the configuration file of the self-hosted repo.

    1. Go to the PyPI repository, and click Set Up on the right of the page.
    2. Click download Configure File under Configuration(for Download).

    3. Save the downloaded pip.ini file as a pip.conf file.

  2. Configure a code repository.

    1. Go to CodeHub and create a Python repository. For details, see Uploading to a Code Repository. This procedure uses the Python3 Demo template.
    2. Go to CodeHub, and upload the pip.conf file to the root directory of the code repository where the PyPI dependency is to be used.
    3. Find the requirements.txt file in the repository and open it. If the file is not found, create it by referring to Creating a File. Add the dependency configuration to this file, as shown in the following figure.
      demo ==1.0

  3. Configure and execute a build task.

    1. On the code repository page, click Create Build Task in the upper right. The Create Task page is displayed.

      Select Blank build template and click OK.

    2. Add the Build with Setuptools action.

    3. Edit the Build with Setuptools action.
      • Select the desired tool version. In this example, python3.6 is used.
      • Delete the existing commands and run the following instead:
        # Set the pip.conf file in the root directory of the current project as the configuration file.
         export PIP_CONFIG_FILE=./pip.conf
        # Download the PyPI component.
         pip install -r requirements.txt --no-cache-dir

  4. Click Create and Run to start the build task.

    After the task is successfully executed, view the task details. If information similar to the following is found in the log, the dependency has been downloaded from the self-hosted repo.