devpi-common
devpi-common is a utility library providing common functionalities like URL handling, metadata parsing, and archive management. It is primarily used by devpi-server and devpi-client to ensure consistent behavior across the devpi ecosystem. The current version is 4.1.1, with releases often coinciding with major devpi component updates, typically several times a year.
Common errors
-
AttributeError: module 'devpi_common' has no attribute 'URL'
cause Attempting to import the `URL` class directly from the `devpi_common` package instead of its specific submodule.fixChange the import statement to `from devpi_common.url import URL`. -
TypeError: 'URL' object is not iterable
cause Trying to iterate over a `devpi_common.url.URL` object directly, often when expecting it to behave like a list of path segments.fixUse `url_obj.parts` to get a tuple of path segments if iteration is required, or access specific path components via attributes/methods. -
Failed to load devpi-server: Incompatible devpi-common version X.Y.Z (expected W.X.Y)
cause devpi-server (or devpi-client) was installed with a different version of devpi-common than it expects, leading to runtime incompatibility.fixReinstall `devpi-server` (or `devpi-client`) and `devpi-common` together to ensure compatible versions are installed, e.g., `pip install --upgrade devpi-server devpi-client devpi-common`.
Warnings
- breaking Python 3.6 support was dropped in devpi-common 4.0.0. Users on Python 3.6 must use an older version.
- gotcha It is crucial to keep devpi-common's version aligned with devpi-server and devpi-client versions. Mismatched versions can lead to unexpected behavior or errors.
- gotcha The `URL` object from `devpi_common.url` is not directly iterable. Attempting to iterate over it (e.g., in a `for` loop expecting path segments) will raise a `TypeError`.
Install
-
pip install devpi-common
Imports
- URL
from devpi_common import URL
from devpi_common.url import URL
- get_metadata
from devpi_common.metadata import get_metadata
- archive_file
from devpi_common.archive import archive_file
- Plugin
from devpi_common.plugin import Plugin
Quickstart
from devpi_common.url import URL
# Create a URL object
url_obj = URL('https://pypi.org/project/devpi-common/4.1.1/')
print(f"Original URL: {url_obj}")
# Access parts of the URL
print(f"Scheme: {url_obj.scheme}")
print(f"Netloc: {url_obj.netloc}")
print(f"Path: {url_obj.path}")
# Join paths
new_url = url_obj.joinpath('../pypi')
print(f"Joined URL: {new_url}")
# Create a URL from components
composed_url = URL(scheme='http', netloc='localhost:3141', path='/root/pypi/')
print(f"Composed URL: {composed_url}")