Help Center/ CodeArts Artifact/ Best Practices/ Releasing/Obtaining a PyPI Package via a Build Task
Updated on 2025-07-22 GMT+08:00

Releasing/Obtaining a PyPI Package via a Build Task

This practice describes how to release a private package to a PyPI repository via a build task and obtain a dependency from the repository for deployment.

Prerequisites

  • You have purchased a CodeArts package.
  • You already have a project. If no project is available, create one. For example, create a project named project01.

Releasing a Package to a PyPI Repository

  1. Download the configuration file.

    1. Log in to CodeArts Artifact and access the PyPI repository. Click Tutorial on the right of the page.
    2. In the displayed dialog box, select Publish as the purpose and click Download Configuration File.

    3. 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. Configure and run a build task.

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

      Select Blank 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 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 first line of the preceding command 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=""
    4. 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

The following procedure uses the PyPI package released in Releasing a Package to a PyPI Repository as an example to describe how to obtain a dependency from a PyPI repository.

  1. Download the configuration file.

    1. Go to the PyPI repository and click Tutorial on the right of the page.
    2. In the displayed dialog box, select Download as the purpose and click Download Configuration File.

    3. 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 Blank 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 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.