basstler-git 4.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
basstler/git/branch.py ADDED
@@ -0,0 +1,43 @@
1
+ """
2
+ A git branch, the base of every branch the package handles.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from dataclasses import dataclass
8
+
9
+ from basstler.class_property import classproperty
10
+ from basstler.git.repository import GitRepository
11
+
12
+ # %% the branch
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class Branch[RepositoryType: GitRepository]:
17
+ """
18
+ A named branch of one git repository.
19
+ """
20
+
21
+ repository: RepositoryType
22
+ """
23
+ The repository the branch belongs to.
24
+ """
25
+
26
+ name: str
27
+ """
28
+ The branch's name, without the namespace it is kept under.
29
+ """
30
+
31
+ @classproperty
32
+ def namespace(cls) -> str:
33
+ """
34
+ The namespace every branch is kept under in a repository.
35
+ """
36
+ return "refs/heads"
37
+
38
+ @property
39
+ def reference(self) -> str:
40
+ """
41
+ :return: The full reference the branch is kept under.
42
+ """
43
+ return f"{self.namespace}/{self.name}"
@@ -0,0 +1,571 @@
1
+ """
2
+ Running git for a pass, and deciding what a pass is allowed to publish.
3
+
4
+ Every command a pass runs goes through :class:`GitCommandRunner`, and every push it
5
+ proposes is built as a :class:`ProposedPush` - so whether published history may be
6
+ rewritten is decided in one place rather than at each call site.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ import subprocess
13
+ import tempfile
14
+ from collections.abc import Mapping
15
+ from dataclasses import dataclass
16
+ from enum import StrEnum
17
+ from pathlib import Path, PurePath, PurePosixPath
18
+
19
+ from basstler.class_property import classproperty
20
+ from basstler.environment import GitVariable
21
+ from basstler.exceptions import ExternalCallFailed, UnresolvableReferenceError
22
+ from basstler.exit_codes import CommandFailure, StackExitCode
23
+ from basstler.locations import CommitScratchFile, RepositoryStateLocation
24
+ from basstler.text_file import TextFile
25
+
26
+ # %% running git
27
+
28
+
29
+ class RemoteSubcommand(StrEnum):
30
+ """
31
+ The git subcommands that talk to a remote, whose failure may be the remote's.
32
+ """
33
+
34
+ FETCH = "fetch"
35
+ """
36
+ Updates references from a remote.
37
+ """
38
+
39
+ LIST_REMOTE = "ls-remote"
40
+ """
41
+ Lists the references a remote has.
42
+ """
43
+
44
+ PUSH = "push"
45
+ """
46
+ Publishes references to a remote.
47
+ """
48
+
49
+
50
+ @dataclass
51
+ class GitCommandFailed(CommandFailure, ExternalCallFailed):
52
+ """
53
+ Raised when a git command this module depends on the result of fails.
54
+ """
55
+
56
+ @classproperty
57
+ def exit_code(cls) -> StackExitCode:
58
+ """:return: The status this kind of error ends a command with."""
59
+ return StackExitCode.GIT_COMMAND_FAILED
60
+
61
+ arguments: tuple[str, ...] = ()
62
+ """
63
+ The git subcommand and its arguments, as invoked.
64
+ """
65
+
66
+ @property
67
+ def call(self) -> str:
68
+ """:return: The git command line, as invoked."""
69
+ return f"git {' '.join(self.arguments)}"
70
+
71
+ def suggest_correction(self) -> str:
72
+ if self.arguments and self.arguments[0] in set(RemoteSubcommand):
73
+ return (
74
+ f"check that the remote is reachable with this session's credential, "
75
+ f"then run `{self.call}` to see it succeed"
76
+ )
77
+ return f"run `{self.call}` in the checkout to see why git refused it"
78
+
79
+
80
+ @dataclass(frozen=True)
81
+ class GitCommandResult:
82
+ """
83
+ One finished git command, whether or not it succeeded.
84
+ """
85
+
86
+ arguments: tuple[str, ...]
87
+ """
88
+ The git subcommand and its arguments, as invoked.
89
+ """
90
+
91
+ exit_status: int
92
+ """
93
+ The status git exited with.
94
+ """
95
+
96
+ output: str
97
+ """
98
+ Git's stripped stdout.
99
+ """
100
+
101
+ error_output: str
102
+ """
103
+ Git's stripped stderr.
104
+ """
105
+
106
+ @property
107
+ def succeeded(self) -> bool:
108
+ """:return: Whether git exited zero."""
109
+ return self.exit_status == 0
110
+
111
+ def raise_if_failed(self) -> GitCommandResult:
112
+ """:return: This result, when the command succeeded.
113
+ :raises GitCommandFailed: When it did not."""
114
+ if not self.succeeded:
115
+ raise GitCommandFailed(
116
+ status=self.exit_status,
117
+ detail=self.error_output,
118
+ arguments=self.arguments,
119
+ )
120
+ return self
121
+
122
+
123
+ # %% what a pass is allowed to publish
124
+
125
+
126
+ @dataclass(frozen=True)
127
+ class ProposedPush:
128
+ """
129
+ One publication, and whether it is authorised to overwrite what is published.
130
+
131
+ Every push the executor makes is built here, so whether history may be rewritten is
132
+ decided once rather than at each call.
133
+ """
134
+
135
+ remote: str
136
+ """
137
+ The remote to publish to.
138
+ """
139
+
140
+ refspec: str
141
+ """
142
+ What to publish, as ``<source>:<destination>``.
143
+ """
144
+
145
+ with_lease: bool = False
146
+ """
147
+ Whether published history may be overwritten, and then only if the remote is where
148
+ this checkout last saw it.
149
+ """
150
+
151
+ @classmethod
152
+ def publishing(
153
+ cls,
154
+ remote: str,
155
+ branch: str,
156
+ strategy: IntegrationStrategy,
157
+ replaces_superseded_merges: bool = False,
158
+ ) -> ProposedPush:
159
+ """
160
+ Build the push that publishes a restacked branch.
161
+
162
+ :param remote: The remote to publish to: the fork's.
163
+ :param branch: The branch to publish.
164
+ :param strategy: How its parent was integrated, which authorises a rewrite when
165
+ it is a rebase - and which ``Stack.build`` sets to rebase only from the label.
166
+ :param replaces_superseded_merges: Whether the integration replaced merges that
167
+ only brought in an earlier state of the parent, the one rewrite a merge is
168
+ authorised to make.
169
+ :return: The push.
170
+ """
171
+ return cls(
172
+ remote=remote,
173
+ refspec=f"{branch}:{branch}",
174
+ with_lease=strategy is IntegrationStrategy.REBASE
175
+ or replaces_superseded_merges,
176
+ )
177
+
178
+
179
+ @dataclass(frozen=True)
180
+ class GitCommandRunner:
181
+ """
182
+ Runs git in one checkout, reporting failures rather than swallowing them.
183
+
184
+ ``stack/checkout.py`` reads git through a helper that returns an empty string when a command
185
+ fails. That is right for derivation, where a missing ref simply means "no answer",
186
+ and wrong here: a push that silently did nothing would be indistinguishable from one
187
+ that worked.
188
+ """
189
+
190
+ working_directory: Path
191
+ """
192
+ The checkout every command runs in.
193
+ """
194
+
195
+ def attempt(
196
+ self, *arguments: str, environment: Mapping[str, str] | None = None
197
+ ) -> GitCommandResult:
198
+ """
199
+ Run a command whose failure is an expected outcome.
200
+
201
+ :param arguments: The git subcommand and its arguments.
202
+ :param environment: Variables to set for this command on top of the process's
203
+ own.
204
+ :return: The finished command.
205
+ """
206
+ completed = subprocess.run(
207
+ ["git", *arguments],
208
+ cwd=self.working_directory,
209
+ capture_output=True,
210
+ encoding="utf-8",
211
+ env={**os.environ, **(environment or {})},
212
+ )
213
+ return GitCommandResult(
214
+ arguments=arguments,
215
+ exit_status=completed.returncode,
216
+ output=completed.stdout.strip(),
217
+ error_output=completed.stderr.strip(),
218
+ )
219
+
220
+ def run(self, *arguments: str, environment: Mapping[str, str] | None = None) -> str:
221
+ """
222
+ Run a command this module depends on the result of.
223
+
224
+ :param arguments: The git subcommand and its arguments.
225
+ :param environment: Variables to set for this command on top of the process's
226
+ own.
227
+ :return: Git's stripped stdout.
228
+ :raises GitCommandFailed: If git exits non-zero.
229
+ """
230
+ return (
231
+ self.attempt(*arguments, environment=environment).raise_if_failed().output
232
+ )
233
+
234
+ def repository_state_path(self, location: RepositoryStateLocation) -> Path:
235
+ """
236
+ :param location: Scratch state kept per repository.
237
+ :return: Where it lives for this checkout's repository, the same from every
238
+ worktree of it.
239
+ """
240
+ common_directory = self.run(
241
+ "rev-parse", "--path-format=absolute", "--git-common-dir"
242
+ )
243
+ return Path(common_directory) / location
244
+
245
+ def fetch(self, remote: str, *references: str) -> None:
246
+ """
247
+ Refresh what this checkout knows about a remote.
248
+
249
+ :param remote: The remote to fetch from.
250
+ :param references: The branches to fetch, all of them when none is named.
251
+ """
252
+ self.run("fetch", "--quiet", remote, *references)
253
+
254
+ def fetch_branch(
255
+ self, location: str, branch: str, tracking_remote: str
256
+ ) -> GitCommandResult:
257
+ """
258
+ Fetch one branch into its tracking ref, leaving ``FETCH_HEAD`` alone.
259
+
260
+ :param location: The remote name or URL to fetch from.
261
+ :param branch: The branch to fetch.
262
+ :param tracking_remote: The remote whose tracking refs the branch is kept under.
263
+ :return: The finished fetch, whose failure is an expected outcome.
264
+ """
265
+ return self.attempt(
266
+ "fetch",
267
+ "--quiet",
268
+ "--no-write-fetch-head",
269
+ location,
270
+ f"+refs/heads/{branch}:refs/remotes/{tracking_remote}/{branch}",
271
+ )
272
+
273
+ def configured_remote_url(self, remote: str) -> str | None:
274
+ """
275
+ :param remote: A remote's name.
276
+ :return: The URL the clone configures for it, not git's rewrite of it, ``None``
277
+ for no such remote.
278
+ """
279
+ read = self.attempt("config", "--get", f"remote.{remote}.url")
280
+ return read.output if read.succeeded else None
281
+
282
+ def commit_or_none(self, reference: str) -> str | None:
283
+ """:param reference: A ref that may not exist.
284
+ :return: The commit it names, or ``None`` if it does not exist."""
285
+ resolved = self.attempt("rev-parse", "--verify", "--quiet", reference)
286
+ return resolved.output if resolved.succeeded else None
287
+
288
+ def commit_at(self, reference: str) -> str:
289
+ """:param reference: Any reference git can resolve.
290
+ :return: The commit it names."""
291
+ return self.run("rev-parse", reference)
292
+
293
+ def local_commit(self, branch: str) -> str | None:
294
+ """:param branch: A branch name.
295
+ :return: The commit this checkout's own copy of the branch is at, ``None`` when
296
+ it has none."""
297
+ found = self.attempt("rev-parse", "--verify", "--quiet", f"refs/heads/{branch}")
298
+ return found.output if found.succeeded else None
299
+
300
+ def restore_branch(self, branch: str, commit: str | None) -> None:
301
+ """
302
+ Put this checkout's own copy of a branch back where it was.
303
+
304
+ :param branch: The branch to restore.
305
+ :param commit: Where it was, or ``None`` to have no copy of it.
306
+ """
307
+ reference = f"refs/heads/{branch}"
308
+ if commit is None:
309
+ self.run("update-ref", "-d", reference)
310
+ return
311
+ self.run("update-ref", reference, commit)
312
+
313
+ def file_at(self, commit: str, path: str | PurePath) -> str | None:
314
+ """
315
+ :param commit: The commit to read from.
316
+ :param path: The file's path from the commit's root.
317
+ :return: Its text without the final newline, or ``None`` when the commit has
318
+ no such file.
319
+ """
320
+ shown = self.attempt("show", f"{commit}:{PurePosixPath(path)}")
321
+ return shown.output if shown.succeeded else None
322
+
323
+ def commit_files(
324
+ self,
325
+ parent: str | None,
326
+ files: Mapping[str, str],
327
+ message: str,
328
+ merged_parents: tuple[str, ...] = (),
329
+ ) -> str:
330
+ """
331
+ Commit files on top of a commit without touching the working tree or the index,
332
+ keeping every file of the parent not given.
333
+
334
+ :param parent: The commit to build on, ``None`` for a commit with no parent.
335
+ :param files: What to write, by path, each without its final newline.
336
+ :param message: The commit message.
337
+ :param merged_parents: Further parents after *parent*, whose files the commit
338
+ does not keep.
339
+ :return: The new commit.
340
+ """
341
+ with tempfile.TemporaryDirectory() as scratch:
342
+ index = {
343
+ GitVariable.INDEX_FILE: str(Path(scratch) / CommitScratchFile.INDEX)
344
+ }
345
+ self.run("read-tree", parent or "--empty", environment=index)
346
+ blob_file = Path(scratch) / CommitScratchFile.BLOB
347
+ for path, text in files.items():
348
+ TextFile(blob_file).write(text + "\n")
349
+ blob = self.run("hash-object", "-w", str(blob_file))
350
+ self.run(
351
+ "update-index",
352
+ "--add",
353
+ "--cacheinfo",
354
+ f"100644,{blob},{path}",
355
+ environment=index,
356
+ )
357
+ tree = self.run("write-tree", environment=index)
358
+ parents = [
359
+ argument
360
+ for commit in (parent, *merged_parents)
361
+ if commit
362
+ for argument in ("-p", commit)
363
+ ]
364
+ return self.run("commit-tree", tree, *parents, "-m", message)
365
+
366
+ def parents_of(self, commit: str) -> tuple[str, ...]:
367
+ """:param commit: Any reference git can resolve to a commit.
368
+ :return: The commit's parents, its first parent first."""
369
+ return tuple(
370
+ self.run("rev-list", "--parents", "--max-count=1", commit).split()[1:]
371
+ )
372
+
373
+ def tree_of(self, commit: str) -> str:
374
+ """:param commit: Any reference git can resolve to a commit.
375
+ :return: The tree the commit records."""
376
+ return self.run("rev-parse", f"{commit}^{{tree}}")
377
+
378
+ def automatic_merge_tree(self, first: str, second: str) -> str | None:
379
+ """
380
+ Merge two commits without touching any branch or the working tree.
381
+
382
+ :param first: One side of the merge.
383
+ :param second: The other side.
384
+ :return: The tree merging them produces, or ``None`` when it conflicts.
385
+ """
386
+ merge = self.attempt("merge-tree", "--write-tree", first, second)
387
+ return merge.output.splitlines()[0] if merge.succeeded else None
388
+
389
+ def adds_only_merges(self, candidate: str, *references: str) -> bool:
390
+ """:param candidate: The reference whose history is examined.
391
+ :param references: The references it is compared against.
392
+ :return: Whether every commit *candidate* holds beyond all of *references* is a
393
+ merge.
394
+ :raises UnresolvableReferenceError: If any reference names no commit here.
395
+ """
396
+ for compared in (*references, candidate):
397
+ if not self.attempt(
398
+ "rev-parse", "--verify", "--quiet", f"{compared}^{{commit}}"
399
+ ).succeeded:
400
+ raise UnresolvableReferenceError(reference=compared)
401
+ beyond = self.run(
402
+ "rev-list",
403
+ "--no-merges",
404
+ "--max-count=1",
405
+ candidate,
406
+ *(f"^{reference}" for reference in references),
407
+ )
408
+ return not beyond
409
+
410
+ def checkout(self, branch: str, start_point: str) -> None:
411
+ """
412
+ Put a branch at a starting point and check it out.
413
+
414
+ :param branch: The branch to move and check out.
415
+ :param start_point: What to point it at.
416
+ """
417
+ self.run("checkout", "--quiet", "-B", branch, start_point)
418
+
419
+ def checked_out_branch(self) -> str:
420
+ """:return: The branch whose content a push would move."""
421
+ return self.run("branch", "--show-current")
422
+
423
+ def merge(self, reference: str, message: str) -> GitCommandResult:
424
+ """:param reference: The reference to merge in.
425
+ :param message: The merge commit's message.
426
+ :return: The finished merge, whose failure is a conflict only when it left
427
+ unmerged paths behind."""
428
+ return self.attempt("merge", "--no-edit", "--message", message, reference)
429
+
430
+ def trailer_value(self, commit: str, trailer: CommitTrailer) -> str:
431
+ """:param commit: Any reference git can resolve to a commit.
432
+ :param trailer: The trailer key read.
433
+ :return: The value the commit's message gives that trailer, empty when it has
434
+ none."""
435
+ return self.run(
436
+ "log",
437
+ "--max-count=1",
438
+ f"--format=%(trailers:key={trailer},valueonly)",
439
+ commit,
440
+ )
441
+
442
+ def rebase(self, reference: str) -> GitCommandResult:
443
+ """:param reference: The reference to rebase onto.
444
+ :return: The finished rebase, whose failure is a conflict only when it left
445
+ unmerged paths behind."""
446
+ return self.attempt("rebase", reference)
447
+
448
+ def abandon(self, strategy: IntegrationStrategy) -> None:
449
+ """
450
+ Undo whichever integration just failed.
451
+
452
+ :param strategy: The integration that was attempted.
453
+ """
454
+ self.attempt(
455
+ "rebase" if strategy is IntegrationStrategy.REBASE else "merge", "--abort"
456
+ )
457
+
458
+ def unmerged_paths(self) -> tuple[str, ...]:
459
+ """:return: The paths the integration that just failed left conflicted."""
460
+ unmerged = self.attempt("diff", "--name-only", "--diff-filter=U")
461
+ return tuple(path for path in unmerged.output.splitlines() if path)
462
+
463
+ def push(self, proposed: ProposedPush) -> GitCommandResult:
464
+ """
465
+ Publish a refspec, forcing only where the push itself says it is authorised.
466
+
467
+ :param proposed: What to publish, and whether a rewrite is authorised.
468
+ :return: The finished push, whose failure the caller reports rather than forces.
469
+ """
470
+ lease = ["--force-with-lease"] if proposed.with_lease else []
471
+ return self.attempt(
472
+ "push", "--quiet", *lease, proposed.remote, proposed.refspec
473
+ )
474
+
475
+ def contains(self, candidate: str, descendant: str) -> bool:
476
+ """:param candidate: The reference that may be contained.
477
+ :param descendant: The reference that may contain it.
478
+ :return: Whether *candidate* is an ancestor of *descendant*."""
479
+ return self.attempt(
480
+ "merge-base", "--is-ancestor", candidate, descendant
481
+ ).succeeded
482
+
483
+ def share_history(self, first: str, second: str) -> bool:
484
+ """
485
+ :param first: Any reference git can resolve to a commit.
486
+ :param second: Another one.
487
+ :return: Whether the two commits have a common ancestor.
488
+ """
489
+ return self.attempt("merge-base", first, second).succeeded
490
+
491
+ def merge_base(self, first: str, second: str) -> str:
492
+ """
493
+ :param first: Any reference git can resolve to a commit.
494
+ :param second: Another one.
495
+ :return: The best common ancestor of the two commits.
496
+ """
497
+ return self.run("merge-base", first, second)
498
+
499
+
500
+ @dataclass(frozen=True)
501
+ class TransientGitSetting:
502
+ """
503
+ A git config setting in force for the processes given it, written to no config file
504
+ and taking precedence over every one.
505
+ """
506
+
507
+ key: str
508
+ """
509
+ The setting's key, such as ``user.name``.
510
+ """
511
+
512
+ value: str
513
+ """
514
+ The value it takes.
515
+ """
516
+
517
+ def variables(self, environment: Mapping[str, str]) -> dict[str, str]:
518
+ """
519
+ :param environment: The environment the setting is added to, whose own
520
+ transient settings stay in force.
521
+ :return: The variables that add it, to be merged over *environment*.
522
+ """
523
+ index = int(environment.get(GitVariable.CONFIGURATION_COUNT) or 0)
524
+ return {
525
+ GitVariable.CONFIGURATION_COUNT: str(index + 1),
526
+ f"{GitVariable.CONFIGURATION_KEY_PREFIX}{index}": self.key,
527
+ f"{GitVariable.CONFIGURATION_VALUE_PREFIX}{index}": self.value,
528
+ }
529
+
530
+
531
+ # %% commit trailers
532
+
533
+
534
+ class CommitTrailer(StrEnum):
535
+ """
536
+ The trailer keys basstler writes into the commits it makes, and later recognises
537
+ those commits by.
538
+ """
539
+
540
+ RESTACKED_PARENT = "Restacked-parent"
541
+ """
542
+ Names the parent a restack merged in, marking the merge as the restack's own rather
543
+ than one a person made.
544
+ """
545
+
546
+ RESTACKED_PARENT_COMMIT = "Restacked-parent-commit"
547
+ """
548
+ The commit of the parent a restack merged in, which a restack's own merge records as
549
+ its second parent.
550
+ """
551
+
552
+ ACTION_REQUEST = "Basstler-request"
553
+ """
554
+ The identifier of the upstream-reviews request whose branch the commit is on,
555
+ marking the branch as basstler's own rather than one a person made.
556
+ """
557
+
558
+
559
+ # %% integrating a moved parent
560
+
561
+
562
+ class IntegrationStrategy(StrEnum):
563
+ """How a branch integrates its parent's moved tip during a restack."""
564
+
565
+ MERGE = "merge"
566
+ """Merge the parent's tip in, replacing the merges earlier restacks left that only
567
+ brought in an older state of the parent, so the branch carries one such merge."""
568
+
569
+ REBASE = "rebase"
570
+ """Replay the branch onto the parent's tip, which rewrites published history and is
571
+ authorised only by the branch's own rebase label."""
@@ -0,0 +1,145 @@
1
+ """
2
+ The files changed between two commits, by how many lines and in both their versions.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from dataclasses import asdict, dataclass
8
+ from pathlib import PurePosixPath
9
+
10
+ from basstler.git.commands import GitCommandRunner
11
+
12
+ # %% one file's change
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class FileChange:
17
+ """
18
+ One file changed between two commits, and by how many lines.
19
+ """
20
+
21
+ path: PurePosixPath
22
+ """
23
+ Where the file is in the head commit, or was in the base commit when it is deleted.
24
+ """
25
+
26
+ insertions: int = 0
27
+ """
28
+ Lines added, zero for a binary file.
29
+ """
30
+
31
+ deletions: int = 0
32
+ """
33
+ Lines removed, zero for a binary file.
34
+ """
35
+
36
+ previous_path: PurePosixPath | None = None
37
+ """
38
+ Where the file was in the base commit, when the change moves it.
39
+ """
40
+
41
+ is_binary: bool = False
42
+ """
43
+ Whether git compares the file as binary, which leaves its lines uncounted.
44
+ """
45
+
46
+ @property
47
+ def changed_lines(self) -> int:
48
+ """
49
+ Lines added and removed together.
50
+ """
51
+ return self.insertions + self.deletions
52
+
53
+
54
+ @dataclass(frozen=True)
55
+ class FileVersions(FileChange):
56
+ """
57
+ A file's change, with the file's text in both commits.
58
+ """
59
+
60
+ base_text: str | None = None
61
+ """
62
+ The file's content in the base commit, ``None`` when it is added or binary.
63
+ """
64
+
65
+ head_text: str | None = None
66
+ """
67
+ The file's content in the head commit, ``None`` when it is deleted or binary.
68
+ """
69
+
70
+
71
+ # %% the changed files
72
+
73
+
74
+ @dataclass(frozen=True)
75
+ class CommitRange:
76
+ """
77
+ The change from a base commit to a head commit.
78
+ """
79
+
80
+ git: GitCommandRunner
81
+ """
82
+ The checkout holding both commits.
83
+ """
84
+
85
+ base_commit: str
86
+ """
87
+ The commit the change starts from.
88
+ """
89
+
90
+ head_commit: str
91
+ """
92
+ The commit the change ends at.
93
+ """
94
+
95
+ def file_changes(self) -> tuple[FileChange, ...]:
96
+ """
97
+ :return: Every file the range changes, in the order git lists them.
98
+ """
99
+ listing = iter(
100
+ self.git.run(
101
+ "diff",
102
+ "--numstat",
103
+ "-z",
104
+ "--find-renames",
105
+ self.base_commit,
106
+ self.head_commit,
107
+ ).split("\0")
108
+ )
109
+ changes: list[FileChange] = []
110
+ for entry in listing:
111
+ if not entry:
112
+ continue
113
+ insertions, deletions, path = entry.split("\t", 2)
114
+ previous_path = None
115
+ if not path:
116
+ previous_path = PurePosixPath(next(listing))
117
+ path = next(listing)
118
+ is_binary = insertions == "-"
119
+ changes.append(
120
+ FileChange(
121
+ PurePosixPath(path),
122
+ 0 if is_binary else int(insertions),
123
+ 0 if is_binary else int(deletions),
124
+ previous_path,
125
+ is_binary,
126
+ )
127
+ )
128
+ return tuple(changes)
129
+
130
+ def file_versions(self) -> tuple[FileVersions, ...]:
131
+ """
132
+ :return: Every file the range changes, with its texts read unless it is binary.
133
+ """
134
+ return tuple(
135
+ FileVersions(**asdict(change))
136
+ if change.is_binary
137
+ else FileVersions(
138
+ **asdict(change),
139
+ base_text=self.git.file_at(
140
+ self.base_commit, change.previous_path or change.path
141
+ ),
142
+ head_text=self.git.file_at(self.head_commit, change.path),
143
+ )
144
+ for change in self.file_changes()
145
+ )
@@ -0,0 +1,64 @@
1
+ """
2
+ Searching the files of one commit.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from dataclasses import dataclass
8
+
9
+ from basstler.exit_codes import ExitCode
10
+ from basstler.git.commands import GitCommandRunner
11
+
12
+ # %% the search
13
+
14
+
15
+ class GitGrepExitCode(ExitCode):
16
+ """
17
+ What ``git grep`` exits with.
18
+ """
19
+
20
+ SUCCESS = 0
21
+ """
22
+ At least one line matched.
23
+ """
24
+
25
+ NO_MATCH = 1
26
+ """
27
+ Nothing matched.
28
+ """
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class CommitTree:
33
+ """
34
+ The files of one commit, searched for words.
35
+ """
36
+
37
+ git: GitCommandRunner
38
+ """
39
+ The checkout holding the commit.
40
+ """
41
+
42
+ commit: str
43
+ """
44
+ The commit searched.
45
+ """
46
+
47
+ def mentions(self, word: str) -> bool:
48
+ """
49
+ :param word: A name or any other fixed string.
50
+ :return: Whether any file of the commit holds it as a whole word.
51
+ :raises GitCommandFailed: If the search itself fails.
52
+ """
53
+ search = self.git.attempt(
54
+ "grep",
55
+ "--quiet",
56
+ "--word-regexp",
57
+ "--fixed-strings",
58
+ "-e",
59
+ word,
60
+ self.commit,
61
+ )
62
+ if search.exit_status == GitGrepExitCode.NO_MATCH:
63
+ return False
64
+ return search.raise_if_failed().succeeded
basstler/git/remote.py ADDED
@@ -0,0 +1,35 @@
1
+ """
2
+ A remote of a clone: the repository a remote name or URL points at.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from dataclasses import dataclass
8
+
9
+ from basstler.git.commands import GitCommandRunner
10
+ from basstler.git.repository import GitRepository
11
+
12
+ # %% the remote
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class Remote(GitRepository):
17
+ """
18
+ The repository one remote of a clone points at.
19
+ """
20
+
21
+ git: GitCommandRunner
22
+ """
23
+ The clone the remote is reached from.
24
+ """
25
+
26
+ location: str
27
+ """
28
+ The remote, as a remote name in the clone or a URL.
29
+ """
30
+
31
+ @property
32
+ def url(self) -> str:
33
+ return self.git.attempt("remote", "get-url", self.location).output or (
34
+ self.location
35
+ )
@@ -0,0 +1,212 @@
1
+ """
2
+ One branch of a remote, read and written without touching the working tree.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import json
8
+ from collections.abc import Mapping
9
+ from dataclasses import dataclass
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ from basstler.class_property import classproperty
14
+ from basstler.git.branch import Branch
15
+ from basstler.git.commands import GitCommandResult, ProposedPush
16
+ from basstler.git.remote import Remote
17
+ from basstler.json_model import JSONSerializable
18
+
19
+ # %% the branch
20
+
21
+ FileContent = str | dict[str, Any] | JSONSerializable
22
+ """
23
+ What a file is written from: its text, or a JSON object or a value written as one.
24
+ """
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class RemoteBranch[RemoteType: Remote](Branch[RemoteType]):
29
+ """
30
+ One branch of one remote, read and written without touching the working tree.
31
+ """
32
+
33
+ @classproperty
34
+ def local_reference_prefix(cls) -> str:
35
+ """
36
+ Where every fetched branch is kept, so a fetch never moves ``FETCH_HEAD`` under
37
+ anyone else.
38
+ """
39
+ return "refs/basstler/remote-branches"
40
+
41
+ @property
42
+ def local_reference(self) -> str:
43
+ """
44
+ :return: Where a fetch of this branch is kept.
45
+ """
46
+ return f"{self.local_reference_prefix}/{self.name}"
47
+
48
+ def exists(self) -> bool:
49
+ """
50
+ :return: Whether the remote can be reached and has this branch.
51
+ """
52
+ return bool(
53
+ self.repository.git.attempt(
54
+ "ls-remote", "--heads", self.repository.location, self.name
55
+ ).output
56
+ )
57
+
58
+ def fetch(self) -> str | None:
59
+ """
60
+ :return: The branch's tip commit, or ``None`` when the remote has no such branch.
61
+ """
62
+ if not self.exists():
63
+ return None
64
+ self.repository.git.fetch(
65
+ self.repository.location,
66
+ "--no-tags",
67
+ "--no-write-fetch-head",
68
+ f"+{self.reference}:{self.local_reference}",
69
+ )
70
+ return self.repository.git.commit_at(self.local_reference)
71
+
72
+ def read_latest(self, path: str | Path) -> str | None:
73
+ """
74
+ :param path: The file's path from the branch's root.
75
+ :return: Its text at the branch's current tip without the final newline, or
76
+ ``None`` when the remote has no such branch or the branch no such file.
77
+ """
78
+ tip = self.fetch()
79
+ return self.repository.git.file_at(tip, path) if tip else None
80
+
81
+ def read_every_latest(self, directory: str | Path, file_name: str) -> list[str]:
82
+ """
83
+ :param directory: A directory from the branch's root.
84
+ :param file_name: The name of the files to read.
85
+ :return: The text of every file of that name anywhere under the directory at
86
+ the branch's current tip, in path order; empty when the remote has no such
87
+ branch.
88
+ """
89
+ tip = self.fetch()
90
+ if tip is None:
91
+ return []
92
+ listed = self.repository.git.run(
93
+ "ls-tree", "-r", "--name-only", tip, "--", Path(directory).as_posix()
94
+ )
95
+ return [
96
+ self.repository.git.file_at(tip, path)
97
+ for path in sorted(listed.splitlines())
98
+ if Path(path).name == file_name
99
+ ]
100
+
101
+ def attempt_write(
102
+ self, files: Mapping[str, FileContent], message: str, attempts: int = 3
103
+ ) -> FileWrite:
104
+ """
105
+ Commit files onto the branch's latest tip and push them, again on top of another
106
+ writer's commit when that landed first.
107
+
108
+ :param files: What to write, by path, each without its final newline.
109
+ :param message: The commit message.
110
+ :param attempts: How many times to commit and push before giving up.
111
+ :return: The last commit and its push, failed when every attempt was refused.
112
+ """
113
+ for _ in range(attempts):
114
+ commit = self.commit_on(self.fetch(), files, message)
115
+ pushed = self.repository.git.push(
116
+ ProposedPush(self.repository.location, f"{commit}:{self.reference}")
117
+ )
118
+ if pushed.succeeded:
119
+ break
120
+ return FileWrite(commit, pushed)
121
+
122
+ def write(
123
+ self, files: Mapping[str, FileContent], message: str, attempts: int = 3
124
+ ) -> str:
125
+ """
126
+ Like :meth:`attempt_write`, but a refused push is an error.
127
+
128
+ :return: The pushed commit.
129
+ :raises GitCommandFailed: If the last push is refused too.
130
+ """
131
+ written = self.attempt_write(files, message, attempts)
132
+ written.push.raise_if_failed()
133
+ return written.commit
134
+
135
+ def attempt_create(
136
+ self, parent: str, files: Mapping[str, FileContent], message: str
137
+ ) -> FileWrite:
138
+ """
139
+ Commit files on top of another branch's commit and push them as this branch.
140
+
141
+ :param parent: The commit to build on.
142
+ :param files: What to write, by path, each without its final newline.
143
+ :param message: The commit message.
144
+ :return: The commit and its push, failed when the remote refused it.
145
+ """
146
+ commit = self.commit_on(parent, files, message)
147
+ return FileWrite(
148
+ commit,
149
+ self.repository.git.push(
150
+ ProposedPush(self.repository.location, f"{commit}:{self.reference}")
151
+ ),
152
+ )
153
+
154
+ def create(
155
+ self, parent: str, files: Mapping[str, FileContent], message: str
156
+ ) -> str:
157
+ """
158
+ Like :meth:`attempt_create`, but a refused push is an error.
159
+
160
+ :return: The pushed commit.
161
+ :raises GitCommandFailed: If the remote refuses the push.
162
+ """
163
+ written = self.attempt_create(parent, files, message)
164
+ written.push.raise_if_failed()
165
+ return written.commit
166
+
167
+ def commit_on(
168
+ self, parent: str | None, files: Mapping[str, FileContent], message: str
169
+ ) -> str:
170
+ """
171
+ Commit files on top of a commit, a JSON object as its indented JSON text.
172
+
173
+ :param parent: The commit to build on, ``None`` for a commit with no parent.
174
+ :param files: What to write, by path, each without its final newline.
175
+ :param message: The commit message.
176
+ :return: The new commit.
177
+ """
178
+ texts = {}
179
+ for path, content in files.items():
180
+ if isinstance(content, JSONSerializable):
181
+ content = content.to_json()
182
+ if isinstance(content, dict):
183
+ content = json.dumps(content, indent=2)
184
+ texts[path] = content
185
+ return self.repository.git.commit_files(parent, texts, message)
186
+
187
+ def delete(self) -> GitCommandResult:
188
+ """
189
+ Delete the branch from the remote.
190
+
191
+ :return: The push deleting it, failed when the remote refused it.
192
+ """
193
+ return self.repository.git.push(
194
+ ProposedPush(self.repository.location, f":{self.reference}")
195
+ )
196
+
197
+
198
+ @dataclass(frozen=True)
199
+ class FileWrite:
200
+ """
201
+ One commit of files onto a branch, and its push.
202
+ """
203
+
204
+ commit: str
205
+ """
206
+ The commit.
207
+ """
208
+
209
+ push: GitCommandResult
210
+ """
211
+ Its push, failed when the remote refused it.
212
+ """
@@ -0,0 +1,22 @@
1
+ """
2
+ A git repository, the owner every branch belongs to.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from abc import ABC, abstractmethod
8
+
9
+ # %% the repository
10
+
11
+
12
+ class GitRepository(ABC):
13
+ """
14
+ A git repository, which every branch belongs to.
15
+ """
16
+
17
+ @property
18
+ @abstractmethod
19
+ def url(self) -> str:
20
+ """
21
+ The URL the repository is fetched from and pushed to.
22
+ """
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.5
2
+ Name: basstler-git
3
+ Version: 4.2.0
4
+ Summary: Git commands and branches, for basstler.
5
+ Project-URL: Source, https://github.com/KAOS-repositories/basstler
6
+ Project-URL: Bug Tracker, https://github.com/KAOS-repositories/basstler/issues
7
+ Author-email: Abdelrhman Bassiouny <bido.bassuny@gmail.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Requires-Python: >=3.12
12
+ Requires-Dist: basstler-core==4.2.0
@@ -0,0 +1,13 @@
1
+ basstler/git/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ basstler/git/branch.py,sha256=-q7Iz_V2Q2oxS0xer1NiFa28iMgJQA7OYMcn-cG6fRk,919
3
+ basstler/git/commands.py,sha256=hZKv_-_g2ngm0tK4SnqRKkuEzmbuTGbsPI1USUlFDW8,20007
4
+ basstler/git/commit_range.py,sha256=VGHMhXaPqJISz79FDbaA_mTKFbfqJopgFIo2fmKpdWI,3639
5
+ basstler/git/commit_tree.py,sha256=sCpk7r5f-NfcfOO3jRF1MW-MZXBTMQsMrOj0KXNGNO0,1277
6
+ basstler/git/remote.py,sha256=7yF93fRB6gLzHdy-42ky6g0x2XJ5jXx_iMpCFzK_Qa0,722
7
+ basstler/git/remote_branch.py,sha256=U8MU0nim1XJFb8nhYxnG0lHooakK3rG6gptAUeI1nsQ,7157
8
+ basstler/git/repository.py,sha256=tjnJsxtqiEFx1gK5rQx8sc8poKbipnQpEUSGyrOO8w8,399
9
+ basstler_git-4.2.0.dist-info/METADATA,sha256=KkqEubfWfZCSd_pXV8YEqPwJtIN9B-CmKtsIiEA9lBM,446
10
+ basstler_git-4.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ basstler_git-4.2.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
12
+ basstler_git-4.2.0.dist-info/licenses/NOTICE,sha256=dBp1KVYEzyxlNrbsD-iH86mHlxEPlBHlGoqx8R_GNDM,695
13
+ basstler_git-4.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,13 @@
1
+ basstler
2
+ Copyright 2026 Abdelrhman Bassiouny and the basstler contributors
3
+
4
+ basstler (https://github.com/KAOS-repositories/basstler) is licensed under the
5
+ Apache License, Version 2.0 (see LICENSE). Abdelrhman Bassiouny wrote it
6
+ independently of any employer or institution and maintains it in the
7
+ KAOS-repositories organization on GitHub; contributors keep the copyright on
8
+ their contributions.
9
+
10
+ packages/core/src/basstler/{exceptions,class_property}.py contain code adapted
11
+ from krrood (https://github.com/cram2/cognitive_robot_abstract_machine/tree/main/krrood),
12
+ copyright the krrood authors, which remains licensed under the GNU Lesser
13
+ General Public License, version 3 only (LGPL-3.0-only).