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,44 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
# Outers
|
|
4
|
+
from ....logic.archive_library import archive_folder
|
|
5
|
+
# Inners
|
|
6
|
+
from ._tools import format_archive_report
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def run_zip_command(
|
|
10
|
+
arguments: argparse.Namespace,
|
|
11
|
+
) -> int:
|
|
12
|
+
"""Run the command `zip`: pack a folder into a zip and print what was packed.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
arguments: The parsed arguments: `folder`, `output`, `dry_run`.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
0 when the zip was written (or the files were listed with `--dry-run`).
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
GuideError: If the folder does not exist, or the zip to write is the path of a folder.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# 1. The paths of the arguments; no `--output` means the default place of the zip
|
|
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 = archive_folder(folder, output=output, dry_run=arguments.dry_run)
|
|
30
|
+
print(*format_archive_report(report, dry_run=arguments.dry_run), sep="\n")
|
|
31
|
+
|
|
32
|
+
return 0
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_DESIGN_NOTES = """
|
|
36
|
+
# run_zip_command - Pack and Report
|
|
37
|
+
|
|
38
|
+
## Purpose
|
|
39
|
+
Everything the user sees of `zip`. It asks no question: the zip is one new file, and a zip of the same name is
|
|
40
|
+
written again, as the script of a library does.
|
|
41
|
+
|
|
42
|
+
## No Logic of Its Own
|
|
43
|
+
`archive_folder` decides what is packed. This function only reads the arguments and prints.
|
|
44
|
+
"""
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
# Inners
|
|
3
|
+
from ._runners import run_check_command, run_create_bare_batch_command, run_create_batch_command, run_create_files_command, run_new_command, run_zip_command
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
7
|
+
"""Build the parser of the arguments of `simplibs-guide`.
|
|
8
|
+
|
|
9
|
+
Returns:
|
|
10
|
+
The parser; every command sets `handler`, the function that runs it and returns the exit code.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
# 1. The program and its commands; a command is required
|
|
14
|
+
parser = argparse.ArgumentParser(
|
|
15
|
+
prog="simplibs-guide",
|
|
16
|
+
description="Tools for building a library of the simplibs system.",
|
|
17
|
+
)
|
|
18
|
+
commands = parser.add_subparsers(dest="command", required=True, metavar="command")
|
|
19
|
+
|
|
20
|
+
# 2. `new`: the files of a new library, named by its folder
|
|
21
|
+
new = commands.add_parser(
|
|
22
|
+
"new",
|
|
23
|
+
help="make the files of a new library in a folder",
|
|
24
|
+
description=(
|
|
25
|
+
"Make the files of a new library in a folder. The name of the library is the name of the folder "
|
|
26
|
+
"(simplibs-<name>); existing files are skipped unless --force is given."
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
new.add_argument("folder", nargs="?", default=".", help="the folder of the library (default: the current folder)")
|
|
30
|
+
new.add_argument("-y", "--yes", action="store_true", help="do not ask for confirmation")
|
|
31
|
+
new.add_argument("--dry-run", action="store_true", help="only list what would be made; write nothing")
|
|
32
|
+
new.add_argument("--force", action="store_true", help="overwrite the files that exist")
|
|
33
|
+
new.set_defaults(handler=run_new_command)
|
|
34
|
+
|
|
35
|
+
# 3. `check`: what is not ready for the upload; it changes nothing
|
|
36
|
+
check = commands.add_parser(
|
|
37
|
+
"check",
|
|
38
|
+
help="list what is not ready for the upload in a library folder",
|
|
39
|
+
description="Check a library folder against the templates and the facts of the checklist. Nothing is changed.",
|
|
40
|
+
)
|
|
41
|
+
check.add_argument("folder", nargs="?", default=".", help="the folder of the library (default: the current folder)")
|
|
42
|
+
check.set_defaults(handler=run_check_command)
|
|
43
|
+
|
|
44
|
+
# 4. `zip`: a folder packed into a zip, without what git leaves out
|
|
45
|
+
zip_command = commands.add_parser(
|
|
46
|
+
"zip",
|
|
47
|
+
help="pack a folder into a zip, without what git leaves out",
|
|
48
|
+
description=(
|
|
49
|
+
"Pack a folder into a zip, without what git leaves out. The paths in the zip start in the folder itself. "
|
|
50
|
+
"The zip is named after the folder and put in the current folder, unless --output says another one."
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
zip_command.add_argument("folder", nargs="?", default=".", help="the folder to pack (default: the current folder)")
|
|
54
|
+
zip_command.add_argument("-o", "--output", help="the zip to write (default: <folder name>.zip in the current folder)")
|
|
55
|
+
zip_command.add_argument("--dry-run", action="store_true", help="only list the files; write nothing")
|
|
56
|
+
zip_command.set_defaults(handler=run_zip_command)
|
|
57
|
+
|
|
58
|
+
# 5. `create-files`: the files of a batch, made in a folder
|
|
59
|
+
create_files_command = commands.add_parser(
|
|
60
|
+
"create-files",
|
|
61
|
+
help="make the files of a batch: one text, the files split by lines `# >>> path`",
|
|
62
|
+
description=(
|
|
63
|
+
"Make the files of a batch: one text in which every file starts with a line `# >>> relative/path`. "
|
|
64
|
+
"The files are made in the current folder, and a relative path of the batch is taken from there too. "
|
|
65
|
+
"Files that exist are written again; --dry-run shows which."
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
create_files_command.add_argument("batch", help="the batch file")
|
|
69
|
+
create_files_command.add_argument("-C", "--folder", default=".", help="the folder the files are made in (default: the current folder); the batch is still taken from the current folder")
|
|
70
|
+
create_files_command.add_argument("--only", action="append", metavar="FOLDER", help="allow only paths that start with this folder; repeat for more")
|
|
71
|
+
create_files_command.add_argument("--dry-run", action="store_true", help="only list what would be created or overwritten; write nothing")
|
|
72
|
+
create_files_command.set_defaults(handler=run_create_files_command)
|
|
73
|
+
|
|
74
|
+
# 6. `create-batch`: the text files of a folder, packed into one batch (the reverse of `create-files`)
|
|
75
|
+
create_batch_command = commands.add_parser(
|
|
76
|
+
"create-batch",
|
|
77
|
+
help="pack the text files of a folder into one batch: the reverse of `create-files`",
|
|
78
|
+
description=(
|
|
79
|
+
"Pack the text files of a folder into one batch: every file under a line `# >>> relative/path`, without what git leaves out. "
|
|
80
|
+
"Files that are not UTF-8 text, or that have a line starting with the marker, are left out and listed. "
|
|
81
|
+
"The batch is named <folder name>_batch.txt and put in the current folder, unless --output says another one."
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
create_batch_command.add_argument("folder", nargs="?", default=".", help="the folder to pack (default: the current folder)")
|
|
85
|
+
create_batch_command.add_argument("-o", "--output", help="the batch to write (default: <folder name>_batch.txt in the current folder)")
|
|
86
|
+
create_batch_command.add_argument("--max-depth", type=int, metavar="N", help="pack only files at most N folders deep (0: the files of the folder itself; default: any depth)")
|
|
87
|
+
create_batch_command.add_argument("--dry-run", action="store_true", help="only list the files; write nothing")
|
|
88
|
+
create_batch_command.set_defaults(handler=run_create_batch_command)
|
|
89
|
+
|
|
90
|
+
# 7. `create-bare-batch`: the Python code of a folder without its words, in one batch (lossy, to read)
|
|
91
|
+
create_bare_batch_command = commands.add_parser(
|
|
92
|
+
"create-bare-batch",
|
|
93
|
+
help="pack the Python code of a folder into one batch, without comments, docstrings and design notes",
|
|
94
|
+
description=(
|
|
95
|
+
"Pack the .py files of a folder into one batch, each under a line `# >>> relative/path`, without comment lines, docstrings and the block _DESIGN_NOTES. "
|
|
96
|
+
"The text is for reading (for example by an AI), not for making files from. Files that cannot be parsed are left out and listed. "
|
|
97
|
+
"The batch is named <folder name>_bare_batch.txt and put in the current folder, unless --output says another one."
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
create_bare_batch_command.add_argument("folder", nargs="?", default=".", help="the folder to pack (default: the current folder)")
|
|
101
|
+
create_bare_batch_command.add_argument("-o", "--output", help="the batch to write (default: <folder name>_bare_batch.txt in the current folder)")
|
|
102
|
+
create_bare_batch_command.add_argument("--max-depth", type=int, metavar="N", help="pack only files at most N folders deep (0: the files of the folder itself; default: any depth)")
|
|
103
|
+
create_bare_batch_command.add_argument("--dry-run", action="store_true", help="only list the files; write nothing")
|
|
104
|
+
create_bare_batch_command.set_defaults(handler=run_create_bare_batch_command)
|
|
105
|
+
|
|
106
|
+
return parser
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
_DESIGN_NOTES = """
|
|
110
|
+
# build_parser — One Place for the Look of the Command Line
|
|
111
|
+
|
|
112
|
+
## Purpose
|
|
113
|
+
The names of the commands and of their options are written once here, with their help. A new command adds one
|
|
114
|
+
`add_parser` block and one `handler`.
|
|
115
|
+
|
|
116
|
+
## `handler`
|
|
117
|
+
Each command sets `handler` with `set_defaults`, so that `run_cli` needs no list of commands: it calls what the
|
|
118
|
+
parser chose.
|
|
119
|
+
"""
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def silence_closed_stdout() -> None:
|
|
7
|
+
"""Point the standard output at the null device, after the reader of the pipe it was writing to has closed it.
|
|
8
|
+
|
|
9
|
+
Returns:
|
|
10
|
+
Nothing. A standard output that has no file number (a test, a replaced stream) or cannot be redirected is left as it is.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
# 1. Without this Python writes `Exception ignored ... BrokenPipeError` once more, when it flushes the closed pipe at exit
|
|
14
|
+
with contextlib.suppress(OSError, ValueError):
|
|
15
|
+
null = os.open(os.devnull, os.O_WRONLY)
|
|
16
|
+
try:
|
|
17
|
+
os.dup2(null, sys.stdout.fileno())
|
|
18
|
+
finally:
|
|
19
|
+
os.close(null)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
_DESIGN_NOTES = """
|
|
23
|
+
# silence_closed_stdout — a Reader That Stopped Reading
|
|
24
|
+
|
|
25
|
+
## Purpose
|
|
26
|
+
`simplibs-guide check | head` ends when `head` has its lines: it closes the pipe, and the next write raises `BrokenPipeError`. The command has done
|
|
27
|
+
nothing wrong, and a traceback would be noise. The output is pointed at the null device so that the flush at exit has nothing to fail on.
|
|
28
|
+
|
|
29
|
+
## Why Suppress
|
|
30
|
+
A stream that has no file number (the capture of a test, a replaced `sys.stdout`) has nothing to redirect, and a number that cannot be used is
|
|
31
|
+
not worth a second error on top of the first one. In both cases the output stays as it was.
|
|
32
|
+
"""
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from collections.abc import Sequence
|
|
3
|
+
# Outers
|
|
4
|
+
from ..exceptions import GuideError
|
|
5
|
+
# Inners
|
|
6
|
+
from ._helpers import build_parser, silence_closed_stdout
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def run_cli(
|
|
10
|
+
argv: Sequence[str] | None = None,
|
|
11
|
+
) -> int:
|
|
12
|
+
"""Run the command line of the library and return the exit code.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
argv: The arguments after the name of the program; `None` for those of the command line.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
0 when the command did its work, 1 when it failed, was cancelled or found its output closed, 2 for a wrong usage, 130 after Ctrl+C.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# 1. The arguments; `--help` and a wrong usage end in SystemExit, which becomes the exit code here
|
|
22
|
+
parser = build_parser()
|
|
23
|
+
try:
|
|
24
|
+
arguments = parser.parse_args(argv)
|
|
25
|
+
except SystemExit as exit_signal:
|
|
26
|
+
return exit_signal.code if isinstance(exit_signal.code, int) else 1
|
|
27
|
+
|
|
28
|
+
# 2. The command; the one error of the library is printed as it is, with its advice
|
|
29
|
+
try:
|
|
30
|
+
return arguments.handler(arguments)
|
|
31
|
+
except GuideError as error:
|
|
32
|
+
print(error, file=sys.stderr)
|
|
33
|
+
return 1
|
|
34
|
+
except BrokenPipeError:
|
|
35
|
+
silence_closed_stdout()
|
|
36
|
+
return 1
|
|
37
|
+
except KeyboardInterrupt:
|
|
38
|
+
print("Cancelled.", file=sys.stderr)
|
|
39
|
+
return 130
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
_DESIGN_NOTES = """
|
|
43
|
+
# run_cli — the Border of the Command Line
|
|
44
|
+
|
|
45
|
+
## Purpose
|
|
46
|
+
The only function that turns errors into exit codes, so that the commands can raise and return plainly and a test
|
|
47
|
+
can call a command without a process.
|
|
48
|
+
|
|
49
|
+
## Exit Codes
|
|
50
|
+
0 done, 1 an error of the library, a cancelled question or a closed output, 2 a wrong usage (from `argparse`), 130 Ctrl+C.
|
|
51
|
+
|
|
52
|
+
## A Closed Pipe
|
|
53
|
+
A reader that stops reading (`simplibs-guide check | head`) closes the pipe, and the next `print` raises `BrokenPipeError`. It is no bug of the command, so it gets no traceback: the output is pointed at the null device, so that Python does not complain again when it flushes at exit, and the code is 1.
|
|
54
|
+
"""
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Inners
|
|
2
|
+
from ._helpers import build_error_message
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class GuideError(Exception):
|
|
6
|
+
"""The error of `simplibs-guide`: a plain message that says what happened and what to do next.
|
|
7
|
+
|
|
8
|
+
The text holds the code of the error, what happened, the value that failed, what was expected
|
|
9
|
+
and the steps that help. The commands print it as it is.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# --- Attributes Type Annotations ---
|
|
13
|
+
error_name: str
|
|
14
|
+
what: str
|
|
15
|
+
value: object
|
|
16
|
+
expected: str | None
|
|
17
|
+
how_to_fix: tuple[str, ...]
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
error_name: str,
|
|
22
|
+
what: str,
|
|
23
|
+
*,
|
|
24
|
+
value: object = None,
|
|
25
|
+
expected: str | None = None,
|
|
26
|
+
how_to_fix: tuple[str, ...] = (),
|
|
27
|
+
) -> None:
|
|
28
|
+
"""Build the error and its text.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
error_name: The code of the error, `UPPER_SNAKE_CASE`, such as `GUIDE_NAMES_INVALID_NAME_ERROR`.
|
|
32
|
+
what: One sentence: what happened.
|
|
33
|
+
value: The value that failed; `None` when there is none to show.
|
|
34
|
+
expected: What was expected.
|
|
35
|
+
how_to_fix: Steps that help, one sentence each.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
# 1. The parts stay on the error, so that a test can compare them
|
|
39
|
+
self.error_name = error_name
|
|
40
|
+
self.what = what
|
|
41
|
+
self.value = value
|
|
42
|
+
self.expected = expected
|
|
43
|
+
self.how_to_fix = how_to_fix
|
|
44
|
+
|
|
45
|
+
# 2. The text is made once, from the parts
|
|
46
|
+
super().__init__(build_error_message(error_name, what, value, expected, how_to_fix))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
_DESIGN_NOTES = """
|
|
50
|
+
# GuideError — a Plain Error That Advises
|
|
51
|
+
|
|
52
|
+
## Purpose
|
|
53
|
+
The one error of `simplibs-guide`. A command that fails raises it, and `run_cli` prints its text and returns 1.
|
|
54
|
+
|
|
55
|
+
## State
|
|
56
|
+
|
|
57
|
+
| Attribute | Type | Role |
|
|
58
|
+
| :----------- | :------------------ | :------------------------------------------------ |
|
|
59
|
+
| `error_name` | `str` | The code of the error, one token, easy to search. |
|
|
60
|
+
| `what` | `str` | What happened, in one sentence. |
|
|
61
|
+
| `value` | `object` | The value that failed, or `None`. |
|
|
62
|
+
| `expected` | `str \\| None` | What was expected. |
|
|
63
|
+
| `how_to_fix` | `tuple[str, ...]` | Steps that help. |
|
|
64
|
+
|
|
65
|
+
## Why Its Own Class
|
|
66
|
+
The library has no dependency, so it cannot use the card of `simplibs-exception`. The message keeps the same idea
|
|
67
|
+
(what happened, the value, what was expected, how to fix it), only as plain text. The parts also stay as attributes,
|
|
68
|
+
so a test checks `error.error_name` and not a sentence.
|
|
69
|
+
|
|
70
|
+
## Why No Subclasses
|
|
71
|
+
A command only needs to know that the library failed and to print why. The code in `error_name` tells the cases apart.
|
|
72
|
+
"""
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Inners
|
|
2
|
+
from .GuideError import GuideError
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
_DESIGN_NOTES = """
|
|
6
|
+
# Errors Sub-Package
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
The error of the library: one class, `GuideError`, which every command catches, prints and turns into the exit code 1.
|
|
10
|
+
|
|
11
|
+
## Internal Components Registry
|
|
12
|
+
|
|
13
|
+
| Component | Type | Description |
|
|
14
|
+
| :----------- | :----- | :--------------------------------------------------------------------------- |
|
|
15
|
+
| `GuideError` | Class | The one error of the library: a plain message that says what to do next. |
|
|
16
|
+
| `_helpers` | Folder | Internal helpers of the error; not exported. |
|
|
17
|
+
|
|
18
|
+
## Layering & Design
|
|
19
|
+
- `simplibs-guide` stands at level 00 and has no dependency, so it cannot raise through `simplibs-exception`. The error is its own and plain, and the style of the other libraries stays: the message says what happened and how to go on.
|
|
20
|
+
"""
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Inners
|
|
2
|
+
from .build_error_message import build_error_message
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
_DESIGN_NOTES = """
|
|
6
|
+
# Helpers Sub-Package
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
Internal helpers of the error. Nothing here leaves the library.
|
|
10
|
+
|
|
11
|
+
## Internal Components Registry
|
|
12
|
+
|
|
13
|
+
| Component | Type | Description |
|
|
14
|
+
| :-------------------- | :------- | :---------------------------------------------------- |
|
|
15
|
+
| `build_error_message` | Function | Puts the parts of an error together into its text. |
|
|
16
|
+
"""
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
def build_error_message(
|
|
2
|
+
error_name: str,
|
|
3
|
+
what: str,
|
|
4
|
+
value: object,
|
|
5
|
+
expected: str | None,
|
|
6
|
+
how_to_fix: tuple[str, ...],
|
|
7
|
+
) -> str:
|
|
8
|
+
"""Put the parts of an error together into the plain text the commands print.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
error_name: The code of the error.
|
|
12
|
+
what: One sentence: what happened.
|
|
13
|
+
value: The value that failed, or `None` for none.
|
|
14
|
+
expected: What was expected, or `None`.
|
|
15
|
+
how_to_fix: Steps that help; empty for none.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
The text: the first line holds the code and what happened, then only the filled parts follow, one per line.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# 1. The first line: the code and what happened
|
|
22
|
+
lines = [f"{error_name}: {what}"]
|
|
23
|
+
|
|
24
|
+
# 2. The value and what was expected, when there are any
|
|
25
|
+
if value is not None:
|
|
26
|
+
lines.append(f" value: {value!r}")
|
|
27
|
+
if expected:
|
|
28
|
+
lines.append(f" expected: {expected}")
|
|
29
|
+
|
|
30
|
+
# 3. The steps that help
|
|
31
|
+
if how_to_fix:
|
|
32
|
+
lines.append(" how to fix:")
|
|
33
|
+
lines.extend(f" - {step}" for step in how_to_fix)
|
|
34
|
+
|
|
35
|
+
return "\n".join(lines)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
_DESIGN_NOTES = """
|
|
39
|
+
# build_error_message — the Text of an Error
|
|
40
|
+
|
|
41
|
+
## Purpose
|
|
42
|
+
One place for the look of every message, so that all errors of the library read the same: the first line says the
|
|
43
|
+
code and what happened, the lines under it are indented and only the filled ones are written.
|
|
44
|
+
|
|
45
|
+
## Why `repr` for the Value
|
|
46
|
+
The quotes show an empty text, a space at the end and a path with a space, which a plain `print` would hide.
|
|
47
|
+
"""
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
_DESIGN_NOTES = """
|
|
2
|
+
# Logic Sub-Package
|
|
3
|
+
|
|
4
|
+
## Purpose
|
|
5
|
+
What the tools do, apart from the command line: the commands only read the arguments, call these domains and print.
|
|
6
|
+
The root imports the public names from them directly (`simplibs.guide.logic.scaffold_library`, …).
|
|
7
|
+
|
|
8
|
+
## Internal Components Registry
|
|
9
|
+
|
|
10
|
+
| Component | Type | Description |
|
|
11
|
+
| :------------------------ | :----- | :---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
12
|
+
| `derive_library_names` | Folder | The three shapes of a library name, `NAME`, `IMPORT` and `UPPER`, from the folder name. |
|
|
13
|
+
| `load_manifest` | Folder | Reads and checks `MANIFEST.toml`: the tokens, the templates, the folders. |
|
|
14
|
+
| `scaffold_library` | Folder | Plans and writes the files of a new library from the templates. |
|
|
15
|
+
| `check_library` | Folder | Lists what is not ready for the upload in a library folder. |
|
|
16
|
+
| `archive_library` | Folder | Packs a folder into a zip, without what git leaves out. |
|
|
17
|
+
| `pack_and_unpack_batches` | Folder | Makes the files of a batch (many files in one text, split by marker lines), and packs a folder into one, whole or as bare code for an AI. |
|
|
18
|
+
|
|
19
|
+
## Layering & Design
|
|
20
|
+
- `derive_library_names`, `load_manifest` and `archive_library` stand on their own; `pack_and_unpack_batches` uses the walk of `archive_library` (its public `collect_archive_files`) to pack files; `scaffold_library` uses the first two; `check_library` uses `scaffold_library` to know what the skeleton should hold.
|
|
21
|
+
- A domain never imports the `_helpers` or `_validations` of another one.
|
|
22
|
+
"""
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from .types import ArchiveReport
|
|
2
|
+
from .archive_folder import archive_folder
|
|
3
|
+
from .collect_archive_files import collect_archive_files
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
_DESIGN_NOTES = """
|
|
7
|
+
# Archive Sub-Package
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
Packs a folder into a zip, without what git leaves out: the same work as the script `__DOC__/_tools/_create_code_zip.py`, so that it can also be
|
|
11
|
+
asked for on the command line, `simplibs-guide zip <folder>`. It reads the folder and writes the one zip; it changes nothing else.
|
|
12
|
+
|
|
13
|
+
## Internal Components Registry
|
|
14
|
+
|
|
15
|
+
| Component | Type | Description |
|
|
16
|
+
| :---------------------- | :------- | :------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `ArchiveReport` | Type | What was done: the folder, the zip, the packed paths, whether it was written. |
|
|
18
|
+
| `archive_folder` | Function | Collects the files of a folder and writes them into a zip, or only lists them. |
|
|
19
|
+
| `collect_archive_files` | Function | The files a folder holds, without what is left out, in a fixed order; `batch` packs files with it. |
|
|
20
|
+
| `_helpers` | Folder | What the files here use, sorted by who uses it; not exported. |
|
|
21
|
+
| `_validations` | Folder | The checks and the errors they raise; not exported. |
|
|
22
|
+
| `types` | Folder | The types that leave the domain. |
|
|
23
|
+
|
|
24
|
+
## Layering & Design
|
|
25
|
+
- The lists of what is left out are the lists of the script template `scripts/create_code_zip.py.tmpl`, written out again here, because the
|
|
26
|
+
script is one file with no import and this folder is code of the library. A test keeps the two equal; when one list changes, the other changes with it.
|
|
27
|
+
- The walk is exported as `collect_archive_files`: `batch` packs files with it (`create_batch`), so that the lists of what is left out stay in one place.
|
|
28
|
+
"""
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from .is_excluded_file import is_excluded_file
|
|
2
|
+
from .is_excluded_folder import is_excluded_folder
|
|
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
|
+
| `is_excluded_file` | Function | Say whether a zip leaves a file out. |
|
|
16
|
+
| `is_excluded_folder` | Function | Say whether a zip leaves a folder out. |
|
|
17
|
+
| `_constants` | Folder | The fixed values used here; not exported. |
|
|
18
|
+
"""
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
EXCLUDED_FILE_PATTERNS: Final[tuple[str, ...]] = ("*.pyc", "*.pyo", "*.pyd", "*.zip", "*.whl", ".coverage", ".coverage.*", ".DS_Store", "Thumbs.db", ".env")
|
|
5
|
+
"""The files a zip leaves out, in every folder, by a pattern of their name."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_DESIGN_NOTES = """
|
|
9
|
+
# EXCLUDED_FILE_PATTERNS - What a Zip Leaves Out by a Pattern of a File
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
The list of the script `_create_code_zip.py`, written out again. A test keeps the two equal.
|
|
13
|
+
"""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
EXCLUDED_FOLDERS: Final[frozenset[str]] = frozenset({".git", ".venv", "venv", "_old", "__pycache__", ".idea", ".pytest_cache", ".mypy_cache", ".ruff_cache", "htmlcov", "node_modules"})
|
|
5
|
+
"""The folders a zip leaves out at any depth: those of `.gitignore`, and `.git`, because a zip handed over must not carry the history."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_DESIGN_NOTES = """
|
|
9
|
+
# EXCLUDED_FOLDERS - What a Zip Leaves Out by the Name of a Folder
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
The list of the script `_create_code_zip.py`, written out again. A test keeps the two equal; when one changes, the other changes with it.
|
|
13
|
+
|
|
14
|
+
## Not Here: `dist`, `build` and `__DOC__`
|
|
15
|
+
They count only in the root of the packed folder, like `/dist/`, `/build/` and `/__DOC__/` in `.gitignore`, so they are in `EXCLUDED_ROOT_FOLDERS`.
|
|
16
|
+
|
|
17
|
+
## The Backup Folder `_old`
|
|
18
|
+
A copy of a folder that the author keeps while working; the older copies lie inside it, so the exact name is enough. A prefix such as `_old*` could leave a real folder out of the zip without a word, while a forgotten `_old2` outside `_old` is found by the checks, loudly.
|
|
19
|
+
"""
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
EXCLUDED_FOLDER_PATTERNS: Final[tuple[str, ...]] = ("*.egg-info",)
|
|
5
|
+
"""The folders a zip leaves out by a pattern of their name."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_DESIGN_NOTES = """
|
|
9
|
+
# EXCLUDED_FOLDER_PATTERNS - What a Zip Leaves Out by a Pattern of a Folder
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
The list of the script `_create_code_zip.py`, written out again. A test keeps the two equal.
|
|
13
|
+
"""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
EXCLUDED_ROOT_FILES: Final[frozenset[str]] = frozenset({"_create_files.py", "_create_files_test.txt", "_create_code_zip.py", "_fix_line_endings.py", "_create_batch.py", "_create_bare_batch.py"})
|
|
5
|
+
"""The files a zip leaves out only in the root of the packed folder, by their whole name, like `/_create_files.py` and the others in `.gitignore`."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_DESIGN_NOTES = """
|
|
9
|
+
# EXCLUDED_ROOT_FILES - What a Zip Leaves Out Only in the Root, by the Name of a File
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
The tools of `__DOC__/_tools/` and the files they make, when the author copies them into the root of the library to use them: they are not part of the repository, and a zip handed over must not carry them. A name with a leading slash in `.gitignore` means the root only; the same file name deeper in the folder is a file of the library and is packed.
|
|
13
|
+
|
|
14
|
+
## Whole Names, Not Patterns
|
|
15
|
+
The tools are exact names. A pattern such as `_create_files*` would also leave out a file of the library that happens to start with it, and a tool without its name would be committed without a word. The one thing that cannot be a name is the batch a tool makes, because it carries the name of the folder; that is `EXCLUDED_ROOT_FILE_PATTERNS`.
|
|
16
|
+
|
|
17
|
+
## One List in Several Places
|
|
18
|
+
The list of the script `_create_code_zip.py`, written out again. A test keeps the two equal, and keeps both equal to `.gitignore`; when one changes, the others change with it.
|
|
19
|
+
"""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
EXCLUDED_ROOT_FILE_PATTERNS: Final[tuple[str, ...]] = ("*_batch.txt",)
|
|
5
|
+
"""The patterns of the files a zip leaves out only in the root of the packed folder: the batches the tools make, like `/*_batch.txt` in `.gitignore`."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_DESIGN_NOTES = """
|
|
9
|
+
# EXCLUDED_ROOT_FILE_PATTERNS - the Batches the Tools Make, in the Root Only
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
The tools `create-batch` and `create-bare-batch` write `<folder name>_batch.txt` and `<folder name>_bare_batch.txt` into the current folder, and when the author stands in the root of a library, the file lies there. It holds the whole code of the library, so it must neither be committed nor travel in a zip handed over. The name carries the name of the folder, so it cannot be a whole name in `EXCLUDED_ROOT_FILES`; one pattern covers both outputs, and also `_create_files_batch.txt`.
|
|
13
|
+
|
|
14
|
+
## The Root Only
|
|
15
|
+
Like `/*_batch.txt` in `.gitignore`: the pattern counts only for a file in the root of the packed folder. A file of the same kind deeper in the folder is a file of the library.
|
|
16
|
+
|
|
17
|
+
## One List in Several Places
|
|
18
|
+
The same pattern stands in `.gitignore.tmpl`, in the check and in the script `_create_code_zip.py`. A test keeps them equal.
|
|
19
|
+
"""
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
EXCLUDED_ROOT_FOLDERS: Final[frozenset[str]] = frozenset({"dist", "build", "__DOC__"})
|
|
5
|
+
"""The folders a zip leaves out only in the root of the packed folder, like `/dist/`, `/build/` and `/__DOC__/` in `.gitignore`: a library may have a package of that name."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_DESIGN_NOTES = """
|
|
9
|
+
# EXCLUDED_ROOT_FOLDERS - What a Zip Leaves Out Only in the Root, by the Name of a Folder
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
A name with a leading slash in `.gitignore` means the root only. `/dist/` and `/build/` are the output of the build of the library and `/__DOC__/` is its internal documentation and scratch folder; a folder of the same name deeper in the tree (for example a package `src/simplibs/<IMPORT>/build/`) is a part of the library and is packed.
|
|
13
|
+
|
|
14
|
+
## One List in Two Places
|
|
15
|
+
The list of the script `_create_code_zip.py`, written out again. A test keeps the two equal; when one changes, the other changes with it.
|
|
16
|
+
"""
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from .EXCLUDED_FILE_PATTERNS import EXCLUDED_FILE_PATTERNS
|
|
2
|
+
from .EXCLUDED_FOLDER_PATTERNS import EXCLUDED_FOLDER_PATTERNS
|
|
3
|
+
from .EXCLUDED_FOLDERS import EXCLUDED_FOLDERS
|
|
4
|
+
from .EXCLUDED_ROOT_FILE_PATTERNS import EXCLUDED_ROOT_FILE_PATTERNS
|
|
5
|
+
from .EXCLUDED_ROOT_FILES import EXCLUDED_ROOT_FILES
|
|
6
|
+
from .EXCLUDED_ROOT_FOLDERS import EXCLUDED_ROOT_FOLDERS
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
_DESIGN_NOTES = """
|
|
10
|
+
# Constants Sub-Package
|
|
11
|
+
|
|
12
|
+
## Purpose
|
|
13
|
+
The fixed values that the code next to this folder uses. Nothing here leaves the library.
|
|
14
|
+
|
|
15
|
+
## Internal Components Registry
|
|
16
|
+
|
|
17
|
+
| Component | Type | Description |
|
|
18
|
+
| :---------------------------- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| `EXCLUDED_FILE_PATTERNS` | Constant | The files a zip leaves out, in every folder, by a pattern of their name. |
|
|
20
|
+
| `EXCLUDED_FOLDER_PATTERNS` | Constant | The folders a zip leaves out by a pattern of their name. |
|
|
21
|
+
| `EXCLUDED_FOLDERS` | Constant | The folders a zip leaves out at any depth: those of `.gitignore`, and `.git`, because a zip handed over must not carry the history. |
|
|
22
|
+
| `EXCLUDED_ROOT_FILE_PATTERNS` | Constant | The patterns of the files a zip leaves out only in the root of the packed folder: the batches the tools make, like `/*_batch.txt` in `.gitignore`. |
|
|
23
|
+
| `EXCLUDED_ROOT_FILES` | Constant | The files a zip leaves out only in the root of the packed folder, by their whole name, like `/_create_files.py` and the others in `.gitignore`. |
|
|
24
|
+
| `EXCLUDED_ROOT_FOLDERS` | Constant | The folders a zip leaves out only in the root of the packed folder, like `/dist/`, `/build/` and `/__DOC__/` in `.gitignore`: a library may have a package of that name. |
|
|
25
|
+
"""
|