basstler 4.2.0__tar.gz

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.
Files changed (36) hide show
  1. basstler-4.2.0/.gitignore +13 -0
  2. basstler-4.2.0/LICENSE +202 -0
  3. basstler-4.2.0/NOTICE +13 -0
  4. basstler-4.2.0/PKG-INFO +20 -0
  5. basstler-4.2.0/pyproject.toml +68 -0
  6. basstler-4.2.0/src/basstler/__main__.py +33 -0
  7. basstler-4.2.0/tests/__init__.py +0 -0
  8. basstler-4.2.0/tests/bash_path.py +43 -0
  9. basstler-4.2.0/tests/conftest.py +25 -0
  10. basstler-4.2.0/tests/hooks/__init__.py +0 -0
  11. basstler-4.2.0/tests/hooks/test_basstler_entry_point.py +257 -0
  12. basstler-4.2.0/tests/hooks/test_check_setup.py +1081 -0
  13. basstler-4.2.0/tests/hooks/test_create_personal_notes_branch.py +59 -0
  14. basstler-4.2.0/tests/hooks/test_git_identity_sync.py +425 -0
  15. basstler-4.2.0/tests/hooks/test_personal_notes_saving.py +81 -0
  16. basstler-4.2.0/tests/hooks/test_personal_settings_sync.py +263 -0
  17. basstler-4.2.0/tests/hooks/test_plan_updates_since.py +448 -0
  18. basstler-4.2.0/tests/hooks/test_save_plan.py +906 -0
  19. basstler-4.2.0/tests/hooks/test_save_pr_progress.py +204 -0
  20. basstler-4.2.0/tests/hooks/test_session_start.py +2675 -0
  21. basstler-4.2.0/tests/publish_jobs.py +27 -0
  22. basstler-4.2.0/tests/skills/__init__.py +0 -0
  23. basstler-4.2.0/tests/skills/test_manifest_staleness_document.py +159 -0
  24. basstler-4.2.0/tests/skills/test_setup_prerequisite_documents.py +201 -0
  25. basstler-4.2.0/tests/skills/test_setup_skill_rows.py +52 -0
  26. basstler-4.2.0/tests/skills/test_skill_document_sizes.py +101 -0
  27. basstler-4.2.0/tests/skills/test_skill_documents.py +402 -0
  28. basstler-4.2.0/tests/skills/test_starter_notes_stay_generic.py +115 -0
  29. basstler-4.2.0/tests/test_basstler_command.py +42 -0
  30. basstler-4.2.0/tests/test_distribution_build.py +271 -0
  31. basstler-4.2.0/tests/test_license.py +34 -0
  32. basstler-4.2.0/tests/test_package_contract.py +492 -0
  33. basstler-4.2.0/tests/test_publish_workflow.py +195 -0
  34. basstler-4.2.0/tests/test_shipped_locations.py +25 -0
  35. basstler-4.2.0/tests/test_windows_setup_workflow.py +32 -0
  36. basstler-4.2.0/tests/test_windows_tests_workflow.py +129 -0
@@ -0,0 +1,13 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ .venv/
4
+ .pytest_cache/
5
+
6
+ # What the plugin's own session start writes into the project it serves - this
7
+ # repository, when developing it with its own plugin enabled. Personal, never committed.
8
+ CLAUDE.local.md
9
+ .claude/settings.local.json
10
+
11
+ # Everything the last maintenance pass did, written by `python3 -m basstler.maintenance
12
+ # run-report` beside the board. Scratch state, never committed.
13
+ src/basstler/maintenance-report.json
basstler-4.2.0/LICENSE ADDED
@@ -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.
basstler-4.2.0/NOTICE ADDED
@@ -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).
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.5
2
+ Name: basstler
3
+ Version: 4.2.0
4
+ Summary: Workflow tooling: stacked-pull-request maintenance, the plan site, personal-notes hooks and upstream review reading.
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
+ Requires-Python: >=3.12
10
+ Requires-Dist: basstler-core==4.2.0
11
+ Requires-Dist: basstler-git==4.2.0
12
+ Requires-Dist: basstler-github==4.2.0
13
+ Requires-Dist: basstler-hub==4.2.0
14
+ Requires-Dist: basstler-notes==4.2.0
15
+ Requires-Dist: basstler-plan==4.2.0
16
+ Requires-Dist: basstler-review-triage==4.2.0
17
+ Requires-Dist: basstler-reviews==4.2.0
18
+ Requires-Dist: basstler-rules==4.2.0
19
+ Requires-Dist: basstler-stack==4.2.0
20
+ Requires-Dist: cyclopts>=5.3
@@ -0,0 +1,68 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24", "hatch-vcs>=0.4", "basstler-build"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "basstler"
7
+ description = "Workflow tooling: stacked-pull-request maintenance, the plan site, personal-notes hooks and upstream review reading."
8
+ requires-python = ">=3.12"
9
+ license = "Apache-2.0"
10
+ license-files = ["LICENSE", "NOTICE"]
11
+ authors = [{name = "Abdelrhman Bassiouny", email = "bido.bassuny@gmail.com"}]
12
+ dynamic = ["version", "dependencies"]
13
+
14
+ [project.scripts]
15
+ basstler = "basstler.__main__:app"
16
+
17
+ [project.urls]
18
+ "Source" = "https://github.com/KAOS-repositories/basstler"
19
+ "Bug Tracker" = "https://github.com/KAOS-repositories/basstler/issues"
20
+
21
+ [tool.hatch.version]
22
+ source = "vcs"
23
+ fallback-version = "0.0.0"
24
+ raw-options = {root = "../.."}
25
+
26
+ # Built with every basstler requirement pinned to this release.
27
+ [tool.hatch.metadata.hooks.basstler-sibling-pins]
28
+ family = "basstler"
29
+ dependencies = [
30
+ "cyclopts>=5.3",
31
+ "basstler-core",
32
+ "basstler-git",
33
+ "basstler-rules",
34
+ "basstler-github",
35
+ "basstler-reviews",
36
+ "basstler-review-triage",
37
+ "basstler-stack",
38
+ "basstler-plan",
39
+ "basstler-notes",
40
+ "basstler-hub",
41
+ ]
42
+
43
+ [tool.hatch.build.targets.wheel]
44
+ packages = ["src/basstler"]
45
+
46
+ # The repository's licence and notices, put at the root of the source distribution so
47
+ # the wheel built from it carries them.
48
+ [tool.hatch.build.targets.sdist.force-include]
49
+ "../../LICENSE" = "LICENSE"
50
+ "../../NOTICE" = "NOTICE"
51
+
52
+ # What this distribution's tests need besides itself.
53
+ [dependency-groups]
54
+ dev = [
55
+ "pytest",
56
+ "pytest-xdist",
57
+ "basstler-build",
58
+ "basstler-core",
59
+ "basstler-git",
60
+ "basstler-github",
61
+ "basstler-hub",
62
+ "basstler-notes",
63
+ "basstler-packaging",
64
+ "basstler-plan",
65
+ "basstler-reviews",
66
+ "basstler-review-triage",
67
+ "basstler-stack",
68
+ ]
@@ -0,0 +1,33 @@
1
+ """
2
+ The ``basstler`` command: one command tree that each v3 command is mounted on.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from functools import partial
8
+ from importlib.metadata import version
9
+
10
+ from cyclopts import App
11
+
12
+ from basstler.code_rules.command_line import code_rules_app
13
+ from basstler.locations import PackageLocation
14
+ from basstler.plan.handover_command import plan_handover_app
15
+ from basstler.plan.repository_rules_command import repository_rules_app
16
+ from basstler.review_triage.command_line import review_triage_app
17
+
18
+ app = App(
19
+ name=PackageLocation.DIRECTORY.name,
20
+ help="Workflow tooling for stacked pull requests and plans.",
21
+ version=partial(version, PackageLocation.DIRECTORY.name),
22
+ )
23
+ """
24
+ The command tree; a v3 command is added with ``@app.command``.
25
+ """
26
+
27
+ app.command(code_rules_app)
28
+ app.command(plan_handover_app)
29
+ app.command(repository_rules_app)
30
+ app.command(review_triage_app)
31
+
32
+ if __name__ == "__main__":
33
+ app()
File without changes
@@ -0,0 +1,43 @@
1
+ """
2
+ A path as the bash running the hook scripts writes it.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import os
8
+ import subprocess
9
+ from dataclasses import dataclass
10
+ from pathlib import Path
11
+
12
+ from basstler.bash import Bash
13
+
14
+ from basstler_testing.constants.paths import DatasetLocation
15
+
16
+ # %% the path bash prints
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class BashPath:
21
+ """
22
+ A path as a hook script prints it: Git Bash on Windows writes the temporary directory
23
+ as ``/tmp``, so a script's output names a path differently from Python.
24
+ """
25
+
26
+ path: Path
27
+ """
28
+ The path, as Python names it.
29
+ """
30
+
31
+ @property
32
+ def text(self) -> str:
33
+ """
34
+ :return: The path as bash writes it.
35
+ """
36
+ return subprocess.run(
37
+ Bash.locate(os.environ).command(
38
+ DatasetLocation.BASH_PATH_SCRIPT, self.path
39
+ ),
40
+ capture_output=True,
41
+ encoding="utf-8",
42
+ check=True,
43
+ ).stdout.removesuffix("\n")
@@ -0,0 +1,25 @@
1
+ """
2
+ The shared fixtures this distribution's tests use.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from basstler_testing.fixtures import (
8
+ package_environment_of_the_suite,
9
+ python3_directory,
10
+ running_shell_process_id,
11
+ stub_bin,
12
+ )
13
+ from basstler_testing.repository_fixtures import (
14
+ scratch_repository,
15
+ )
16
+
17
+ # %% the fixtures pytest finds here
18
+
19
+ __all__ = [
20
+ "package_environment_of_the_suite",
21
+ "python3_directory",
22
+ "running_shell_process_id",
23
+ "scratch_repository",
24
+ "stub_bin",
25
+ ]
File without changes
@@ -0,0 +1,257 @@
1
+ """
2
+ Tests for basstler.sh, the entry point every skill runs a module of the package through:
3
+
4
+ it runs the module once the package is ready, waits on or completes an install that is
5
+ not finished, and says in one line why when the package still cannot run.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import os
11
+ import subprocess
12
+ from pathlib import Path
13
+
14
+ import pytest
15
+
16
+ from basstler.bash import Bash
17
+ from basstler.locations import PluginLocation
18
+ from basstler.shell_configuration import ShellConfigurationFunction
19
+
20
+ from basstler_testing.constants.environment import (
21
+ ConfigurationVariable,
22
+ SearchPathVariable,
23
+ )
24
+ from basstler_testing.executable_stubs import (
25
+ ExecutableStubDirectory,
26
+ path_hiding_executables,
27
+ )
28
+ from basstler_testing.scratch_repository import ScratchRepository
29
+ from .test_session_start import PackageManager, StubVariable
30
+
31
+ MODULE_WITH_HELP = "maintenance"
32
+ """
33
+ A module of the package whose ``--help`` succeeds without a board or a credential.
34
+ """
35
+
36
+ # %% the scratch layout
37
+
38
+
39
+ @pytest.fixture
40
+ def entry_point_repository(scratch_repository: ScratchRepository) -> ScratchRepository:
41
+ """
42
+ A scratch repository whose plugin carries basstler.sh and whose package environment
43
+ is installed and current.
44
+
45
+ :param scratch_repository: The initialized scratch repository.
46
+ :return: The same repository.
47
+ """
48
+ scratch_repository.install_hook_scripts(
49
+ PluginLocation.PERSONAL_NOTES_CONFIGURATION_SCRIPT.name,
50
+ PluginLocation.ENTRY_POINT_SCRIPT.name,
51
+ )
52
+ scratch_repository.install_package()
53
+ scratch_repository.install_package_environment()
54
+ return scratch_repository
55
+
56
+
57
+ def run_entry_point(
58
+ repository: ScratchRepository, *arguments: str, **environment: str
59
+ ) -> subprocess.CompletedProcess[str]:
60
+ """
61
+ :param repository: The fixture-built scratch repository.
62
+ :param arguments: The module and its arguments.
63
+ :param environment: Variables to set for the run.
64
+ :return: The finished basstler.sh.
65
+ """
66
+ return repository.run_hook_script(
67
+ PluginLocation.ENTRY_POINT_SCRIPT.name, *arguments, **environment
68
+ )
69
+
70
+
71
+ def installed_source_file(repository: ScratchRepository) -> Path:
72
+ """
73
+ :param repository: The fixture-built scratch repository.
74
+ :return: The file recording what the environment's package was installed from.
75
+ """
76
+ return Path(
77
+ repository.configuration_value(ConfigurationVariable.INSTALLED_SOURCE_FILE)
78
+ )
79
+
80
+
81
+ def install_lock(repository: ScratchRepository) -> Path:
82
+ """
83
+ :param repository: The fixture-built scratch repository.
84
+ :return: The directory held while the package is installed.
85
+ """
86
+ return Path(repository.configuration_value(ConfigurationVariable.INSTALL_LOCK))
87
+
88
+
89
+ def hold_install_lock(repository: ScratchRepository, holder: int) -> Path:
90
+ """
91
+ :param repository: The fixture-built scratch repository.
92
+ :param holder: The process id to record as holding it.
93
+ :return: The lock, now held.
94
+ """
95
+ lock = install_lock(repository)
96
+ lock.mkdir(parents=True)
97
+ (lock / "pid").write_text(f"{holder}\n", encoding="utf-8")
98
+ return lock
99
+
100
+
101
+ def a_process_that_has_exited() -> int:
102
+ """
103
+ :return: The id of a process that has already exited.
104
+ """
105
+ finished = subprocess.Popen(["true"])
106
+ finished.wait()
107
+ return finished.pid
108
+
109
+
110
+ def uv_stub_path(stub_bin: ExecutableStubDirectory, tmp_path: Path) -> str:
111
+ """
112
+ :param stub_bin: The stub directory, holding the ``uv`` stub.
113
+ :param tmp_path: pytest's per-test temporary directory.
114
+ :return: A ``PATH`` finding the ``uv`` stub ahead of any real ``uv``.
115
+ """
116
+ stub_bin.install(PackageManager.UV)
117
+ return stub_bin.ahead_of(path_hiding_executables(tmp_path, PackageManager.UV))
118
+
119
+
120
+ # %% a ready package
121
+
122
+
123
+ def test_a_ready_package_runs_the_module(entry_point_repository: ScratchRepository):
124
+ result = run_entry_point(entry_point_repository, MODULE_WITH_HELP, "--help")
125
+
126
+ assert result.returncode == 0, result.stderr
127
+ assert f"basstler.{MODULE_WITH_HELP}" in result.stdout
128
+
129
+
130
+ # %% an install that is not finished
131
+
132
+
133
+ def test_an_install_that_never_finished_is_completed_before_the_module_runs(
134
+ entry_point_repository: ScratchRepository,
135
+ stub_bin: ExecutableStubDirectory,
136
+ tmp_path: Path,
137
+ ):
138
+ """
139
+ The session start died holding the lock, mid-install: the lock is taken over and the
140
+ install run again.
141
+ """
142
+ installed_source_file(entry_point_repository).unlink()
143
+ hold_install_lock(entry_point_repository, a_process_that_has_exited())
144
+ call_log = tmp_path / "uv-calls"
145
+
146
+ result = run_entry_point(
147
+ entry_point_repository,
148
+ MODULE_WITH_HELP,
149
+ "--help",
150
+ **{
151
+ SearchPathVariable.EXECUTABLE_SEARCH_PATH: uv_stub_path(stub_bin, tmp_path),
152
+ StubVariable.UV_CALL_LOG: str(call_log),
153
+ },
154
+ )
155
+
156
+ assert result.returncode == 0, result.stderr
157
+ assert len(call_log.read_text(encoding="utf-8").splitlines()) == 1
158
+ assert not install_lock(entry_point_repository).exists()
159
+
160
+
161
+ def test_an_install_still_running_is_waited_for_rather_than_repeated(
162
+ entry_point_repository: ScratchRepository,
163
+ stub_bin: ExecutableStubDirectory,
164
+ tmp_path: Path,
165
+ ):
166
+ """
167
+ An install another live process holds the lock for is waited for, not run twice.
168
+ """
169
+ source_file = installed_source_file(entry_point_repository)
170
+ source = source_file.read_text(encoding="utf-8")
171
+ source_file.unlink()
172
+ lock = install_lock(entry_point_repository)
173
+ running_install = subprocess.Popen(
174
+ Bash.locate(os.environ).command(
175
+ "-c",
176
+ 'printf "%s\n" "$$"; sleep 1; printf "%s" "$1" > "$2"; rm -rf "$3"',
177
+ "running-install",
178
+ source,
179
+ str(source_file),
180
+ str(lock),
181
+ ),
182
+ stdout=subprocess.PIPE,
183
+ encoding="utf-8",
184
+ )
185
+ hold_install_lock(entry_point_repository, running_install.pid)
186
+ call_log = tmp_path / "uv-calls"
187
+
188
+ result = run_entry_point(
189
+ entry_point_repository,
190
+ MODULE_WITH_HELP,
191
+ "--help",
192
+ **{
193
+ SearchPathVariable.EXECUTABLE_SEARCH_PATH: uv_stub_path(stub_bin, tmp_path),
194
+ StubVariable.UV_CALL_LOG: str(call_log),
195
+ },
196
+ )
197
+ running_install.wait()
198
+
199
+ assert result.returncode == 0, result.stderr
200
+ assert not call_log.exists()
201
+
202
+
203
+ # %% a package that cannot run
204
+
205
+
206
+ def test_a_failed_install_is_one_line_naming_what_to_run(
207
+ entry_point_repository: ScratchRepository,
208
+ stub_bin: ExecutableStubDirectory,
209
+ tmp_path: Path,
210
+ ):
211
+ """
212
+ A failed install ends the hook with one line naming the command that installs it.
213
+ """
214
+ installed_source_file(entry_point_repository).unlink()
215
+ search_path = {
216
+ SearchPathVariable.EXECUTABLE_SEARCH_PATH: uv_stub_path(stub_bin, tmp_path)
217
+ }
218
+
219
+ result = run_entry_point(
220
+ entry_point_repository,
221
+ MODULE_WITH_HELP,
222
+ "--help",
223
+ **search_path,
224
+ **{StubVariable.UV_STATUS: "1"},
225
+ )
226
+
227
+ source = entry_point_repository.configuration_output(
228
+ ShellConfigurationFunction.BASSTLER_PACKAGE_SOURCE
229
+ ).strip()
230
+ assert result.returncode == 1
231
+ assert result.stdout == ""
232
+ (line,) = result.stderr.splitlines()
233
+ assert line.startswith(f"could not install {source}: ")
234
+ assert line.endswith(
235
+ f" - run: {entry_point_repository.install_command(**search_path)}"
236
+ )
237
+
238
+
239
+ def test_an_install_held_by_a_live_process_past_the_wait_is_one_line_naming_the_lock(
240
+ entry_point_repository: ScratchRepository, running_shell_process_id: int
241
+ ):
242
+ installed_source_file(entry_point_repository).unlink()
243
+ hold_install_lock(entry_point_repository, running_shell_process_id)
244
+
245
+ result = run_entry_point(
246
+ entry_point_repository,
247
+ MODULE_WITH_HELP,
248
+ "--help",
249
+ **{ConfigurationVariable.INSTALL_WAIT_SECONDS: "0"},
250
+ )
251
+
252
+ assert result.returncode == 1
253
+ (line,) = result.stderr.splitlines()
254
+ assert (
255
+ entry_point_repository.configuration_value(ConfigurationVariable.INSTALL_LOCK)
256
+ in line
257
+ )