Pushing PyPI Packages to Gitea
This step-by-step guide outlines how to push your Python packages to a Gitea registry using Twine.
Requirements
- To work with the PyPI package registry, you need to use the package pip to consume and twine to publish packages.
- To push packages, a user with read-write permissions is required. This user can either be a technical user or a human user.
- For PyPI packages, authentication can be achieved using either a password or a token. However, for npm packages, pushing to the registry is only possible with a token.
Generating a Token
To push packages to Gitea, you must have an access token with read and write permissions. The Creating Access Tokens for Pushing Packages to Gitea documentation guides you on how to create such a token.
Guide
Configuration
For configuring .pypirc in Windows or Linux:
- Open/Create .pypirc file:
In Windows, navigate to C:\Users\YourUsername or in Linux to ~, and create or open the .pypirc file.
- Edit .pypirc Content:
Add the [distutils] section to declare gitea as an index server.
In the [gitea] section specify your Gitea repository URL, replacing the placeholders {pkey}, {username} and {password} with actual values.[distutils]
index-servers = gitea
[gitea]
repository = https://gitea-CUSTOMER.devops.t-systems.net/api/packages/{pkey}/pypi
username = {username}
password = {password}Placeholder Description pkey Project Key in DevOps Portal, refers to Organization in Gitea username Your Gitea username or the name of the technical user password Your password or access token.
A token has to be used if 2FA is configured for the user.
Refer to Creating Access Tokens for Pushing Packages to Gitea for instructions. - Save .pypirc:
Ensure no file extension like .txt when saving. In Linux, use a text editor like nano or vim; in Windows, Notepad can be used, ensuring to select "All Files" and type the filename as .pypirc.
Publish a package
To publish a package with Twine, first identify the path where your package files (.tar.gz and .whl) are located, typically in the dist/ directory created after building your package.
Result
Once published, the package will be accessible within the "Packages" section of the organization in Gitea.
The following picture displays how the "requests" package appears in Gitea after being pushed to the package registry.