Help Center/ CodeArts Artifact/ Best Practices/ Releasing/Obtaining a PyPI Component via a Build Task
Updated on 2024-11-11 GMT+08:00

Releasing/Obtaining a PyPI Component via a Build Task

Background

A self-hosted repo manages private component packages (such as Maven) corresponding to various development languages. Different development language components vary in the archive format. A self-hosted repo manages private development language components and shares them with other developers in the same enterprise or team.

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

Preparations

Releasing a Component to a PyPI Repository

  1. Download the configuration file.

    1. Log in to the CodeArts homepage, choose Services > Artifact on the top navigation bar, and click the Self-hosted Repos tab. Select a 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. 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 a 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 component to the PyPI repository.
        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 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 component.

Obtaining a Dependency from a PyPI Repository

The following procedure uses the PyPI component released in Releasing a Component 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 For 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 Using a Template. 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 . 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 a 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 component.
         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.