package_to_distribution
Class info¶
🛈 DocStrings¶
clear_caches
¶
Clear all function caches, the entry point cache included.
This should be called when the underlying package distributions might have changed, for example after installing or removing packages.
Example
clear_caches() # Clear all cached mappings
Source code in src/epregistry/package_to_distribution.py
distribution_to_package
¶
Convert a distribution name to its primary package name.
If a distribution provides multiple packages, returns the primary one: the package named like the distribution, else the shortest name without a leading underscore (ties broken alphabetically). Use distribution_to_packages() to get all packages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distribution_name
|
str
|
The name of the distribution |
required |
fallback
|
bool
|
Returns a normalized best guess even if no mapping found |
False
|
Returns:
| Type | Description |
|---|---|
str | None
|
The primary package name if found, None otherwise |
Example
distribution_to_package('Pillow') 'PIL' distribution_to_package('requests') 'requests' distribution_to_package('nonexistent') None
Source code in src/epregistry/package_to_distribution.py
distribution_to_packages
cached
¶
Convert a distribution name to all its package names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distribution_name
|
str
|
The name of the distribution |
required |
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
A frozenset of the (importable) top-level package names of the distribution |
Example
distribution_to_packages('Pillow') {'PIL'} distribution_to_packages('python-dateutil') {'dateutil'} distribution_to_packages('nonexistent') set()
Source code in src/epregistry/package_to_distribution.py
get_cache_info
¶
Get information about the current state of all caches.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A dictionary with cache statistics for each cached function |
Example
info = get_cache_info() print(info['package_to_distribution']) 'CacheInfo(hits=42, misses=10, maxsize=1024, currsize=10)'
Source code in src/epregistry/package_to_distribution.py
get_packages_distributions
cached
¶
Cached call for packages_distributions (read-only).
Extends the stdlib mapping with packages of .pth-based editable installs
which packages_distributions() does not report.
Source code in src/epregistry/package_to_distribution.py
package_to_distribution
cached
¶
Convert a package name to its distribution name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
The name of the package |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The distribution name if found, None otherwise |
Example
package_to_distribution('PIL') 'Pillow' package_to_distribution('requests') 'requests' package_to_distribution('nonexistent') None
Source code in src/epregistry/package_to_distribution.py
package_to_distributions
¶
Convert a package name to all its distribution names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
The name of the package |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
List of distribution names if found, None otherwise. |
Example
package_to_distributions('zope') # namespace package ['zope.interface', 'zope.event'] # if both are installed package_to_distributions('requests') ['requests'] package_to_distributions('nonexistent') None
Notes
For namespace packages (like 'zope'), returns all related distributions. This is particularly useful for examining namespace package relationships.