galactic.helpers.market.core#
galactic.helpers.market.core module
Defines the core market helpers.
- class Market(cache_path=None, config_path=None)#
Bases:
objectSingleton class representing a market of stores managing cached packages.
- static __new__(cls, cache_path=None, config_path=None)#
Create a singleton instance of the Market class.
- Return type:
Self
- property cache_path: Path#
Get the cache directory used for directory paths.
- Returns:
The cache directory.
- Return type:
Path
- property config_path: Path#
Get the config directory used for directory paths.
- Returns:
The config directory.
- Return type:
Path
- property store_path: Path#
Get the store file used for directory paths.
- Returns:
The store file.
- Return type:
Path
- add_store(store, replace=False)#
Add a new store to the market.
- Parameters:
- Raises:
TypeError – If store is not an instance of Store.
ValueError – If a store with the same name or url already exists.
- Return type:
- get_store(name)#
Get a store by its name.
- Parameters:
name (
str) – The name of the store to retrieve.- Returns:
The Store instance with the specified name.
- Return type:
- Raises:
TypeError – If name is not a string.
ValueError – If the store does not exist.
- remove_store(name)#
Remove a store by its name.
- Parameters:
name (
str) – The name of the store to remove.- Raises:
TypeError – If name is not a string.
ValueError – If the store does not exist.
PermissionError – If trying to remove a system-level store.
- Return type:
- load_store(name)#
Load the store by downloading the latest packages from the remote index.
- Raises:
RuntimeError – If the download fails for any package.
- Return type:
- unload_store(name)#
Unload the store by removing its cached packages.
- save_store(name)#
Save the store metadata to the stores.json file.
- Parameters:
name (
str) – The name of the store to save.- Raises:
TypeError – If name is not a string.
ValueError – If the store does not exist.
- Return type:
- unsave_store(name)#
Remove the store metadata from the stores.json file.
- Parameters:
name (
str) – The name of the store to remove.- Raises:
TypeError – If name is not a string.
ValueError – If the store does not exist.
- Return type:
- get_package(name, pre_release=False)#
Find package metadata by name using fuzzy matching.
- Parameters:
- Returns:
Metadata dictionary of the matching package.
- Return type:
Wheel- Raises:
FileNotFoundError – If no matching package is found in the cache.
- find_matching_packages(**criteria)#
Find packages in the cache matching given criteria.
- install_package(name, extra_index_urls=None)#
Install a package by name using fuzzy matching.
- Parameters:
- Returns:
The name of the installed package file.
- Return type:
- Raises:
TypeError – If name is not a string or extra_index_urls is not a list of strings.
FileNotFoundError – If no matching package is found in the cache.
RuntimeError – If pip is not installed or fails to install the package.
subprocess.CalledProcessError – If the pip install command fails.
- get_store_packages(name)#
List all wheel packages for a given store name.
- get_all_packages()#
List all wheel packages grouped by store folder.
- Returns:
Mapping store folder name -> list of package metadata dicts.
- Return type:
- Raises:
FileNotFoundError – If the cache directory does not exist or is not a directory.
- class Store(name, url, /, *, summary='', created_at=None, loaded_at=None, package_count=0, access_level='unknown', extra_index_urls=None)#
Bases:
objectClass representing a store for managing Python package repositories.
- Parameters:
name (
str) – The name of the store.url (
str) – The URL of the store.summary (
str, default:'') – The summary of the store.created_at (
datetime|None, default:None) – The timestamp when the store was created.loaded_at (
datetime|None, default:None) – The timestamp when the store was last updated.package_count (
int, default:0) – The number of packages available in the store.access_level (
str, default:'unknown') – The access level of the store (e.g., “public”, “protected”, “paid”, “private”, “unknown”, “network_error”).extra_index_urls (
list[str] |None, default:None) – The extra index URLs detected in the store
- property summary: str#
Get the store’s summary description.
- Returns:
The summary text.
- Return type:
- property is_system: bool#
Check if the store is a system-level store.
- Returns:
True if the store is system-level, False otherwise.
- Return type:
- property created_at: datetime#
Get the timestamp when the store was created.
- Returns:
The creation timestamp in ISO 8601 format.
- Return type:
datetime
- property loaded_at: datetime#
Get the timestamp when the store was last updated.
- Returns:
The last updated timestamp in ISO 8601 format.
- Return type:
datetime
- property package_count: int#
Get the number of packages available in the store.
- Returns:
The number of packages in the store.
- Return type:
- property access_level: str#
Get the access level of the store.
- Returns:
The access level of the store.
- Return type:
- fetch_access_level()#
Determine the access level of the store by performing an HTTP GET request.
- Returns:
One of the following access levels: - “public”: accessible without authentication (HTTP 200) - “protected”: requires authentication but is free (HTTP 401) - “paid”: requires payment for access (HTTP 402) - “private”: requires special permissions (HTTP 403) - “network_error”: if a network error occurs
- Return type: