simplibs-guide 0.1.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.
- simplibs/guide/__init__.py +72 -0
- simplibs/guide/__main__.py +19 -0
- simplibs/guide/cli/__init__.py +22 -0
- simplibs/guide/cli/_helpers/__init__.py +18 -0
- simplibs/guide/cli/_helpers/_runners/__init__.py +26 -0
- simplibs/guide/cli/_helpers/_runners/_tools/__init__.py +25 -0
- simplibs/guide/cli/_helpers/_runners/_tools/ask_for_confirmation.py +29 -0
- simplibs/guide/cli/_helpers/_runners/_tools/format_archive_report.py +35 -0
- simplibs/guide/cli/_helpers/_runners/_tools/format_batch_build_report.py +40 -0
- simplibs/guide/cli/_helpers/_runners/_tools/format_batch_report.py +42 -0
- simplibs/guide/cli/_helpers/_runners/_tools/format_findings.py +35 -0
- simplibs/guide/cli/_helpers/_runners/_tools/format_scaffold_report.py +46 -0
- simplibs/guide/cli/_helpers/_runners/run_check_command.py +46 -0
- simplibs/guide/cli/_helpers/_runners/run_create_bare_batch_command.py +40 -0
- simplibs/guide/cli/_helpers/_runners/run_create_batch_command.py +40 -0
- simplibs/guide/cli/_helpers/_runners/run_create_files_command.py +44 -0
- simplibs/guide/cli/_helpers/_runners/run_new_command.py +64 -0
- simplibs/guide/cli/_helpers/_runners/run_zip_command.py +44 -0
- simplibs/guide/cli/_helpers/build_parser.py +119 -0
- simplibs/guide/cli/_helpers/silence_closed_stdout.py +32 -0
- simplibs/guide/cli/run_cli.py +54 -0
- simplibs/guide/exceptions/GuideError.py +72 -0
- simplibs/guide/exceptions/__init__.py +20 -0
- simplibs/guide/exceptions/_helpers/__init__.py +16 -0
- simplibs/guide/exceptions/_helpers/build_error_message.py +47 -0
- simplibs/guide/logic/__init__.py +22 -0
- simplibs/guide/logic/archive_library/__init__.py +28 -0
- simplibs/guide/logic/archive_library/_helpers/__init__.py +18 -0
- simplibs/guide/logic/archive_library/_helpers/_constants/EXCLUDED_FILE_PATTERNS.py +13 -0
- simplibs/guide/logic/archive_library/_helpers/_constants/EXCLUDED_FOLDERS.py +19 -0
- simplibs/guide/logic/archive_library/_helpers/_constants/EXCLUDED_FOLDER_PATTERNS.py +13 -0
- simplibs/guide/logic/archive_library/_helpers/_constants/EXCLUDED_ROOT_FILES.py +19 -0
- simplibs/guide/logic/archive_library/_helpers/_constants/EXCLUDED_ROOT_FILE_PATTERNS.py +19 -0
- simplibs/guide/logic/archive_library/_helpers/_constants/EXCLUDED_ROOT_FOLDERS.py +16 -0
- simplibs/guide/logic/archive_library/_helpers/_constants/__init__.py +25 -0
- simplibs/guide/logic/archive_library/_helpers/is_excluded_file.py +35 -0
- simplibs/guide/logic/archive_library/_helpers/is_excluded_folder.py +36 -0
- simplibs/guide/logic/archive_library/_validations/__init__.py +17 -0
- simplibs/guide/logic/archive_library/_validations/validate_archive_folder_exists.py +38 -0
- simplibs/guide/logic/archive_library/_validations/validate_archive_output.py +38 -0
- simplibs/guide/logic/archive_library/archive_folder.py +71 -0
- simplibs/guide/logic/archive_library/collect_archive_files.py +39 -0
- simplibs/guide/logic/archive_library/types/ArchiveReport.py +28 -0
- simplibs/guide/logic/archive_library/types/__init__.py +15 -0
- simplibs/guide/logic/check_library/__init__.py +27 -0
- simplibs/guide/logic/check_library/_helpers/__init__.py +15 -0
- simplibs/guide/logic/check_library/_helpers/_commons/__init__.py +20 -0
- simplibs/guide/logic/check_library/_helpers/_commons/_constants/WORKING_ROOT_FILES.py +19 -0
- simplibs/guide/logic/check_library/_helpers/_commons/_constants/WORKING_ROOT_FILE_PATTERNS.py +19 -0
- simplibs/guide/logic/check_library/_helpers/_commons/_constants/__init__.py +17 -0
- simplibs/guide/logic/check_library/_helpers/_commons/is_working_file.py +40 -0
- simplibs/guide/logic/check_library/_helpers/_commons/make_finding.py +31 -0
- simplibs/guide/logic/check_library/_helpers/_commons/read_pyproject.py +33 -0
- simplibs/guide/logic/check_library/_helpers/checks/__init__.py +37 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/CHECKED_DOCUMENTS.py +14 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/COMMENT_PATTERN.py +15 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/LICENSE_YEAR_PATTERN.py +14 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/PLACEHOLDER_PATTERN.py +22 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/PYTHON_PATTERNS.py +27 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/RELEASE_HEADING_PATTERN.py +15 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/TODO_PATTERN.py +15 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/TOKEN_LEFT_PATTERN.py +15 -0
- simplibs/guide/logic/check_library/_helpers/checks/_constants/__init__.py +29 -0
- simplibs/guide/logic/check_library/_helpers/checks/_tools/__init__.py +25 -0
- simplibs/guide/logic/check_library/_helpers/checks/_tools/_read_prose_lines.py +43 -0
- simplibs/guide/logic/check_library/_helpers/checks/_tools/_slugify_heading.py +41 -0
- simplibs/guide/logic/check_library/_helpers/checks/_tools/get_project_table.py +27 -0
- simplibs/guide/logic/check_library/_helpers/checks/_tools/read_heading_anchors.py +45 -0
- simplibs/guide/logic/check_library/_helpers/checks/_tools/read_markdown_links.py +45 -0
- simplibs/guide/logic/check_library/_helpers/checks/_tools/resolve_link.py +45 -0
- simplibs/guide/logic/check_library/_helpers/checks/_tools/scan_texts.py +54 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_files_exist.py +35 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_files_match_template.py +40 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_license_year_agrees.py +46 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_links_resolve.py +81 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_namespace_has_no_init.py +31 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_no_comments_left.py +34 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_no_placeholders_left.py +34 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_no_todo_left.py +30 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_no_tokens_left.py +30 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_python_agrees.py +69 -0
- simplibs/guide/logic/check_library/_helpers/checks/check_version_agrees.py +50 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/__init__.py +23 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_constants/DEFAULT_IGNORED_CHECKS.py +14 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_constants/IGNORABLE_CHECKS.py +17 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_constants/__init__.py +17 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_tools/__init__.py +15 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_tools/matches_glob.py +43 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_types/IgnoreRule.py +28 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_types/__init__.py +15 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_validations/__init__.py +16 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_validations/_raise_check_ignore_invalid_error.py +39 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/_validations/validate_ignore_rules.py +60 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/apply_ignore_rules.py +39 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/find_unused_ignore_rules.py +43 -0
- simplibs/guide/logic/check_library/_helpers/ignore_rules/read_ignore_rules.py +63 -0
- simplibs/guide/logic/check_library/_helpers/repository/__init__.py +18 -0
- simplibs/guide/logic/check_library/_helpers/repository/_constants/IGNORED_FOLDERS.py +22 -0
- simplibs/guide/logic/check_library/_helpers/repository/_constants/IGNORED_ROOT_FOLDERS.py +14 -0
- simplibs/guide/logic/check_library/_helpers/repository/_constants/__init__.py +17 -0
- simplibs/guide/logic/check_library/_helpers/repository/iter_repository_files.py +53 -0
- simplibs/guide/logic/check_library/_helpers/repository/read_repository_texts.py +37 -0
- simplibs/guide/logic/check_library/_validations/__init__.py +15 -0
- simplibs/guide/logic/check_library/_validations/validate_library_folder_exists.py +39 -0
- simplibs/guide/logic/check_library/check_library.py +78 -0
- simplibs/guide/logic/check_library/constants/MANUAL_CHECKS.py +25 -0
- simplibs/guide/logic/check_library/constants/__init__.py +15 -0
- simplibs/guide/logic/check_library/types/Finding.py +26 -0
- simplibs/guide/logic/check_library/types/__init__.py +15 -0
- simplibs/guide/logic/derive_library_names/__init__.py +20 -0
- simplibs/guide/logic/derive_library_names/_constants/LIBRARY_PREFIX.py +14 -0
- simplibs/guide/logic/derive_library_names/_constants/NAME_PATTERN.py +18 -0
- simplibs/guide/logic/derive_library_names/_constants/__init__.py +17 -0
- simplibs/guide/logic/derive_library_names/_validations/__init__.py +18 -0
- simplibs/guide/logic/derive_library_names/_validations/_raise_invalid_name_error.py +37 -0
- simplibs/guide/logic/derive_library_names/_validations/_raise_keyword_name_error.py +37 -0
- simplibs/guide/logic/derive_library_names/_validations/_raise_missing_prefix_error.py +37 -0
- simplibs/guide/logic/derive_library_names/_validations/validate_library_folder_name.py +44 -0
- simplibs/guide/logic/derive_library_names/derive_name_tokens.py +55 -0
- simplibs/guide/logic/load_manifest/__init__.py +27 -0
- simplibs/guide/logic/load_manifest/_constants/PENDING_STATUS.py +14 -0
- simplibs/guide/logic/load_manifest/_constants/__init__.py +15 -0
- simplibs/guide/logic/load_manifest/_helpers/__init__.py +16 -0
- simplibs/guide/logic/load_manifest/_helpers/_validations/__init__.py +17 -0
- simplibs/guide/logic/load_manifest/_helpers/_validations/raise_manifest_missing_error.py +38 -0
- simplibs/guide/logic/load_manifest/_helpers/_validations/raise_manifest_unreadable_error.py +39 -0
- simplibs/guide/logic/load_manifest/_helpers/read_manifest_file.py +39 -0
- simplibs/guide/logic/load_manifest/_validations/__init__.py +21 -0
- simplibs/guide/logic/load_manifest/_validations/_constants/TEMPLATE_KINDS.py +14 -0
- simplibs/guide/logic/load_manifest/_validations/_constants/__init__.py +15 -0
- simplibs/guide/logic/load_manifest/_validations/_raise_manifest_entry_error.py +41 -0
- simplibs/guide/logic/load_manifest/_validations/_raise_template_missing_error.py +37 -0
- simplibs/guide/logic/load_manifest/_validations/_validate_folder_entry.py +31 -0
- simplibs/guide/logic/load_manifest/_validations/_validate_relative_path.py +42 -0
- simplibs/guide/logic/load_manifest/_validations/_validate_template_entry.py +67 -0
- simplibs/guide/logic/load_manifest/_validations/validate_manifest_data.py +60 -0
- simplibs/guide/logic/load_manifest/find_templates_root.py +25 -0
- simplibs/guide/logic/load_manifest/load_manifest.py +53 -0
- simplibs/guide/logic/load_manifest/types/Manifest.py +27 -0
- simplibs/guide/logic/load_manifest/types/__init__.py +15 -0
- simplibs/guide/logic/pack_and_unpack_batches/__init__.py +42 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/__init__.py +16 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/MARKER_PATTERN.py +17 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/__init__.py +20 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_constants/MARKER_LINE_REASON.py +13 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_constants/NOT_PYTHON_REASON.py +14 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_constants/NOT_TEXT_REASON.py +14 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_constants/__init__.py +19 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_tools/__init__.py +19 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_tools/is_within_depth.py +27 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_tools/make_batch_block.py +39 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_tools/read_batch_source.py +37 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_validations/__init__.py +21 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_validations/raise_batch_nothing_to_pack_error.py +40 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_validations/validate_batch_folder_exists.py +38 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_validations/validate_batch_max_depth.py +37 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/_validations/validate_batch_output.py +38 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/commons/pack_batch.py +131 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_bare_batch/__init__.py +16 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_bare_batch/_tools/__init__.py +21 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_bare_batch/_tools/find_comment_lines.py +38 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_bare_batch/_tools/find_python_docstrings.py +34 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_bare_batch/_tools/find_string_lines.py +31 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_bare_batch/_tools/layout_python_code.py +59 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_bare_batch/strip_python_source.py +75 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_files/__init__.py +16 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_files/_validations/__init__.py +17 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_files/_validations/raise_batch_missing_error.py +37 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_files/_validations/raise_batch_unreadable_error.py +38 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/create_files/read_batch_text.py +44 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/plan_batch/__init__.py +18 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/plan_batch/_validations/__init__.py +17 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/plan_batch/_validations/raise_batch_empty_error.py +30 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/plan_batch/_validations/raise_batch_root_not_allowed_error.py +38 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/plan_batch/parse_batch_path.py +55 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/plan_batch/split_batch.py +46 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/write_batch/__init__.py +15 -0
- simplibs/guide/logic/pack_and_unpack_batches/_helpers/write_batch/encode_content.py +23 -0
- simplibs/guide/logic/pack_and_unpack_batches/_validations/__init__.py +21 -0
- simplibs/guide/logic/pack_and_unpack_batches/_validations/raise_batch_duplicate_path_error.py +35 -0
- simplibs/guide/logic/pack_and_unpack_batches/_validations/raise_batch_path_invalid_error.py +37 -0
- simplibs/guide/logic/pack_and_unpack_batches/_validations/raise_batch_write_failed_error.py +38 -0
- simplibs/guide/logic/pack_and_unpack_batches/_validations/validate_batch_destination.py +44 -0
- simplibs/guide/logic/pack_and_unpack_batches/create_bare_batch.py +53 -0
- simplibs/guide/logic/pack_and_unpack_batches/create_batch.py +43 -0
- simplibs/guide/logic/pack_and_unpack_batches/create_files.py +52 -0
- simplibs/guide/logic/pack_and_unpack_batches/plan_batch.py +46 -0
- simplibs/guide/logic/pack_and_unpack_batches/types/BatchBuildReport.py +30 -0
- simplibs/guide/logic/pack_and_unpack_batches/types/BatchReport.py +27 -0
- simplibs/guide/logic/pack_and_unpack_batches/types/__init__.py +17 -0
- simplibs/guide/logic/pack_and_unpack_batches/write_batch.py +65 -0
- simplibs/guide/logic/scaffold_library/__init__.py +31 -0
- simplibs/guide/logic/scaffold_library/_helpers/__init__.py +21 -0
- simplibs/guide/logic/scaffold_library/_helpers/_constants/ABOUT_SOURCE.py +14 -0
- simplibs/guide/logic/scaffold_library/_helpers/_constants/TOKEN_PATTERN.py +16 -0
- simplibs/guide/logic/scaffold_library/_helpers/_constants/__init__.py +17 -0
- simplibs/guide/logic/scaffold_library/_helpers/_validations/__init__.py +17 -0
- simplibs/guide/logic/scaffold_library/_helpers/_validations/raise_about_missing_error.py +37 -0
- simplibs/guide/logic/scaffold_library/_helpers/_validations/raise_unknown_token_error.py +41 -0
- simplibs/guide/logic/scaffold_library/_helpers/build_file_content.py +45 -0
- simplibs/guide/logic/scaffold_library/_helpers/fill_tokens.py +42 -0
- simplibs/guide/logic/scaffold_library/_helpers/read_about_text.py +37 -0
- simplibs/guide/logic/scaffold_library/_validations/__init__.py +18 -0
- simplibs/guide/logic/scaffold_library/_validations/_raise_target_conflict_error.py +39 -0
- simplibs/guide/logic/scaffold_library/_validations/raise_write_failed_error.py +39 -0
- simplibs/guide/logic/scaffold_library/_validations/validate_no_target_conflicts.py +55 -0
- simplibs/guide/logic/scaffold_library/plan_scaffold.py +58 -0
- simplibs/guide/logic/scaffold_library/scaffold_library.py +49 -0
- simplibs/guide/logic/scaffold_library/types/ScaffoldPlan.py +26 -0
- simplibs/guide/logic/scaffold_library/types/ScaffoldReport.py +26 -0
- simplibs/guide/logic/scaffold_library/types/__init__.py +17 -0
- simplibs/guide/logic/scaffold_library/write_scaffold.py +79 -0
- simplibs/guide/py.typed +0 -0
- simplibs/guide/templates/MANIFEST.toml +109 -0
- simplibs/guide/templates/__init__.py +19 -0
- simplibs/guide/templates/files/.gitattributes.tmpl +7 -0
- simplibs/guide/templates/files/.gitignore.tmpl +57 -0
- simplibs/guide/templates/files/ABOUT_SIMPLIBS.md.tmpl +40 -0
- simplibs/guide/templates/files/CHANGELOG.md.tmpl +56 -0
- simplibs/guide/templates/files/LICENSE.tmpl +21 -0
- simplibs/guide/templates/files/README_MAIN.md.tmpl +243 -0
- simplibs/guide/templates/files/__init__.py.tmpl +28 -0
- simplibs/guide/templates/files/pyproject.toml.tmpl +78 -0
- simplibs/guide/templates/files/test_architecture.py.tmpl +146 -0
- simplibs/guide/templates/files/test_public_api.py.tmpl +91 -0
- simplibs/guide/templates/files/tests.yml.tmpl +38 -0
- simplibs/guide/templates/scripts/create_bare_batch.py.tmpl +228 -0
- simplibs/guide/templates/scripts/create_batch.py.tmpl +120 -0
- simplibs/guide/templates/scripts/create_code_zip.py.tmpl +77 -0
- simplibs/guide/templates/scripts/create_files.py.tmpl +88 -0
- simplibs/guide/templates/scripts/create_files_batch.txt.tmpl +12 -0
- simplibs/guide/templates/scripts/fix_line_endings.py.tmpl +96 -0
- simplibs_guide-0.1.0.dist-info/METADATA +465 -0
- simplibs_guide-0.1.0.dist-info/RECORD +238 -0
- simplibs_guide-0.1.0.dist-info/WHEEL +5 -0
- simplibs_guide-0.1.0.dist-info/entry_points.txt +2 -0
- simplibs_guide-0.1.0.dist-info/licenses/LICENSE +21 -0
- simplibs_guide-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Inners
|
|
2
|
+
from .exceptions import GuideError
|
|
3
|
+
from .logic.archive_library import ArchiveReport, archive_folder
|
|
4
|
+
from .logic.check_library import Finding, check_library
|
|
5
|
+
from .logic.derive_library_names import derive_name_tokens
|
|
6
|
+
from .logic.pack_and_unpack_batches import BatchBuildReport, BatchReport, create_bare_batch, create_batch, create_files, plan_batch, write_batch
|
|
7
|
+
from .logic.scaffold_library import ScaffoldPlan, ScaffoldReport, plan_scaffold, scaffold_library, write_scaffold
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
# scaffold: make the files of a new library
|
|
11
|
+
"plan_scaffold",
|
|
12
|
+
"scaffold_library",
|
|
13
|
+
"write_scaffold",
|
|
14
|
+
"ScaffoldPlan",
|
|
15
|
+
"ScaffoldReport",
|
|
16
|
+
# check: list what is not ready for the upload
|
|
17
|
+
"check_library",
|
|
18
|
+
"Finding",
|
|
19
|
+
# archive: pack a folder into a zip
|
|
20
|
+
"archive_folder",
|
|
21
|
+
"ArchiveReport",
|
|
22
|
+
# batch: make the files of a batch (many files in one text), and pack a folder into one
|
|
23
|
+
"plan_batch",
|
|
24
|
+
"write_batch",
|
|
25
|
+
"create_files",
|
|
26
|
+
"BatchReport",
|
|
27
|
+
"create_batch",
|
|
28
|
+
"create_bare_batch",
|
|
29
|
+
"BatchBuildReport",
|
|
30
|
+
# names: the shapes of the name of a library
|
|
31
|
+
"derive_name_tokens",
|
|
32
|
+
# exceptions: the one error of the library
|
|
33
|
+
"GuideError",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
_DESIGN_NOTES = """
|
|
38
|
+
# simplibs-guide — Package Root
|
|
39
|
+
|
|
40
|
+
## Purpose
|
|
41
|
+
The guides, the templates and the tools for building a library of the simplibs system: make the files of a new library
|
|
42
|
+
from the templates, and check a library folder before the upload. Everything is also a command, `simplibs-guide`.
|
|
43
|
+
|
|
44
|
+
## Internal Components Registry
|
|
45
|
+
|
|
46
|
+
| Component | Type | Description |
|
|
47
|
+
| :------------- | :------ | :---------------------------------------------------------------------------------- |
|
|
48
|
+
| `exceptions` | Folder | `GuideError`, the one error of the library. |
|
|
49
|
+
| `logic` | Folder | What the tools do: the names, the manifest, the scaffold, check, zip and batch. |
|
|
50
|
+
| `cli` | Folder | The command line: `new`, `check`, `zip`, `create-files`, `create-batch`, `create-bare-batch`; the entry point `run_cli` is in here. |
|
|
51
|
+
| `templates` | Folder | The data: `MANIFEST.toml` and the templates that the generator and the check read. |
|
|
52
|
+
| `__main__.py` | File | `python -m simplibs.guide`, the same command as `simplibs-guide`. |
|
|
53
|
+
| `py.typed` | File | The marker that the package has type annotations. |
|
|
54
|
+
|
|
55
|
+
## What the Root Exports
|
|
56
|
+
The functions that make and check a library, and the types that appear in their signatures:
|
|
57
|
+
|
|
58
|
+
from simplibs.guide import check_library, scaffold_library, GuideError
|
|
59
|
+
|
|
60
|
+
## What the Root Deliberately Does NOT Export
|
|
61
|
+
* **`cli/`**: the command line is started by the command, not imported; its entry point is `simplibs.guide.cli:run_cli`.
|
|
62
|
+
* **`load_manifest`, `find_templates_root` and `Manifest`**: the manifest is the file of the tools themselves; a caller
|
|
63
|
+
has no use for it, and a name that is not public can be changed without a new major version.
|
|
64
|
+
* **`MANUAL_CHECKS`**: the list of the points a person checks by hand is printed by the command and is not a function of the library.
|
|
65
|
+
|
|
66
|
+
## `__all__`
|
|
67
|
+
Defined here only. The sub-packages have plain re-imports.
|
|
68
|
+
|
|
69
|
+
## Level 00
|
|
70
|
+
The library stands before `simplibs-exception` and has no dependency, so `GuideError` is its own plain error and not
|
|
71
|
+
a card of the exception library. The rest of the rules of the guide holds.
|
|
72
|
+
"""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Inners
|
|
2
|
+
from .cli import run_cli
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
_DESIGN_NOTES = """
|
|
6
|
+
# __main__ — `python -m simplibs.guide`
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
The same command as `simplibs-guide`, for an environment where the script folder is not on the path. It only passes
|
|
10
|
+
the exit code of `run_cli` on.
|
|
11
|
+
|
|
12
|
+
## The Guard
|
|
13
|
+
Importing the module must not start the command, so the call stands behind `if __name__ == "__main__"`. That is why
|
|
14
|
+
this file is the one whose notes do not stand last.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
raise SystemExit(run_cli())
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Inners
|
|
2
|
+
from .run_cli import run_cli
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
_DESIGN_NOTES = """
|
|
6
|
+
# Cli Sub-Package
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
The command line of the library: `simplibs-guide new`, `simplibs-guide check`, `simplibs-guide zip`, `simplibs-guide create-files`, `simplibs-guide create-batch` and `simplibs-guide create-bare-batch` (and `python -m simplibs.guide <command>`). The entry point of
|
|
10
|
+
`pyproject.toml` is `simplibs.guide.cli:run_cli`; it returns the exit code and the generated wrapper passes it on.
|
|
11
|
+
|
|
12
|
+
## Internal Components Registry
|
|
13
|
+
|
|
14
|
+
| Component | Type | Description |
|
|
15
|
+
| :-------- | :------- | :---------------------------------------------------------------------------------- |
|
|
16
|
+
| `run_cli` | Function | Parses the arguments, runs the command, prints a `GuideError` and returns the exit code. |
|
|
17
|
+
| `_helpers` | Folder | The parser, the commands `new`, `check`, `zip`, `create-files`, `create-batch`, `create-bare-batch` and the printing; not exported. |
|
|
18
|
+
|
|
19
|
+
## Layering & Design
|
|
20
|
+
- The commands hold no logic of their own: they read the arguments, call `logic/` and print. What a library is made of is decided in `logic/scaffold_library`.
|
|
21
|
+
- The text of the commands is plain ASCII, so that it prints the same in every console, also on Windows.
|
|
22
|
+
"""
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from .build_parser import build_parser
|
|
2
|
+
from .silence_closed_stdout import silence_closed_stdout
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
_DESIGN_NOTES = """
|
|
6
|
+
# Helpers Sub-Package
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
What the code next to this folder uses, sorted by who uses it. Nothing here leaves the library.
|
|
10
|
+
|
|
11
|
+
## Internal Components Registry
|
|
12
|
+
|
|
13
|
+
| Component | Type | Description |
|
|
14
|
+
| :---------------------- | :------- | :---------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `build_parser` | Function | Build the parser of the arguments of `simplibs-guide`. |
|
|
16
|
+
| `silence_closed_stdout` | Function | Point the standard output at the null device, after the reader of the pipe it was writing to has closed it. |
|
|
17
|
+
| `_runners` | Folder | The commands, one file each. |
|
|
18
|
+
"""
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from .run_check_command import run_check_command
|
|
2
|
+
from .run_create_bare_batch_command import run_create_bare_batch_command
|
|
3
|
+
from .run_create_batch_command import run_create_batch_command
|
|
4
|
+
from .run_create_files_command import run_create_files_command
|
|
5
|
+
from .run_new_command import run_new_command
|
|
6
|
+
from .run_zip_command import run_zip_command
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
_DESIGN_NOTES = """
|
|
10
|
+
# Runners Sub-Package
|
|
11
|
+
|
|
12
|
+
## Purpose
|
|
13
|
+
The commands, one file each; `run_cli` calls them. Nothing here leaves the library.
|
|
14
|
+
|
|
15
|
+
## Internal Components Registry
|
|
16
|
+
|
|
17
|
+
| Component | Type | Description |
|
|
18
|
+
| :------------------------------ | :------- | :--------------------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| `run_check_command` | Function | Run the command `check`: check a library folder and print what is not ready, then what only a person can answer. |
|
|
20
|
+
| `run_create_bare_batch_command` | Function | Run the command `create-bare-batch`: pack the Python code of a folder into one batch and print what was packed. |
|
|
21
|
+
| `run_create_batch_command` | Function | Run the command `create-batch`: pack a folder into one batch and print what was packed. |
|
|
22
|
+
| `run_create_files_command` | Function | Run the command `create-files`: make the files of a batch and print what was made. |
|
|
23
|
+
| `run_new_command` | Function | Run the command `new`: show the names, ask, make the files and print what was done. |
|
|
24
|
+
| `run_zip_command` | Function | Run the command `zip`: pack a folder into a zip and print what was packed. |
|
|
25
|
+
| `_tools` | Folder | The small steps used here; not exported. |
|
|
26
|
+
"""
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from .ask_for_confirmation import ask_for_confirmation
|
|
2
|
+
from .format_archive_report import format_archive_report
|
|
3
|
+
from .format_batch_build_report import format_batch_build_report
|
|
4
|
+
from .format_batch_report import format_batch_report
|
|
5
|
+
from .format_findings import format_findings
|
|
6
|
+
from .format_scaffold_report import format_scaffold_report
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
_DESIGN_NOTES = """
|
|
10
|
+
# Tools Sub-Package
|
|
11
|
+
|
|
12
|
+
## Purpose
|
|
13
|
+
The small steps that the code next to this folder calls. Nothing here leaves the library.
|
|
14
|
+
|
|
15
|
+
## Internal Components Registry
|
|
16
|
+
|
|
17
|
+
| Component | Type | Description |
|
|
18
|
+
| :-------------------------- | :------- | :------------------------------------------------------------ |
|
|
19
|
+
| `ask_for_confirmation` | Function | Ask one yes or no question on the terminal. |
|
|
20
|
+
| `format_archive_report` | Function | Turn the report of a packing into lines of text. |
|
|
21
|
+
| `format_batch_build_report` | Function | Turn the report of a packing into a batch into lines of text. |
|
|
22
|
+
| `format_batch_report` | Function | Turn the report of a batch into lines of text. |
|
|
23
|
+
| `format_findings` | Function | Turn the findings of a check into lines of text. |
|
|
24
|
+
| `format_scaffold_report` | Function | Turn the report of the writing into lines of text. |
|
|
25
|
+
"""
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
def ask_for_confirmation(
|
|
2
|
+
question: str,
|
|
3
|
+
) -> bool:
|
|
4
|
+
"""Ask one yes or no question on the terminal.
|
|
5
|
+
|
|
6
|
+
Args:
|
|
7
|
+
question: The question, without the choices.
|
|
8
|
+
|
|
9
|
+
Returns:
|
|
10
|
+
`True` for `y` or `yes` (any case); everything else, and no terminal at all, is `False`.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
# 1. A closed input (a pipe, a script) cannot answer, which counts as no
|
|
14
|
+
try:
|
|
15
|
+
answer = input(f"{question} [y/N] ")
|
|
16
|
+
except EOFError:
|
|
17
|
+
return False
|
|
18
|
+
|
|
19
|
+
# 2. Only a clear yes is a yes
|
|
20
|
+
return answer.strip().lower() in {"y", "yes"}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
_DESIGN_NOTES = """
|
|
24
|
+
# ask_for_confirmation — the Default Is No
|
|
25
|
+
|
|
26
|
+
## Purpose
|
|
27
|
+
The command writes files, so the safe answer is the default: an empty line, a typo or a script without a terminal
|
|
28
|
+
does not start the writing. `--yes` is the way for a script.
|
|
29
|
+
"""
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Outers
|
|
2
|
+
from .....logic.archive_library import ArchiveReport
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def format_archive_report(
|
|
6
|
+
report: ArchiveReport,
|
|
7
|
+
*,
|
|
8
|
+
dry_run: bool,
|
|
9
|
+
) -> list[str]:
|
|
10
|
+
"""Turn the report of a packing into lines of text.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
report: What `archive_folder` did.
|
|
14
|
+
dry_run: Whether it was only a preview.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
With `dry_run` the packed paths and a closing line with their count; otherwise one line with the count, the size and the zip.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
# 1. The count in words ("1 file", "2 files"); a preview lists the paths and says where the zip would be written
|
|
21
|
+
count = len(report["files"])
|
|
22
|
+
files = "1 file" if count == 1 else f"{count} files"
|
|
23
|
+
if dry_run:
|
|
24
|
+
return [*report["files"], "", f"Dry run: {files} would be packed into {report['output']}"]
|
|
25
|
+
|
|
26
|
+
# 2. The real run is one line
|
|
27
|
+
return [f"Packed {files} ({report['size_kb']} KB) into {report['output']}"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
_DESIGN_NOTES = """
|
|
31
|
+
# format_archive_report - the Words of a Packing
|
|
32
|
+
|
|
33
|
+
## Purpose
|
|
34
|
+
The lines are the same as the ones of the script `_create_code_zip.py`, so a person who knows one command knows the other.
|
|
35
|
+
"""
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Outers
|
|
2
|
+
from .....logic.pack_and_unpack_batches import BatchBuildReport
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def format_batch_build_report(
|
|
6
|
+
report: BatchBuildReport,
|
|
7
|
+
*,
|
|
8
|
+
dry_run: bool,
|
|
9
|
+
) -> list[str]:
|
|
10
|
+
"""Turn the report of a packing into a batch into lines of text.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
report: What `create_batch` did.
|
|
14
|
+
dry_run: Whether it was only a preview.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
One line per file that was left out; with `dry_run` also the packed paths first; and a closing line with the count (and the size, when written).
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
# 1. The files that were left out, one line each with the reason, and the count for the closing line
|
|
21
|
+
left_out = [f"Left out: {path} ({reason})" for path, reason in report["skipped"].items()]
|
|
22
|
+
count = len(report["files"])
|
|
23
|
+
files = "1 file" if count == 1 else f"{count} files"
|
|
24
|
+
tail = f", {len(left_out)} left out" if left_out else ""
|
|
25
|
+
|
|
26
|
+
# 2. A preview lists the paths and says where the batch would be written
|
|
27
|
+
if dry_run:
|
|
28
|
+
return [*report["files"], *left_out, "", f"Dry run: {files} would be packed into {report['output']}{tail}"]
|
|
29
|
+
|
|
30
|
+
# 3. The real run: what was left out, then one line with the count and the size
|
|
31
|
+
return [*left_out, f"Packed {files} ({report['size_kb']} KB) into {report['output']}{tail}"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
_DESIGN_NOTES = """
|
|
35
|
+
# format_batch_build_report - the Report as Lines
|
|
36
|
+
|
|
37
|
+
## Purpose
|
|
38
|
+
The printing of `create_batch`. The files that were left out are named before the closing line, so the last line is always the summary, and a batch that is not the whole
|
|
39
|
+
folder says so in it.
|
|
40
|
+
"""
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Outers
|
|
2
|
+
from .....logic.pack_and_unpack_batches import BatchReport
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def format_batch_report(
|
|
6
|
+
report: BatchReport,
|
|
7
|
+
*,
|
|
8
|
+
dry_run: bool,
|
|
9
|
+
) -> list[str]:
|
|
10
|
+
"""Turn the report of a batch into lines of text.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
report: What `create_files` did.
|
|
14
|
+
dry_run: Whether it was only a preview.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
One line per file, in the order of the batch, an empty line and a closing line with the count.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
# 1. The words of the lines: what was done, or what would be
|
|
21
|
+
created, overwritten = ("Would create", "Would overwrite") if dry_run else ("Created", "Overwritten")
|
|
22
|
+
|
|
23
|
+
# 2. One line per file, in the order of the batch
|
|
24
|
+
existing = set(report["overwritten"])
|
|
25
|
+
lines = [f"{overwritten if path in existing else created}: {path}" for path in report["files"]]
|
|
26
|
+
|
|
27
|
+
# 3. The closing line
|
|
28
|
+
count = len(report["files"])
|
|
29
|
+
files = "1 file" if count == 1 else f"{count} files"
|
|
30
|
+
lines.append("")
|
|
31
|
+
lines.append(f"Dry run, nothing written: {files} planned." if dry_run else f"Finished: {files} processed.")
|
|
32
|
+
|
|
33
|
+
return lines
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
_DESIGN_NOTES = """
|
|
37
|
+
# format_batch_report - the Words of a Batch
|
|
38
|
+
|
|
39
|
+
## Purpose
|
|
40
|
+
The lines are the same as the ones of the script `_create_files.py` (`Created: path`, `Would overwrite: path`, the
|
|
41
|
+
closing line), so a person who knows one knows the other.
|
|
42
|
+
"""
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Outers
|
|
2
|
+
from .....logic.check_library import Finding
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def format_findings(
|
|
6
|
+
findings: list[Finding],
|
|
7
|
+
) -> list[str]:
|
|
8
|
+
"""Turn the findings of a check into lines of text.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
findings: What the check found.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
One line with the count, then two lines per finding: its id and its message.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
# 1. Nothing found has one short sentence
|
|
18
|
+
if not findings:
|
|
19
|
+
return ["No problems found."]
|
|
20
|
+
|
|
21
|
+
# 2. The count, then the id and the message of every finding
|
|
22
|
+
lines = [f"Found {len(findings)} problem{'s' if len(findings) != 1 else ''}:"]
|
|
23
|
+
for finding in findings:
|
|
24
|
+
lines.append(f" {finding['id']}")
|
|
25
|
+
lines.append(f" {finding['message']}")
|
|
26
|
+
|
|
27
|
+
return lines
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
_DESIGN_NOTES = """
|
|
31
|
+
# format_findings — the Words of a Check
|
|
32
|
+
|
|
33
|
+
## Purpose
|
|
34
|
+
The id comes first on its own line, so it can be copied into a search or a test; the sentence is under it.
|
|
35
|
+
"""
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Outers
|
|
2
|
+
from .....logic.scaffold_library import ScaffoldReport
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def format_scaffold_report(
|
|
6
|
+
report: ScaffoldReport,
|
|
7
|
+
*,
|
|
8
|
+
dry_run: bool,
|
|
9
|
+
) -> list[str]:
|
|
10
|
+
"""Turn the report of the writing into lines of text.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
report: What the writing did, or would do.
|
|
14
|
+
dry_run: `True` when nothing was written; the lines then say what would happen.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
One line per path, and a last line with the counts.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
# 1. The words of the lines: what was done, or what would be
|
|
21
|
+
if dry_run:
|
|
22
|
+
labels = ("would make folder", "would create", "would overwrite", "would skip (exists)")
|
|
23
|
+
else:
|
|
24
|
+
labels = ("folder made", "created", "overwritten", "skipped (exists)")
|
|
25
|
+
|
|
26
|
+
# 2. One line per path, in the order: folders, created, overwritten, skipped
|
|
27
|
+
lines = []
|
|
28
|
+
for label, key in zip(labels, ("folders", "created", "overwritten", "skipped")):
|
|
29
|
+
lines.extend(f" {label:<20}{path}" for path in report[key])
|
|
30
|
+
|
|
31
|
+
# 3. The counts ("1 file created", "2 files created")
|
|
32
|
+
made = len(report["created"])
|
|
33
|
+
files = "1 file" if made == 1 else f"{made} files"
|
|
34
|
+
counts = f"{files} created, {len(report['overwritten'])} overwritten, {len(report['skipped'])} skipped"
|
|
35
|
+
lines.append(("Dry run, nothing was written: " if dry_run else "Done: ") + counts + ".")
|
|
36
|
+
|
|
37
|
+
return lines
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
_DESIGN_NOTES = """
|
|
41
|
+
# format_scaffold_report — the Words of the Report
|
|
42
|
+
|
|
43
|
+
## Purpose
|
|
44
|
+
The report has the same four lists with and without `--dry-run`; only the verbs change ("created" and "would
|
|
45
|
+
create"), so the preview reads like the real run.
|
|
46
|
+
"""
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
# Outers
|
|
4
|
+
from ....logic.check_library import MANUAL_CHECKS, check_library
|
|
5
|
+
# Inners
|
|
6
|
+
from ._tools import format_findings
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def run_check_command(
|
|
10
|
+
arguments: argparse.Namespace,
|
|
11
|
+
) -> int:
|
|
12
|
+
"""Run the command `check`: check a library folder and print what is not ready, then what only a person can answer.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
arguments: The parsed arguments: `folder`.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
0 when nothing was found, 1 when there are findings.
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
GuideError: If the folder does not exist, its name is not valid, or the templates are broken.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# 1. Check the folder; nothing is changed on the disk
|
|
25
|
+
root = Path(arguments.folder).resolve()
|
|
26
|
+
print(f"Checking: {root}")
|
|
27
|
+
findings = check_library(root)
|
|
28
|
+
|
|
29
|
+
# 2. The findings, then the points that no tool can answer; they are printed even when nothing was found
|
|
30
|
+
print(*format_findings(findings), sep="\n")
|
|
31
|
+
print("\nTo check by hand:")
|
|
32
|
+
print(*(f" [ ] {point}" for point in MANUAL_CHECKS), sep="\n")
|
|
33
|
+
|
|
34
|
+
return 1 if findings else 0
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
_DESIGN_NOTES = """
|
|
38
|
+
# run_check_command — Findings First, Then the Hand Work
|
|
39
|
+
|
|
40
|
+
## Purpose
|
|
41
|
+
Everything the user sees of `check`. The exit code follows the findings, so that a script can stop on them; the
|
|
42
|
+
list to check by hand is printed every time, because a clean result of the tool is not the whole checklist.
|
|
43
|
+
|
|
44
|
+
## No Logic of Its Own
|
|
45
|
+
`check_library` decides what is wrong. This function only prints it.
|
|
46
|
+
"""
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
# Outers
|
|
4
|
+
from ....logic.pack_and_unpack_batches import create_bare_batch
|
|
5
|
+
# Inners
|
|
6
|
+
from ._tools import format_batch_build_report
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def run_create_bare_batch_command(
|
|
10
|
+
arguments: argparse.Namespace,
|
|
11
|
+
) -> int:
|
|
12
|
+
"""Run the command `create-bare-batch`: pack the Python code of a folder into one batch and print what was packed.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
arguments: The parsed arguments: `folder`, `output`, `dry_run`, `max_depth`.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
0 when the batch was written (or the files were listed with `--dry-run`).
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
GuideError: If the folder does not exist, the depth is negative, the batch to write is the path of a folder, no file is left to pack, or the disk refuses the write.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# 1. The paths of the arguments; no `--output` means the default place of the batch
|
|
25
|
+
folder = Path(arguments.folder).resolve()
|
|
26
|
+
output = Path(arguments.output).resolve() if arguments.output else None
|
|
27
|
+
|
|
28
|
+
# 2. Pack, or only list, and print the report
|
|
29
|
+
report = create_bare_batch(folder, output=output, dry_run=arguments.dry_run, max_depth=arguments.max_depth)
|
|
30
|
+
print(*format_batch_build_report(report, dry_run=arguments.dry_run), sep="\n")
|
|
31
|
+
|
|
32
|
+
return 0
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_DESIGN_NOTES = """
|
|
36
|
+
# run_create_bare_batch_command - the Command create-bare-batch
|
|
37
|
+
|
|
38
|
+
## Purpose
|
|
39
|
+
Reads the arguments, calls `create_bare_batch` and prints, with the same report lines as `create-batch`. The command holds no logic of its own.
|
|
40
|
+
"""
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
# Outers
|
|
4
|
+
from ....logic.pack_and_unpack_batches import create_batch
|
|
5
|
+
# Inners
|
|
6
|
+
from ._tools import format_batch_build_report
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def run_create_batch_command(
|
|
10
|
+
arguments: argparse.Namespace,
|
|
11
|
+
) -> int:
|
|
12
|
+
"""Run the command `create-batch`: pack a folder into one batch and print what was packed.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
arguments: The parsed arguments: `folder`, `output`, `dry_run`, `max_depth`.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
0 when the batch was written (or the files were listed with `--dry-run`).
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
GuideError: If the folder does not exist, the depth is negative, the batch to write is the path of a folder, no file is left to pack, or the disk refuses the write.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# 1. The paths of the arguments; no `--output` means the default place of the batch
|
|
25
|
+
folder = Path(arguments.folder).resolve()
|
|
26
|
+
output = Path(arguments.output).resolve() if arguments.output else None
|
|
27
|
+
|
|
28
|
+
# 2. Pack, or only list, and print the report
|
|
29
|
+
report = create_batch(folder, output=output, dry_run=arguments.dry_run, max_depth=arguments.max_depth)
|
|
30
|
+
print(*format_batch_build_report(report, dry_run=arguments.dry_run), sep="\n")
|
|
31
|
+
|
|
32
|
+
return 0
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_DESIGN_NOTES = """
|
|
36
|
+
# run_create_batch_command - the Command create-batch
|
|
37
|
+
|
|
38
|
+
## Purpose
|
|
39
|
+
Reads the arguments, calls `create_batch` and prints. The command holds no logic of its own, as the other commands.
|
|
40
|
+
"""
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
# Outers
|
|
4
|
+
from ....logic.pack_and_unpack_batches import create_files
|
|
5
|
+
# Inners
|
|
6
|
+
from ._tools import format_batch_report
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def run_create_files_command(
|
|
10
|
+
arguments: argparse.Namespace,
|
|
11
|
+
) -> int:
|
|
12
|
+
"""Run the command `create-files`: make the files of a batch and print what was made.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
arguments: The parsed arguments: `batch`, `folder`, `only`, `dry_run`.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
0 when the files were made (or listed with `--dry-run`).
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
GuideError: If the batch file does not exist or cannot be read, the batch has no marker line, a path is wrong or listed twice, or the disk refuses a write.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# 1. The paths of the arguments, both from where the command is run: `-C` moves the files, not the batch
|
|
25
|
+
folder = Path(arguments.folder).resolve()
|
|
26
|
+
batch = Path(arguments.batch).resolve()
|
|
27
|
+
|
|
28
|
+
# 2. Make the files, or only list them, and print the report
|
|
29
|
+
report = create_files(folder, batch, dry_run=arguments.dry_run, allowed_roots=tuple(arguments.only or ()))
|
|
30
|
+
print(*format_batch_report(report, dry_run=arguments.dry_run), sep="\n")
|
|
31
|
+
|
|
32
|
+
return 0
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_DESIGN_NOTES = """
|
|
36
|
+
# run_create_files_command - Make and Report
|
|
37
|
+
|
|
38
|
+
## Purpose
|
|
39
|
+
Everything the user sees of `create-files`. It asks no question: a batch is written by the author for this very
|
|
40
|
+
folder, and `--dry-run` shows what it would do, which files it would overwrite among them.
|
|
41
|
+
|
|
42
|
+
## No Logic of Its Own
|
|
43
|
+
`create_files` decides what is written. This function only reads the arguments and prints.
|
|
44
|
+
"""
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
# Outers
|
|
4
|
+
from ....logic.derive_library_names import derive_name_tokens
|
|
5
|
+
from ....logic.scaffold_library import scaffold_library
|
|
6
|
+
# Inners
|
|
7
|
+
from ._tools import ask_for_confirmation, format_scaffold_report
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def run_new_command(
|
|
11
|
+
arguments: argparse.Namespace,
|
|
12
|
+
) -> int:
|
|
13
|
+
"""Run the command `new`: show the names, ask, make the files and print what was done.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
arguments: The parsed arguments: `folder`, `yes`, `dry_run`, `force`.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
0 when the files were made (or listed with `--dry-run`), 1 when the question was answered with no.
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
GuideError: If the name of the folder is not valid, the templates are broken, a path clashes with something on the disk, or the disk refuses a write.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
# 1. The names come from the folder; a bad name stops here, before anything is shown or asked
|
|
26
|
+
root = Path(arguments.folder).resolve()
|
|
27
|
+
tokens = derive_name_tokens(root.name)
|
|
28
|
+
|
|
29
|
+
# 2. Show what the generator understood
|
|
30
|
+
print(f"Library folder: {root}")
|
|
31
|
+
print(f" NAME {tokens['NAME']}")
|
|
32
|
+
print(f" IMPORT {tokens['IMPORT']}")
|
|
33
|
+
print(f" UPPER {tokens['UPPER']}")
|
|
34
|
+
|
|
35
|
+
# 3. Ask, unless the answer is not needed: `--yes` says it, `--dry-run` writes nothing
|
|
36
|
+
if not (arguments.yes or arguments.dry_run):
|
|
37
|
+
if not ask_for_confirmation("Make the files of the library here?"):
|
|
38
|
+
print("Nothing was written. Use --yes to skip the question.")
|
|
39
|
+
return 1
|
|
40
|
+
|
|
41
|
+
# 4. Make the files, or only list them, and print the report
|
|
42
|
+
report = scaffold_library(root, force=arguments.force, dry_run=arguments.dry_run)
|
|
43
|
+
print(*format_scaffold_report(report, dry_run=arguments.dry_run), sep="\n")
|
|
44
|
+
|
|
45
|
+
# 5. What to do next, or how to overwrite what was skipped
|
|
46
|
+
if report["skipped"] and not arguments.force:
|
|
47
|
+
print("Files that exist were left as they are; --force overwrites them.")
|
|
48
|
+
if not arguments.dry_run and (report["created"] or report["overwritten"]):
|
|
49
|
+
print("Next: search the files for TODO(simplibs) and fill them in.")
|
|
50
|
+
|
|
51
|
+
return 0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
_DESIGN_NOTES = """
|
|
55
|
+
# run_new_command — Show, Ask, Write, Report
|
|
56
|
+
|
|
57
|
+
## Purpose
|
|
58
|
+
Everything the user sees of `new`, in the order they see it. The names come first, so a wrong folder name is
|
|
59
|
+
noticed before any question; the question comes next, so nothing is written on a mistake.
|
|
60
|
+
|
|
61
|
+
## No Logic of Its Own
|
|
62
|
+
It calls `derive_name_tokens` to show the names and `scaffold_library` to do the work. Which files exist and what is
|
|
63
|
+
in them is decided in `logic/scaffold_library`.
|
|
64
|
+
"""
|