Package Loader¶
hatch.package_loader
¶
Package loader for Hatch.
This module provides functionality to download, cache, and install Hatch packages from various sources to designated target directories.
Classes¶
HatchPackageLoader
¶
Manages the downloading, caching, and installation of Hatch packages.
Source code in hatch/package_loader.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
Functions¶
__init__(cache_dir=None)
¶
Initialize the Hatch package loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path
|
Directory to store cached files for Hatch.
Packages will be stored at |
None
|
Source code in hatch/package_loader.py
clear_cache(package_name=None, version=None)
¶
Clear the package cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of specific package to clear. Defaults to None (all packages). |
None
|
version
|
str
|
Version of specific package to clear. Defaults to None (all versions). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful. |
Source code in hatch/package_loader.py
copy_package(source_path, target_path)
¶
Copy a package from source to target directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
Path
|
Source directory path. |
required |
target_path
|
Path
|
Target directory path. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful. |
Raises:
| Type | Description |
|---|---|
PackageLoaderError
|
If copy fails. |
Source code in hatch/package_loader.py
download_package(package_url, package_name, version, force_download=False)
¶
Download a package from a URL and cache it.
This method handles the complete download process including: 1. Checking if the package is already cached 2. Creating a temporary directory for download 3. Downloading the package from the URL 4. Extracting the zip file 5. Validating the package structure 6. Moving the package to the cache directory
When force_download is True, the method will always download the package directly from the source, even if it's already cached. This is useful when you want to ensure you have the latest version of a package. When used with registry refresh, it ensures both the package metadata and the actual package content are up to date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_url
|
str
|
URL to download the package from. |
required |
package_name
|
str
|
Name of the package. |
required |
version
|
str
|
Version of the package. |
required |
force_download
|
bool
|
Force download even if package is cached. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path to the downloaded package directory. |
Raises:
| Type | Description |
|---|---|
PackageLoaderError
|
If download or extraction fails. |
Source code in hatch/package_loader.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
install_local_package(source_path, target_dir, package_name)
¶
Install a local package to the target directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
Path
|
Path to the source package directory. |
required |
target_dir
|
Path
|
Directory to install the package to. |
required |
package_name
|
str
|
Name of the package for the target directory. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path to the installed package. |
Raises:
| Type | Description |
|---|---|
PackageLoaderError
|
If installation fails. |
Source code in hatch/package_loader.py
install_remote_package(package_url, package_name, version, target_dir, force_download=False)
¶
Download and install a remote package.
This method handles downloading a package from a remote URL and installing it into the specified target directory. It leverages the download_package method which includes caching functionality, but allows forcing a fresh download when needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_url
|
str
|
URL to download the package from. |
required |
package_name
|
str
|
Name of the package. |
required |
version
|
str
|
Version of the package. |
required |
target_dir
|
Path
|
Directory to install the package to. |
required |
force_download
|
bool
|
Force download even if package is cached. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path to the installed package. |
Raises:
| Type | Description |
|---|---|
PackageLoaderError
|
If installation fails. |