upstream
napt.upstream
Recipes imported from other git repositories.
A project imports a recipe with napt upstream add, which writes a
byte-identical pinned copy under upstream/<host>/<repo path>/<path>,
writes an override in recipes/ that names the pinned copy as its
parent, and records the recipe's commit and hashes in upstream.yaml
at the project root. The config loader treats every parent under
upstream/ as a pinned copy: the file must match its recorded hash, and
only app-owned keys reach the merge.
Modules:
| Name | Description |
|---|---|
add |
The import engine behind |
remove |
The removal engine behind |
refresh |
The scan behind |
git |
Read-only transport through the |
lock |
The |
pinned |
What makes a parent a pinned copy, the hash check, and the keys a pinned parent may set. |
napt.upstream.add
Importing recipes from a git repository: the engine behind napt upstream add.
An import writes each selected upstream recipe byte-identical as a pinned
copy under upstream/<host>/<repo path>/<path>, writes an override in
recipes/ that names the pinned copy as its parent and carries the
recipe's name and id, and records each recipe's commit and hashes in
upstream.yaml.
Nothing is written until every selected recipe has been fetched and the
configuration each override will produce has passed validation, so a bad
recipe aborts the whole import with the project untouched.
OVERRIDE_SUFFIX
module-attribute
What an override file is named: <app>.override.yaml.
PlannedRecipe
dataclass
One recipe the import will write, or did write.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The recipe's path inside the repository. |
pinned |
str
|
Where the pinned copy lands, relative to the project root. |
override |
str
|
The override that runs it, relative to the project root. |
app_id |
str
|
The |
dropped |
tuple[str, ...]
|
The keys the allow list removes from the pinned copy. |
duplicate_of |
str | None
|
Another recipe in the project that already uses the
same |
Source code in napt/upstream/add.py
AddResult
dataclass
What napt upstream add imported.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The clone URL as given. |
ref |
str
|
The branch or tag imported from. |
commit |
str
|
The commit fetched, recorded on each imported recipe. |
recipes |
tuple[PlannedRecipe, ...]
|
Each recipe written, in repository order. |
skipped |
tuple[str, ...]
|
Recipes selected through a directory that were already imported, left at their own pins. |
dry_run |
bool
|
Whether nothing was written. |
Source code in napt/upstream/add.py
override_path_for
Decides where the override for an upstream recipe lives.
One rule for files and directories: everything after the last
recipes/ segment of the upstream path is mirrored under the
project's recipes/ (or under dest), so recipes/Google/
chrome.yaml lands at recipes/Google/chrome.override.yaml however
it was selected. Without such a segment, dest is required and the
file lands under it at its path relative to the imported directory,
which for a single file is its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upstream_path
|
str
|
The recipe's path inside the repository. |
required |
imported_from
|
str
|
The |
required |
dest
|
str | None
|
The |
required |
Returns:
| Type | Description |
|---|---|
PurePosixPath
|
The override's path relative to the project root. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When the path has no |
Source code in napt/upstream/add.py
add_recipes
add_recipes(
project_root: Path,
url: str,
paths: Iterable[str],
*,
ref: str | None = None,
dest: str | None = None,
app_id: str | None = None,
excludes: Iterable[str] = (),
dry_run: bool = False
) -> AddResult
Imports recipes from a repository into the project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_root
|
Path
|
The directory holding |
required |
url
|
str
|
The clone URL. |
required |
paths
|
Iterable[str]
|
Files or directories inside the repository to import. A
directory skips recipes already tracked, so re-running it picks
up what the publisher added since; a file already tracked is an
error pointing at |
required |
ref
|
str | None
|
A branch or tag; the default branch when None. A repository already in the lockfile keeps its recorded ref, and a different one is an error. |
None
|
dest
|
str | None
|
Where the overrides go instead of mirroring under
|
None
|
app_id
|
str | None
|
An |
None
|
excludes
|
Iterable[str]
|
Globs matched against each file's path relative to the directory it was selected through. |
()
|
dry_run
|
bool
|
Report what would be written and write nothing. |
False
|
Returns:
| Type | Description |
|---|---|
AddResult
|
What was imported, or would be. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When a selection, path, override, or the configuration an override would produce is invalid; nothing is written. |
NetworkError
|
When the repository cannot be reached. |
Source code in napt/upstream/add.py
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 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
napt.upstream.remove
Removing an imported recipe: the engine behind napt upstream remove.
Removal deletes the pinned copy and its lockfile entry, the repository's
entry and emptied directories under upstream/ once nothing of it
remains, and the lockfile itself once no repository remains. The override
is the user's file, so it is left alone unless asked; it is reported with
its now-dangling parent so the user can inline it or delete it.
RemoveResult
dataclass
What napt upstream remove did.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The pinned copy that was deleted, relative to the project root. |
override |
str | None
|
The override that named it, relative to the project root, or None when the lockfile recorded none that exists. |
override_deleted |
bool
|
Whether the override was deleted too. |
repo_removed |
bool
|
Whether this was the repository's last recipe, so its lockfile entry and directory went with it. |
Source code in napt/upstream/remove.py
remove_recipe
Removes one imported recipe from the project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_root
|
Path
|
The directory holding |
required |
path
|
Path
|
The pinned copy under |
required |
delete_override
|
bool
|
Delete the override as well. |
False
|
Returns:
| Type | Description |
|---|---|
RemoveResult
|
What was removed. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When the path is neither a tracked pinned copy nor
an override naming one, the pinned copy belongs to another
project's |
Source code in napt/upstream/remove.py
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 | |
napt.upstream.refresh
Checking pinned copies against their upstream recipes, and refreshing them.
napt upstream check and napt upstream update run the same scan.
Per repository in upstream.yaml: one ls-remote; when the branch
tip equals every selected recipe's commit and nothing needs rewriting,
the fetch is skipped and only the local hashes are verified. Otherwise the
ref is fetched trees-only once and each recipe's recorded blob id is
compared to the one at its path now. update then rewrites the pinned
copies that changed, each with its own new commit, and leaves every
other entry alone, so a run can refresh one recipe at a time and CI can
open one pull request per recipe.
RecipeStatus
dataclass
What the scan found for one pinned copy.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The repository's clone URL as the lockfile records it. |
path |
str
|
The upstream recipe's path inside the repository. |
override |
str
|
The override that runs it, relative to the project root. |
status |
str
|
One of |
old_commit |
str
|
The commit the pinned copy was taken from. |
new_commit |
str | None
|
The commit the ref resolves to now, or None when the fetch was skipped. |
old_blob |
str
|
The recorded blob id. |
new_blob |
str | None
|
The blob id at the path now, or None when missing or when the fetch was skipped. |
updated |
bool
|
Whether |
dropped |
tuple[str, ...]
|
The keys the allow list removes from the new content; set only when the pinned copy was rewritten. |
Source code in napt/upstream/refresh.py
RefreshResult
dataclass
What napt upstream check found, or update did.
Attributes:
| Name | Type | Description |
|---|---|---|
recipes |
tuple[RecipeStatus, ...]
|
One status per selected recipe, in lockfile order. |
wrote |
bool
|
Whether the run was allowed to rewrite pinned copies. |
Source code in napt/upstream/refresh.py
refresh
refresh(
project_root: Path,
*,
write: bool,
paths: Iterable[Path] = (),
force: bool = False,
quiet: bool = False
) -> RefreshResult
Scans the tracked recipes against upstream and optionally refreshes them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_root
|
Path
|
The directory holding |
required |
write
|
bool
|
Rewrite changed pinned copies and the lockfile ( |
required |
paths
|
Iterable[Path]
|
Overrides or pinned copies to limit the run to. |
()
|
force
|
bool
|
With |
False
|
quiet
|
bool
|
Print no progress or warning lines; the result carries the
same facts ( |
False
|
Returns:
| Type | Description |
|---|---|
RefreshResult
|
One status per selected recipe. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When there is no lockfile, a path is not tracked, or a repository's ref no longer exists. |
NetworkError
|
When a repository cannot be reached. |
Source code in napt/upstream/refresh.py
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 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
napt.upstream.git
Read-only git transport for upstream recipe repositories.
Every network operation of napt upstream goes through the git
binary, so authentication is whatever git already does (credential
helpers, SSH keys) and any host that serves git works. Nothing here
touches the user's own repository: a fetch lands in a temporary directory
that is removed when the operation ends.
Three guards apply to every value that reaches git from a lockfile or a
command line, because upstream.yaml can be edited by anyone who can
open a pull request:
- A URL, ref, or path that starts with
-is refused, so git never reads one as an option. - Positional arguments follow
--wherever git accepts it. GIT_ALLOW_PROTOCOLlimits transports tohttps,ssh,git, andfile, so anext::URL, which runs a command, is never reachable.
Prompts are disabled (GIT_TERMINAL_PROMPT=0, SSH batch mode) so a
missing credential fails at once instead of hanging a CI job. The
variables that would point git at another repository (GIT_DIR and its
relatives, which git exports into hooks) are dropped from the environment,
and a git found in the current directory is refused, so the user's own
repository is never the one acted on.
ALLOWED_PROTOCOLS
module-attribute
Transports git may use; ext and other command-running schemes are out.
RECIPE_SUFFIXES
module-attribute
File name endings that make a tree entry a recipe.
MAX_RECIPE_BYTES
module-attribute
The largest file read_file fetches; a recipe is a few kilobytes.
RemoteRefs
dataclass
What git ls-remote reported for a repository.
Attributes:
| Name | Type | Description |
|---|---|---|
default_branch |
str | None
|
The branch |
refs |
dict[str, str]
|
Each full ref name ( |
Source code in napt/upstream/git.py
commit_for
Finds the commit a branch or tag name points at.
A branch wins over a tag of the same name. An annotated tag resolves through its peeled entry to the commit, so a pinned commit compares against commits only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
str
|
A branch or tag name as the user gave it, or a full ref. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The commit id, or None when the remote has no such ref. |
Source code in napt/upstream/git.py
TreeEntry
dataclass
One recipe file in a fetched tree.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The file's path from the repository root, forward slashes. |
blob |
str
|
The git blob id of its content. |
Source code in napt/upstream/git.py
FetchedRef
A repository's ref fetched trees-only into a temporary directory.
Use as a context manager; the directory and everything git wrote into
it are removed on exit. TemporaryDirectory already retries after
resetting permissions, which is what git's read-only pack files need
on Windows.
Example
Read one file at a branch tip:
Attributes:
| Name | Type | Description |
|---|---|---|
commit |
The commit the ref resolved to when fetched; the value
recorded as each imported recipe's |
Source code in napt/upstream/git.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
__init__
Fetches the ref's tip without its blobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The clone URL. |
required |
ref
|
str
|
A branch or tag name. |
required |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When git is missing or a value starts with |
NetworkError
|
When the fetch fails. |
Source code in napt/upstream/git.py
__enter__
__exit__
list_recipe_files
Lists the recipe files under the given repository paths.
A directory lists every .yaml and .yml beneath it; a file
lists itself. Each returned path has passed
check_upstream_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
Iterable[str]
|
Files or directories relative to the repository root. |
required |
Returns:
| Type | Description |
|---|---|
list[TreeEntry]
|
The matching files with their blob ids, in tree order. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When a path starts with |
NetworkError
|
When git fails. |
Source code in napt/upstream/git.py
read_file
Reads one file's exact bytes at the fetched commit.
The blob is fetched from the remote on demand; no line-ending or filter conversion is applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The file's path from the repository root. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
The file's content as git stores it. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When the path starts with |
NetworkError
|
When the blob cannot be fetched. |
Source code in napt/upstream/git.py
find_git
Locates the git binary.
On Windows the search includes the current directory, which for
napt upstream is the user's project; a git.cmd committed there
must never be what runs, so a result in the current directory is
refused rather than used.
Returns:
| Type | Description |
|---|---|
str
|
The path to |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When git is not on |
Source code in napt/upstream/git.py
redact_url
Hides the user information of a URL for logs and messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Any command argument; one that is not a URL with user information is returned unchanged. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The value with |
Source code in napt/upstream/git.py
check_argument
Refuses a value git would read as an option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
A URL, ref name, or repository path about to be passed to git. |
required |
what
|
str
|
What the value is, for the message ("URL", "ref", "path"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The value, unchanged. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When the value is empty or starts with |
Source code in napt/upstream/git.py
run_git
Runs one git command and returns its stdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
list[str]
|
The arguments after |
required |
cwd
|
Path | None
|
The repository to run in, or None for a command that needs
none ( |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
The command's stdout, as bytes, because paths and refs are not guaranteed to be UTF-8. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When git is not installed. |
NetworkError
|
When git exits non-zero (the message carries its stderr), times out, or cannot be launched. |
Source code in napt/upstream/git.py
ls_remote
Lists a repository's refs without fetching anything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The clone URL. |
required |
Returns:
| Type | Description |
|---|---|
RemoteRefs
|
The default branch and every ref with its object id. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When git is missing or the URL starts with |
NetworkError
|
When the repository cannot be reached. |
Source code in napt/upstream/git.py
check_upstream_path
Refuses a repository path that cannot become a directory tree here.
Every segment must satisfy
is_safe_path_component with
spaces allowed, so .., reserved device names, trailing dots, and
characters Windows forbids never reach the filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
A path from |
required |
Returns:
| Type | Description |
|---|---|
str
|
The path, unchanged. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When a segment is unsafe, naming it. |
Source code in napt/upstream/git.py
napt.upstream.lock
The upstream.yaml lockfile.
upstream.yaml sits at the project root beside defaults/ and is
written by napt upstream alone. It lists every imported repository and,
under each, the recipes imported from it:
apiVersion: napt/v1
repos:
- url: https://github.com/someorg/napt-recipes.git
ref: main
recipes:
- path: recipes/Google/chrome.yaml
override: recipes/Google/chrome.override.yaml
commit: 4f2a9c1e0b7d3f8a2c6e1d9b5a4f7c3e8d2b6a1f
blob: 9c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d
sha256: 8e1b5f2c...
Each recipe carries its own commit, so one repository's recipes can be
pinned at different points and updated one at a time.
The path of a recipe's pinned copy is never stored; it is derived from the
repository URL and the recipe path, and it is the key the config loader
looks an entry up by. sha256 is over the file's bytes with CRLF line
endings normalized to LF, so a checkout with autocrlf on Windows hashes
the same as one without.
LOCKFILE_NAME
module-attribute
The lockfile's name; it lives beside the upstream/ directory.
LockedRecipe
dataclass
One imported recipe as the lockfile records it.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The upstream recipe's path inside its repository, forward slashes. |
override |
str
|
The override that runs it, relative to the project root. |
commit |
str
|
The commit the pinned copy was taken from. |
blob |
str
|
The git blob id of the upstream recipe's content. |
sha256 |
str
|
The canonical hash of the pinned copy. |
Source code in napt/upstream/lock.py
LockedRepo
dataclass
One imported repository as the lockfile records it.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The clone URL as first given. |
ref |
str
|
The branch or tag the recipes are taken from. |
recipes |
tuple[LockedRecipe, ...]
|
The recipes imported from it, each with its own commit. |
Source code in napt/upstream/lock.py
Lockfile
dataclass
The parsed upstream.yaml.
Attributes:
| Name | Type | Description |
|---|---|---|
repos |
tuple[LockedRepo, ...]
|
Every imported repository. |
Source code in napt/upstream/lock.py
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 | |
find_repo
Finds the entry for a repository by any form of its URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
A clone URL. |
required |
Returns:
| Type | Description |
|---|---|
LockedRepo | None
|
The entry, or None when the repository was never imported. |
Source code in napt/upstream/lock.py
replace_repo
Returns a lockfile with one repository's entry replaced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
LockedRepo | None
|
The new entry, or None to drop the repository. |
required |
url
|
str
|
The URL identifying the repository to replace; a repository not yet listed is appended. |
required |
Returns:
| Type | Description |
|---|---|
Lockfile
|
The new lockfile; this one is unchanged. |
Source code in napt/upstream/lock.py
locate
Looks a pinned copy up by its path under upstream/.
The repository part of the path is compared case-insensitively, since GitHub names are and Windows directories collide anyway; the recipe path is compared exactly, as git recorded it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pinned
|
PurePosixPath
|
The file's path relative to the |
required |
Returns:
| Type | Description |
|---|---|
tuple[LockedRepo, LockedRecipe] | None
|
The repository and recipe entries, or None when no repository entry tracks that pinned copy. |
Source code in napt/upstream/lock.py
find
Looks a pinned copy's recipe entry up by its path under upstream/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pinned
|
PurePosixPath
|
The file's path relative to the |
required |
Returns:
| Type | Description |
|---|---|
LockedRecipe | None
|
The matching entry, or None; see locate. |
Source code in napt/upstream/lock.py
canonical_sha256
Hashes file bytes with Windows line endings normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The file's bytes as read from disk or from git. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The hex digest of the bytes with every CRLF replaced by LF. |
Source code in napt/upstream/lock.py
repo_directory
Names the directory under upstream/ that holds a repository's pinned copies.
The directory is the host plus every path segment of the clone URL,
with the user, port, .git suffix, and trailing slash removed, so
HTTPS, ssh://, and scp-like SSH forms of one repository land in one
place and nested GitLab groups keep every segment. The host is
lowercased; path segments keep their case and are compared
case-insensitively by Lockfile.find.
A URL with no host, such as file://, becomes a single directory
named after the whole URL with unsafe characters replaced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
A clone URL as given to |
required |
Returns:
| Type | Description |
|---|---|
PurePosixPath
|
The repository's directory relative to |
Example
Three forms of one repository:
Source code in napt/upstream/lock.py
same_repository
Reports whether two clone URLs name one repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
str
|
A clone URL. |
required |
second
|
str
|
Another clone URL, in any form git accepts. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when both map to the same directory under |
Source code in napt/upstream/lock.py
write_lockfile
Writes upstream.yaml atomically, after a fixed header comment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The lockfile. |
required |
lock
|
Lockfile
|
What to write. |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
When the file cannot be written. |
Source code in napt/upstream/lock.py
read_lockfile
Reads upstream.yaml, once per version of the file per run.
A directory run loads many recipes that share one lockfile; the parsed result is reused until the file's size or modification time changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The lockfile. |
required |
Returns:
| Type | Description |
|---|---|
Lockfile
|
The parsed lockfile. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When the file does not exist, cannot be read, is not
valid YAML, or does not have the shape |
Source code in napt/upstream/lock.py
napt.upstream.pinned
What the config loader does with a parent under upstream/.
A parent is a pinned copy when the parent reference in the override, taken
relative to the override's directory, passes through a directory named
upstream (any case). Only the segments between the override and the
parent count, so a project that itself lives under a folder called
upstream is unaffected. A parent whose resolved path sits under a
tracked upstream/ directory (one with upstream.yaml beside it) is
a pinned copy as well, so a symlink from elsewhere cannot present one as
local. A pinned parent must be listed in the
upstream.yaml beside that directory with a matching hash, and only the
app-owned keys in
ALLOWED_PARENT_KEYS
reach the merge; everything else is tenant policy that defaults/org.yaml
keeps owning without the override restating it.
A pinned copy under upstream/ is never run directly; commands run the
override that names it as parent. A "pinned parent" below is a parent
that is a pinned copy, as opposed to a local parent.
UPSTREAM_DIR_NAME
module-attribute
The reserved directory name; compared case-insensitively.
ALLOWED_PARENT_KEYS
module-attribute
ALLOWED_PARENT_KEYS: dict[str, frozenset[str] | None] = {
"apiVersion": None,
"name": None,
"id": None,
"discovery": None,
"psadt": frozenset(
{
"app_vars",
"install",
"uninstall",
"override_msi_commands",
"override_msix_commands",
}
),
"intune": frozenset(
{
"detection",
"description",
"publisher",
"developer",
"privacy_url",
"info_url",
"run_as_account",
"run_as_32_bit",
"device_restart_behavior",
"max_run_time_minutes",
"minimum_supported_windows_release",
}
),
}
The keys a pinned parent may set.
A top-level key mapped to None is taken whole; one mapped to a set keeps only the named sub-keys. Any key not listed is dropped, so a field this version of NAPT does not know never reaches the merge. The rule for a new recipe field: org-policy fields stay off the list; strategy-specific, recipe-required, and absent-means-skip fields go on it.
PinnedLocation
dataclass
Where a pinned copy sits relative to its upstream/ directory.
Attributes:
| Name | Type | Description |
|---|---|---|
upstream_dir |
Path
|
The |
relative |
PurePosixPath
|
The parent's path below that directory, forward slashes, which is the key its lockfile entry is found by. |
Source code in napt/upstream/pinned.py
pinned_location
Decides whether a parent reference points under upstream/.
Only the path between the override's directory and the parent is
examined: an absolute reference is first made relative to the
override, and leading .. segments are skipped. A reference on
another drive cannot be made relative and is local.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_dir
|
Path
|
The directory of the override declaring |
required |
parent_ref
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
PinnedLocation | None
|
The parent's location when it is a pinned copy, or None when it is a local parent. |
Source code in napt/upstream/pinned.py
tracked_location
Finds the tracked upstream/ directory a file really sits under.
The path is resolved, so a symlink or junction that points into
upstream/ from elsewhere is seen for what it is. A directory named
upstream counts only with an upstream.yaml beside it, so a
project that merely lives under a folder called upstream is not
affected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
A recipe or parent file. |
required |
Returns:
| Type | Description |
|---|---|
PinnedLocation | None
|
The file's location under the tracked directory, or None. |
Source code in napt/upstream/pinned.py
pinned_copy_of_override
Resolves an override's parent to the pinned copy it names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
override
|
Path
|
A recipe file that declares |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved parent path. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When the file cannot be read or declares no parent. |
Source code in napt/upstream/pinned.py
is_pinned_copy
Reports whether a recipe file itself sits under a tracked upstream/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
The recipe a command was asked to run. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the file is a pinned copy rather than an override. |
Source code in napt/upstream/pinned.py
verify_pinned_copy
Checks a pinned parent against its lockfile entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_path
|
Path
|
The parent file, for messages. |
required |
location
|
PinnedLocation
|
Where the parent sits, from pinned_location. |
required |
data
|
bytes
|
The parent's bytes as read from disk. |
required |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When there is no lockfile beside the |
Source code in napt/upstream/pinned.py
filter_pinned_parent
Keeps only the keys a pinned parent may set.
A section the allow list restricts is filtered key by key when it is a mapping; one of another shape (a list, null, a string) is dropped whole and named, since merging it would replace the tenant's section instead of adding to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The parsed parent recipe. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], tuple[str, ...]]
|
The filtered copy and the dotted names of every dropped key, in the order the parent wrote them. |