Help Center/ CodeArts Artifact/ Best Practices/ Publishing/Obtaining a PyPI Package via a Build Task
Updated on 2026-03-13 GMT+08:00

Publishing/Obtaining a PyPI Package via a Build Task

During software development, teams often use private packages to build and deploy applications. However, fetching dependencies from PyPI repositories can introduce permission or network issues, resulting in build failures. Ensuring seamless publishing and fetching private packages is therefore essential. This practice describes how to publish a private package to a PyPI repository via a build task and fetch its dependencies from the repository to complete the build task, supporting smooth development.

Billing

This function requires CodeArts Repo and CodeArts Build. You need to purchase a CodeArts package.

Prerequisites

  • You already have a project. If no project is available, create one. For example, create a project named project_PyPI.

Publishing a Package to a PyPI Repository

  1. Download the configuration file.

    1. Use your Huawei Cloud account to access self-hosted repos.
    2. Select a PyPI repository. Click Tutorial on the right of the page.
    3. In the displayed dialog box, set Select purpose to Publish, select Download the provided configuration file, and click Download Configuration File.

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

  2. Configure a repository.

    1. Go to Repo and create a Python repository. For details, see Creating a Repository. This procedure uses the Python3 Demo template.
    2. Go to the repository and upload the .pypirc file to the root directory of the repository. For details, see
    3. Create a requirements.txt file, change the content to demo ==1.0, and upload the file to the root directory of the repository. For details, see Uploading Code Files to CodeArts Repo.

  3. Configure and run a build task.

    1. On the Repo page, select the repository and click Create Build Task in the upper right.

      Select Setuptools and click OK.

    2. Edit the Build with Setuptools action.
      1. Select the desired tool version. In this example, python3.6 is used.
      2. 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 package to the PyPI repository.
        twine upload -r pypi dist/* 

        • If a certificate error is reported during the upload, add the following command to the top of the command in 3.b to set environment variables to skip certificate verification. (If the Twine version is earlier than or equal to 3.8.0 and the request version is earlier than or equal to 2.27, ignore the following command.)
          export CURL_CA_BUNDLE=""
        • If a code error is reported during the upload, add the following command to the top of the command in 3.b to set the Python code to UTF-8.
          export PYTHONIOENCODING=utf-8
    3. Click Save and Run on the right of the page to start the build task.

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

Obtaining a Dependency from a PyPI Repository

  1. Download the configuration file.

    1. Use your Huawei Cloud account to access self-hosted repos.
    2. Select the PyPI repository and click Tutorial on the right of the page.
    3. In the displayed dialog box, set Select purpose to Download, select Download the provided configuration file, and click Download Configuration File.

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

  2. Configure a repository.

    1. Go to Repo and create a Python repository. For details, see Creating a Repository. This procedure uses the Python3 Demo template.
    2. Go to Repo, and upload the pip.conf file to the root directory of the 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 Managing Files Add the dependency configuration to this file, as shown in the following figure.
      demo ==1.0

  3. Configure and run a build task.

    1. On the Repo page, select the repository and click Create Build Task in the upper right.

      Select Setuptools and click OK.

    2. 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 package.
         pip install -r requirements.txt --no-cache-dir

  4. Click Save and Run on the right of the page 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 PyPI repository.