Releasing/Obtaining a PyPI Component via a Build Task
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.
Prerequisites
- You already have a project. If no project is available, create one.
- You have created a PyPI repository.
- You have permissions for the current repository. For details, see Managing Repository Permissions
Releasing a Component to a PyPI Repository
- Download the configuration file.
- Log in to CodeArts Artifact and access the PyPI repository. Click Tutorial on the right of the page.
- In the displayed dialog box, find the For Publishing and click Download Configuration File.
- Save the downloaded PYPIRC file as a .pypirc file.
- Configure a repository.
- Go to Repo and create a Python repository. For details, see Creating a Repository Using a Template. This procedure uses the Python3 Demo template.
- Go to the repository and upload the .pypirc file to the root directory of the repository. For details, see .
- Configure and run a build task.
- On the Repo page, select a repository and click Create Build Task in the upper right.
Select Blank Template and click OK.
- Add the Build with Setuptools action.
- 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=""
- 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.
- On the Repo page, select a repository and click Create Build Task in the upper right.
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.
- Download the configuration file.
- Go to the PyPI repository and click Tutorial on the right of the page.
- In the displayed dialog box, find the For Download and click Download Configuration File.
- Save the downloaded pip.ini file as a pip.conf file.
- Configure a repository.
- Go to Repo and create a Python repository. For details, see Creating a Repository Using a Template. This procedure uses the Python3 Demo template.
- Go to Repo, and upload the pip.conf file to the root directory of the repository where the PyPI dependency is to be used.
- 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
- Configure and run a build task.
- On the Repo page, select a repository and click Create Build Task in the upper right.
Select Blank Template and click OK.
- Add the Build with Setuptools action.
- 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
- On the Repo page, select a repository and click Create Build Task in the upper right.
- 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 self-hosted repo.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot