pypicloud.cache.base module

Base class for all cache implementations

class pypicloud.cache.base.ICache(request=None, storage=None, allow_overwrite=None, calculate_hashes=True, allow_delete=True)[source]

Bases: object

Base class for a caching database that stores package metadata

all(name: str) → List[pypicloud.models.Package][source]

Search for all versions of a package

Parameters:
name : str

The name of the package

Returns:
packages : list

List of all Package s with the given name

check_health() → Tuple[bool, str][source]

Check the health of the cache backend

Returns:
(healthy, status) : (bool, str)

Tuple that describes the health status and provides an optional status message

clear(package: pypicloud.models.Package) → None[source]

Remove this package from the caching database

Parameters:
package : Package
clear_all() → None[source]

Clear all cached packages from the database

classmethod configure(settings)[source]

Configure the cache method with app settings

delete(package: pypicloud.models.Package) → None[source]

Delete this package from the database and from storage

Parameters:
package : Package
distinct() → List[str][source]

Get all distinct package names

Returns:
names : list

List of package names

download_response(package: pypicloud.models.Package)[source]

Pass through to storage

fetch(filename: str) → pypicloud.models.Package[source]

Get matching package if it exists

Parameters:
filename : str

Name of the package file

Returns:
package : Package
get_url(package: pypicloud.models.Package) → str[source]

Get the download url for a package

Parameters:
package : Package
Returns:
url : str
new_package(*args, **kwargs) → pypicloud.models.Package[source]
classmethod postfork(**kwargs)[source]

This method will be called after uWSGI forks

reload_from_storage(clear: bool = True) → None[source]

Make sure local database is populated with packages

reload_if_needed() → None[source]

Reload packages from storage backend if cache is empty

This will be called when the server first starts

save(package: pypicloud.models.Package) → None[source]

Save this package to the database

Parameters:
package : Package
search(criteria: Dict[str, List[str]], query_type: str) → List[pypicloud.models.Package][source]

Perform a search from pip

Parameters:
criteria : dict

Dictionary containing the search criteria. Pip sends search criteria for “name” and “summary” (typically, both of these lists have the same search values).

Example:

{
    "name": ["value1", "value2", ..., "valueN"],
    "summary": ["value1", "value2", ..., "valueN"]
}
query_type : str

Type of query to perform. By default, pip sends “or”.

summary() → List[Dict[str, Any]][source]

Summarize package metadata

Returns:
packages : list

List of package dicts, each of which contains ‘name’, ‘summary’, and ‘last_modified’.

upload(filename: str, data: BinaryIO, name: Optional[str] = None, version: Optional[str] = None, summary: Optional[str] = None, requires_python: Optional[str] = None) → pypicloud.models.Package[source]

Save this package to the storage mechanism and to the cache

Parameters:
filename : str

Name of the package file

data : file

File-like readable object

name : str, optional

The name of the package (if not provided, will be parsed from filename)

version : str, optional

The version number of the package (if not provided, will be parsed from filename)

summary : str, optional

The summary of the package

requires_python : str, optional

The Python version requirement

Returns:
package : Package

The Package object that was uploaded

Raises:
e : ValueError

If the package already exists and allow_overwrite = False