flat-packager 0.5.2__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flat_packager-0.5.2/src/flat_packager.egg-info → flat_packager-0.6.0}/PKG-INFO +28 -5
- {flat_packager-0.5.2 → flat_packager-0.6.0}/README.md +27 -4
- {flat_packager-0.5.2 → flat_packager-0.6.0}/pyproject.toml +1 -1
- flat_packager-0.6.0/src/flat_packager/__init__.py +43 -0
- flat_packager-0.6.0/src/flat_packager/_deprecation.py +30 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/inspect.py +6 -3
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/pack.py +32 -8
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/unpack.py +10 -8
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/verify.py +2 -2
- {flat_packager-0.5.2 → flat_packager-0.6.0/src/flat_packager.egg-info}/PKG-INFO +28 -5
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager.egg-info/SOURCES.txt +4 -0
- flat_packager-0.6.0/tests/test_deprecations.py +138 -0
- flat_packager-0.6.0/tests/test_golden_archives.py +98 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/tests/test_markdown.py +8 -2
- {flat_packager-0.5.2 → flat_packager-0.6.0}/tests/test_pack.py +4 -2
- flat_packager-0.6.0/tests/test_public_api.py +66 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/tests/test_roundtrip.py +20 -5
- {flat_packager-0.5.2 → flat_packager-0.6.0}/tests/test_text_encoding.py +1 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/tests/test_version.py +0 -16
- flat_packager-0.5.2/src/flat_packager/__init__.py +0 -25
- {flat_packager-0.5.2 → flat_packager-0.6.0}/LICENSE +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/setup.cfg +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/archive.py +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/content.py +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/markdown.py +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/patterns.py +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/secret_files.py +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager/text_encoding.py +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager.egg-info/dependency_links.txt +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager.egg-info/entry_points.txt +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager.egg-info/requires.txt +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/src/flat_packager.egg-info/top_level.txt +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/tests/test_restore_fuzz.py +0 -0
- {flat_packager-0.5.2 → flat_packager-0.6.0}/tests/test_windows_paths.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flat-packager
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Pack a repository into one flat text archive and restore it later.
|
|
5
5
|
Author: Thomas
|
|
6
6
|
License-Expression: MIT
|
|
@@ -82,7 +82,29 @@ python3 pack_repo.py --help
|
|
|
82
82
|
python3 unpack_repo.py --help
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
## Upgrading
|
|
85
|
+
## Upgrading
|
|
86
|
+
|
|
87
|
+
### Python API changes coming in 1.0
|
|
88
|
+
|
|
89
|
+
The `flat-pack`, `flat-unpack`, `flat-inspect` and `flat-verify` commands are
|
|
90
|
+
not affected. If you call the Python API, 0.6 warns (`DeprecationWarning`)
|
|
91
|
+
about everything that changes in 1.0:
|
|
92
|
+
|
|
93
|
+
| Change in 1.0 | Do this now to be unaffected |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `build_archive()` defaults to `text_encoding="auto"` (was `"base64"`) | Pass `text_encoding` explicitly |
|
|
96
|
+
| `build_archive()` defaults to `respect_gitignore=True` (was `False`) | Pass `respect_gitignore` explicitly |
|
|
97
|
+
| `build_archive()` options after `source_label` and `restore_archive()` options after `output_dir` are keyword-only | Pass them by name |
|
|
98
|
+
| `flat_packager.prepare_source` (clones remote repositories) is removed | No public replacement: clone with `git` yourself and pass the directory to `build_archive`, or use the `flat-pack` CLI |
|
|
99
|
+
| `flat_packager.load_and_validate_archive` is removed | Use `inspect_data(archive_path)`, or `restore_archive(..., verify_only=True)` to validate |
|
|
100
|
+
| `flat_packager.process_archive` is removed | Use `restore_archive` |
|
|
101
|
+
|
|
102
|
+
The public API is `build_archive`, `restore_archive`, `inspect_data`,
|
|
103
|
+
`ArchiveManifest` and `__version__`. Submodules such as `flat_packager.pack`
|
|
104
|
+
are internal. To see the warnings, run your code or tests with
|
|
105
|
+
`python -W error::DeprecationWarning`.
|
|
106
|
+
|
|
107
|
+
### Upgrading from 0.4
|
|
86
108
|
|
|
87
109
|
0.5.0 changes some `flat-pack` defaults, so the same command can produce a
|
|
88
110
|
different archive than before:
|
|
@@ -95,9 +117,10 @@ different archive than before:
|
|
|
95
117
|
| Nested `.git` directories and submodule `.git` files are skipped | `--include-git` |
|
|
96
118
|
|
|
97
119
|
Restoring is unchanged: `flat-unpack` 0.5.0 restores archives made by any
|
|
98
|
-
earlier version.
|
|
99
|
-
text encoding (`base64`) and `.gitignore` (not respected), but
|
|
100
|
-
exclude matching. See [CHANGELOG.md](CHANGELOG.md) for the full
|
|
120
|
+
earlier version. In 0.5 and 0.6 the Python API (`build_archive()`) keeps the
|
|
121
|
+
0.4 defaults for text encoding (`base64`) and `.gitignore` (not respected), but
|
|
122
|
+
uses the new exclude matching. See [CHANGELOG.md](CHANGELOG.md) for the full
|
|
123
|
+
list.
|
|
101
124
|
|
|
102
125
|
## Pack a Repository
|
|
103
126
|
|
|
@@ -47,7 +47,29 @@ python3 pack_repo.py --help
|
|
|
47
47
|
python3 unpack_repo.py --help
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
## Upgrading
|
|
50
|
+
## Upgrading
|
|
51
|
+
|
|
52
|
+
### Python API changes coming in 1.0
|
|
53
|
+
|
|
54
|
+
The `flat-pack`, `flat-unpack`, `flat-inspect` and `flat-verify` commands are
|
|
55
|
+
not affected. If you call the Python API, 0.6 warns (`DeprecationWarning`)
|
|
56
|
+
about everything that changes in 1.0:
|
|
57
|
+
|
|
58
|
+
| Change in 1.0 | Do this now to be unaffected |
|
|
59
|
+
|---|---|
|
|
60
|
+
| `build_archive()` defaults to `text_encoding="auto"` (was `"base64"`) | Pass `text_encoding` explicitly |
|
|
61
|
+
| `build_archive()` defaults to `respect_gitignore=True` (was `False`) | Pass `respect_gitignore` explicitly |
|
|
62
|
+
| `build_archive()` options after `source_label` and `restore_archive()` options after `output_dir` are keyword-only | Pass them by name |
|
|
63
|
+
| `flat_packager.prepare_source` (clones remote repositories) is removed | No public replacement: clone with `git` yourself and pass the directory to `build_archive`, or use the `flat-pack` CLI |
|
|
64
|
+
| `flat_packager.load_and_validate_archive` is removed | Use `inspect_data(archive_path)`, or `restore_archive(..., verify_only=True)` to validate |
|
|
65
|
+
| `flat_packager.process_archive` is removed | Use `restore_archive` |
|
|
66
|
+
|
|
67
|
+
The public API is `build_archive`, `restore_archive`, `inspect_data`,
|
|
68
|
+
`ArchiveManifest` and `__version__`. Submodules such as `flat_packager.pack`
|
|
69
|
+
are internal. To see the warnings, run your code or tests with
|
|
70
|
+
`python -W error::DeprecationWarning`.
|
|
71
|
+
|
|
72
|
+
### Upgrading from 0.4
|
|
51
73
|
|
|
52
74
|
0.5.0 changes some `flat-pack` defaults, so the same command can produce a
|
|
53
75
|
different archive than before:
|
|
@@ -60,9 +82,10 @@ different archive than before:
|
|
|
60
82
|
| Nested `.git` directories and submodule `.git` files are skipped | `--include-git` |
|
|
61
83
|
|
|
62
84
|
Restoring is unchanged: `flat-unpack` 0.5.0 restores archives made by any
|
|
63
|
-
earlier version.
|
|
64
|
-
text encoding (`base64`) and `.gitignore` (not respected), but
|
|
65
|
-
exclude matching. See [CHANGELOG.md](CHANGELOG.md) for the full
|
|
85
|
+
earlier version. In 0.5 and 0.6 the Python API (`build_archive()`) keeps the
|
|
86
|
+
0.4 defaults for text encoding (`base64`) and `.gitignore` (not respected), but
|
|
87
|
+
uses the new exclude matching. See [CHANGELOG.md](CHANGELOG.md) for the full
|
|
88
|
+
list.
|
|
66
89
|
|
|
67
90
|
## Pack a Repository
|
|
68
91
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Pack and restore repositories through a single flat text archive.
|
|
2
|
+
|
|
3
|
+
The public API is the names in ``__all__``. Submodules are internal.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import warnings
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from flat_packager.inspect import inspect_data
|
|
12
|
+
from flat_packager.pack import build_archive
|
|
13
|
+
from flat_packager.unpack import ArchiveManifest, restore_archive
|
|
14
|
+
|
|
15
|
+
__version__ = "0.6.0"
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"ArchiveManifest",
|
|
19
|
+
"__version__",
|
|
20
|
+
"build_archive",
|
|
21
|
+
"inspect_data",
|
|
22
|
+
"restore_archive",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
# Removed from the public API in 0.6; the shims below go away in 1.0.
|
|
26
|
+
_DEPRECATED_INTERNAL = {
|
|
27
|
+
"prepare_source": ("flat_packager.pack", "_prepare_source"),
|
|
28
|
+
"process_archive": ("flat_packager.unpack", "_process_archive"),
|
|
29
|
+
"load_and_validate_archive": ("flat_packager.unpack", "_load_and_validate_archive"),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def __getattr__(name: str) -> Any:
|
|
34
|
+
if name in _DEPRECATED_INTERNAL:
|
|
35
|
+
module_name, attribute = _DEPRECATED_INTERNAL[name]
|
|
36
|
+
warnings.warn(
|
|
37
|
+
f"flat_packager.{name} is internal and will be removed in 1.0",
|
|
38
|
+
DeprecationWarning,
|
|
39
|
+
stacklevel=2,
|
|
40
|
+
)
|
|
41
|
+
module = __import__(module_name, fromlist=[attribute])
|
|
42
|
+
return getattr(module, attribute)
|
|
43
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Deprecation helpers for the 0.6 → 1.0 API transition. Removed in 1.0."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import functools
|
|
6
|
+
import warnings
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
from typing import Any, TypeVar
|
|
9
|
+
|
|
10
|
+
F = TypeVar("F", bound=Callable[..., Any])
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def warn_positional(max_positional: int) -> Callable[[F], F]:
|
|
14
|
+
"""Warn when the wrapped function gets more than ``max_positional`` positional args."""
|
|
15
|
+
|
|
16
|
+
def decorate(func: F) -> F:
|
|
17
|
+
@functools.wraps(func)
|
|
18
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
19
|
+
if len(args) > max_positional:
|
|
20
|
+
warnings.warn(
|
|
21
|
+
f"{func.__name__}(): passing options positionally is deprecated; "
|
|
22
|
+
"pass them as keyword arguments (required from 1.0)",
|
|
23
|
+
DeprecationWarning,
|
|
24
|
+
stacklevel=2,
|
|
25
|
+
)
|
|
26
|
+
return func(*args, **kwargs)
|
|
27
|
+
|
|
28
|
+
return wrapper # type: ignore[return-value]
|
|
29
|
+
|
|
30
|
+
return decorate
|
|
@@ -9,7 +9,7 @@ from pathlib import Path
|
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
11
|
from .archive import detect_archive_compression
|
|
12
|
-
from .unpack import ArchiveManifest,
|
|
12
|
+
from .unpack import ArchiveManifest, _load_and_validate_archive
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def parse_args() -> argparse.Namespace:
|
|
@@ -49,7 +49,10 @@ def symlink_records(manifest: ArchiveManifest) -> list[dict[str, Any]]:
|
|
|
49
49
|
return [record for _line_number, record in manifest.records if record.get("type") == "symlink"]
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
def inspect_data(archive_path: Path, manifest: ArchiveManifest) -> dict[str, Any]:
|
|
52
|
+
def inspect_data(archive_path: Path, manifest: ArchiveManifest | None = None) -> dict[str, Any]:
|
|
53
|
+
"""Summarize an archive. Loads and validates it unless ``manifest`` is given."""
|
|
54
|
+
if manifest is None:
|
|
55
|
+
manifest = _load_and_validate_archive(archive_path)
|
|
53
56
|
files = file_records(manifest)
|
|
54
57
|
symlinks = symlink_records(manifest)
|
|
55
58
|
largest_files = sorted(files, key=lambda record: int(record.get("size", 0)), reverse=True)
|
|
@@ -122,7 +125,7 @@ def main() -> int:
|
|
|
122
125
|
archive_path = Path(args.archive).expanduser().resolve()
|
|
123
126
|
|
|
124
127
|
try:
|
|
125
|
-
manifest =
|
|
128
|
+
manifest = _load_and_validate_archive(archive_path)
|
|
126
129
|
except (OSError, ValueError) as exc:
|
|
127
130
|
print(f"error: {exc}", file=sys.stderr)
|
|
128
131
|
return 1
|
|
@@ -14,12 +14,14 @@ import subprocess
|
|
|
14
14
|
import sys
|
|
15
15
|
import tempfile
|
|
16
16
|
import unicodedata
|
|
17
|
+
import warnings
|
|
17
18
|
from collections.abc import Iterable, Iterator, Sequence
|
|
18
19
|
from datetime import datetime, timezone
|
|
19
20
|
from pathlib import Path
|
|
20
21
|
from typing import TextIO
|
|
21
22
|
from urllib.parse import urlsplit
|
|
22
23
|
|
|
24
|
+
from ._deprecation import warn_positional
|
|
23
25
|
from .archive import (
|
|
24
26
|
ARCHIVE_KIND,
|
|
25
27
|
ARCHIVE_VERSION,
|
|
@@ -239,7 +241,7 @@ def repo_name_from_source(source: str) -> str:
|
|
|
239
241
|
return name
|
|
240
242
|
|
|
241
243
|
|
|
242
|
-
def
|
|
244
|
+
def _prepare_source(
|
|
243
245
|
source: str,
|
|
244
246
|
branch: str | None = None,
|
|
245
247
|
recurse_submodules: bool = False,
|
|
@@ -989,20 +991,21 @@ def spool_dir_for(output_path: Path) -> Path | None:
|
|
|
989
991
|
return parent if os.access(parent, os.W_OK | os.X_OK) else None
|
|
990
992
|
|
|
991
993
|
|
|
994
|
+
@warn_positional(3)
|
|
992
995
|
def build_archive(
|
|
993
996
|
root: Path,
|
|
994
997
|
output_path: Path,
|
|
995
998
|
source_label: str,
|
|
996
|
-
tracked_only: bool,
|
|
997
|
-
include_git: bool,
|
|
998
|
-
exclude_patterns: list[str],
|
|
999
|
-
max_file_bytes: int | None,
|
|
999
|
+
tracked_only: bool = False,
|
|
1000
|
+
include_git: bool = False,
|
|
1001
|
+
exclude_patterns: list[str] | None = None,
|
|
1002
|
+
max_file_bytes: int | None = None,
|
|
1000
1003
|
format_version: int = ARCHIVE_VERSION,
|
|
1001
1004
|
chunk_size: int = DEFAULT_CHUNK_SIZE,
|
|
1002
1005
|
compression: str = "auto",
|
|
1003
|
-
text_encoding: str =
|
|
1006
|
+
text_encoding: str | None = None,
|
|
1004
1007
|
max_inline_text_bytes: int = DEFAULT_MAX_INLINE_TEXT_BYTES,
|
|
1005
|
-
respect_gitignore: bool =
|
|
1008
|
+
respect_gitignore: bool | None = None,
|
|
1006
1009
|
fail_on_secrets: bool = False,
|
|
1007
1010
|
include_patterns: list[str] | None = None,
|
|
1008
1011
|
subdir: str | None = None,
|
|
@@ -1016,7 +1019,28 @@ def build_archive(
|
|
|
1016
1019
|
applies), and ``subdir`` restricts packing to one directory while keeping
|
|
1017
1020
|
root-relative archive paths. If packing fails, the partially written
|
|
1018
1021
|
archive is removed.
|
|
1022
|
+
|
|
1023
|
+
Leaving ``text_encoding`` (``"base64"``) or ``respect_gitignore`` (``False``)
|
|
1024
|
+
unset is deprecated: their defaults change to ``"auto"`` and ``True`` in 1.0.
|
|
1019
1025
|
"""
|
|
1026
|
+
if text_encoding is None:
|
|
1027
|
+
warnings.warn(
|
|
1028
|
+
"build_archive(): text_encoding defaults to 'base64' but will default to 'auto' "
|
|
1029
|
+
"in 1.0; pass text_encoding explicitly",
|
|
1030
|
+
DeprecationWarning,
|
|
1031
|
+
stacklevel=3,
|
|
1032
|
+
)
|
|
1033
|
+
text_encoding = "base64"
|
|
1034
|
+
if respect_gitignore is None:
|
|
1035
|
+
warnings.warn(
|
|
1036
|
+
"build_archive(): respect_gitignore defaults to False but will default to True "
|
|
1037
|
+
"in 1.0; pass respect_gitignore explicitly",
|
|
1038
|
+
DeprecationWarning,
|
|
1039
|
+
stacklevel=3,
|
|
1040
|
+
)
|
|
1041
|
+
respect_gitignore = False
|
|
1042
|
+
if exclude_patterns is None:
|
|
1043
|
+
exclude_patterns = []
|
|
1020
1044
|
if format_version not in (1, 2):
|
|
1021
1045
|
raise ValueError(f"unsupported archive format version: {format_version}")
|
|
1022
1046
|
if chunk_size <= 0:
|
|
@@ -1138,7 +1162,7 @@ def main() -> int:
|
|
|
1138
1162
|
args = parse_args()
|
|
1139
1163
|
temp_dir: str | None = None
|
|
1140
1164
|
try:
|
|
1141
|
-
root, temp_dir =
|
|
1165
|
+
root, temp_dir = _prepare_source(
|
|
1142
1166
|
args.source,
|
|
1143
1167
|
branch=args.branch,
|
|
1144
1168
|
recurse_submodules=args.recurse_submodules,
|
|
@@ -15,6 +15,7 @@ from dataclasses import dataclass, field
|
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
from typing import Any
|
|
17
17
|
|
|
18
|
+
from ._deprecation import warn_positional
|
|
18
19
|
from .archive import ARCHIVE_KIND, SUPPORTED_ARCHIVE_VERSIONS, read_json_lines
|
|
19
20
|
from .content import file_content_bytes, validate_inline_file_record
|
|
20
21
|
|
|
@@ -480,7 +481,7 @@ def validate_end_record(
|
|
|
480
481
|
raise ValueError(f"{key} count mismatch: expected {expected}, got {actual}")
|
|
481
482
|
|
|
482
483
|
|
|
483
|
-
def
|
|
484
|
+
def _process_archive(
|
|
484
485
|
archive_path: Path,
|
|
485
486
|
*,
|
|
486
487
|
write_root: Path | None = None,
|
|
@@ -594,8 +595,8 @@ def process_archive(
|
|
|
594
595
|
)
|
|
595
596
|
|
|
596
597
|
|
|
597
|
-
def
|
|
598
|
-
return
|
|
598
|
+
def _load_and_validate_archive(archive_path: Path) -> ArchiveManifest:
|
|
599
|
+
return _process_archive(archive_path, collect_records=True)
|
|
599
600
|
|
|
600
601
|
|
|
601
602
|
def ensure_output_replaceable(output_dir: Path, overwrite: bool) -> None:
|
|
@@ -638,16 +639,17 @@ def replace_output_with_staging(staging_dir: Path, output_dir: Path, overwrite:
|
|
|
638
639
|
backup_dir.unlink()
|
|
639
640
|
|
|
640
641
|
|
|
642
|
+
@warn_positional(2)
|
|
641
643
|
def restore_archive(
|
|
642
644
|
archive_path: Path,
|
|
643
645
|
output_dir: Path,
|
|
644
|
-
overwrite: bool,
|
|
645
|
-
verify_only: bool,
|
|
646
|
-
no_symlinks: bool,
|
|
646
|
+
overwrite: bool = False,
|
|
647
|
+
verify_only: bool = False,
|
|
648
|
+
no_symlinks: bool = False,
|
|
647
649
|
preserve_special_bits: bool = False,
|
|
648
650
|
) -> tuple[int, int]:
|
|
649
651
|
if verify_only:
|
|
650
|
-
manifest =
|
|
652
|
+
manifest = _process_archive(archive_path)
|
|
651
653
|
return manifest.entries, manifest.files
|
|
652
654
|
|
|
653
655
|
output_dir = absolute_path(output_dir)
|
|
@@ -662,7 +664,7 @@ def restore_archive(
|
|
|
662
664
|
)
|
|
663
665
|
staging_dir: Path | None = staging_path
|
|
664
666
|
try:
|
|
665
|
-
manifest =
|
|
667
|
+
manifest = _process_archive(
|
|
666
668
|
archive_path,
|
|
667
669
|
write_root=staging_path,
|
|
668
670
|
no_symlinks=no_symlinks,
|
|
@@ -7,7 +7,7 @@ import sys
|
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
9
|
from .archive import detect_archive_compression
|
|
10
|
-
from .unpack import
|
|
10
|
+
from .unpack import _load_and_validate_archive
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def parse_args() -> argparse.Namespace:
|
|
@@ -21,7 +21,7 @@ def main() -> int:
|
|
|
21
21
|
archive_path = Path(args.archive).expanduser().resolve()
|
|
22
22
|
|
|
23
23
|
try:
|
|
24
|
-
manifest =
|
|
24
|
+
manifest = _load_and_validate_archive(archive_path)
|
|
25
25
|
except (OSError, ValueError) as exc:
|
|
26
26
|
print(f"error: {exc}", file=sys.stderr)
|
|
27
27
|
return 1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flat-packager
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Pack a repository into one flat text archive and restore it later.
|
|
5
5
|
Author: Thomas
|
|
6
6
|
License-Expression: MIT
|
|
@@ -82,7 +82,29 @@ python3 pack_repo.py --help
|
|
|
82
82
|
python3 unpack_repo.py --help
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
## Upgrading
|
|
85
|
+
## Upgrading
|
|
86
|
+
|
|
87
|
+
### Python API changes coming in 1.0
|
|
88
|
+
|
|
89
|
+
The `flat-pack`, `flat-unpack`, `flat-inspect` and `flat-verify` commands are
|
|
90
|
+
not affected. If you call the Python API, 0.6 warns (`DeprecationWarning`)
|
|
91
|
+
about everything that changes in 1.0:
|
|
92
|
+
|
|
93
|
+
| Change in 1.0 | Do this now to be unaffected |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `build_archive()` defaults to `text_encoding="auto"` (was `"base64"`) | Pass `text_encoding` explicitly |
|
|
96
|
+
| `build_archive()` defaults to `respect_gitignore=True` (was `False`) | Pass `respect_gitignore` explicitly |
|
|
97
|
+
| `build_archive()` options after `source_label` and `restore_archive()` options after `output_dir` are keyword-only | Pass them by name |
|
|
98
|
+
| `flat_packager.prepare_source` (clones remote repositories) is removed | No public replacement: clone with `git` yourself and pass the directory to `build_archive`, or use the `flat-pack` CLI |
|
|
99
|
+
| `flat_packager.load_and_validate_archive` is removed | Use `inspect_data(archive_path)`, or `restore_archive(..., verify_only=True)` to validate |
|
|
100
|
+
| `flat_packager.process_archive` is removed | Use `restore_archive` |
|
|
101
|
+
|
|
102
|
+
The public API is `build_archive`, `restore_archive`, `inspect_data`,
|
|
103
|
+
`ArchiveManifest` and `__version__`. Submodules such as `flat_packager.pack`
|
|
104
|
+
are internal. To see the warnings, run your code or tests with
|
|
105
|
+
`python -W error::DeprecationWarning`.
|
|
106
|
+
|
|
107
|
+
### Upgrading from 0.4
|
|
86
108
|
|
|
87
109
|
0.5.0 changes some `flat-pack` defaults, so the same command can produce a
|
|
88
110
|
different archive than before:
|
|
@@ -95,9 +117,10 @@ different archive than before:
|
|
|
95
117
|
| Nested `.git` directories and submodule `.git` files are skipped | `--include-git` |
|
|
96
118
|
|
|
97
119
|
Restoring is unchanged: `flat-unpack` 0.5.0 restores archives made by any
|
|
98
|
-
earlier version.
|
|
99
|
-
text encoding (`base64`) and `.gitignore` (not respected), but
|
|
100
|
-
exclude matching. See [CHANGELOG.md](CHANGELOG.md) for the full
|
|
120
|
+
earlier version. In 0.5 and 0.6 the Python API (`build_archive()`) keeps the
|
|
121
|
+
0.4 defaults for text encoding (`base64`) and `.gitignore` (not respected), but
|
|
122
|
+
uses the new exclude matching. See [CHANGELOG.md](CHANGELOG.md) for the full
|
|
123
|
+
list.
|
|
101
124
|
|
|
102
125
|
## Pack a Repository
|
|
103
126
|
|
|
@@ -2,6 +2,7 @@ LICENSE
|
|
|
2
2
|
README.md
|
|
3
3
|
pyproject.toml
|
|
4
4
|
src/flat_packager/__init__.py
|
|
5
|
+
src/flat_packager/_deprecation.py
|
|
5
6
|
src/flat_packager/archive.py
|
|
6
7
|
src/flat_packager/content.py
|
|
7
8
|
src/flat_packager/inspect.py
|
|
@@ -18,8 +19,11 @@ src/flat_packager.egg-info/dependency_links.txt
|
|
|
18
19
|
src/flat_packager.egg-info/entry_points.txt
|
|
19
20
|
src/flat_packager.egg-info/requires.txt
|
|
20
21
|
src/flat_packager.egg-info/top_level.txt
|
|
22
|
+
tests/test_deprecations.py
|
|
23
|
+
tests/test_golden_archives.py
|
|
21
24
|
tests/test_markdown.py
|
|
22
25
|
tests/test_pack.py
|
|
26
|
+
tests/test_public_api.py
|
|
23
27
|
tests/test_restore_fuzz.py
|
|
24
28
|
tests/test_roundtrip.py
|
|
25
29
|
tests/test_text_encoding.py
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""0.6 deprecations of build_archive()/restore_archive() defaults and positional options."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
import tempfile
|
|
9
|
+
import unittest
|
|
10
|
+
import warnings
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
14
|
+
|
|
15
|
+
from flat_packager import build_archive, restore_archive
|
|
16
|
+
from flat_packager.archive import read_json_lines
|
|
17
|
+
|
|
18
|
+
SRC = Path(__file__).resolve().parents[1] / "src"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def file_encodings(archive: Path) -> set[str]:
|
|
22
|
+
return {
|
|
23
|
+
str(record["encoding"])
|
|
24
|
+
for _line, record in read_json_lines(archive)
|
|
25
|
+
if record.get("type") == "file"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class DeprecationTests(unittest.TestCase):
|
|
30
|
+
def setUp(self) -> None:
|
|
31
|
+
self._tmp = tempfile.TemporaryDirectory(prefix="flat-packager-deprecation-")
|
|
32
|
+
self.tmp = Path(self._tmp.name)
|
|
33
|
+
self.source = self.tmp / "source"
|
|
34
|
+
self.source.mkdir()
|
|
35
|
+
(self.source / "a.txt").write_text("hello\n", encoding="utf-8")
|
|
36
|
+
self.archive = self.tmp / "out.flat.txt"
|
|
37
|
+
|
|
38
|
+
def tearDown(self) -> None:
|
|
39
|
+
self._tmp.cleanup()
|
|
40
|
+
|
|
41
|
+
def explicit_build(self, **overrides: object) -> None:
|
|
42
|
+
options: dict[str, object] = {
|
|
43
|
+
"root": self.source,
|
|
44
|
+
"output_path": self.archive,
|
|
45
|
+
"source_label": "source",
|
|
46
|
+
"text_encoding": "auto",
|
|
47
|
+
"respect_gitignore": False,
|
|
48
|
+
}
|
|
49
|
+
options.update(overrides)
|
|
50
|
+
build_archive(**options) # type: ignore[arg-type]
|
|
51
|
+
|
|
52
|
+
def test_text_encoding_default_warns(self) -> None:
|
|
53
|
+
with self.assertWarnsRegex(
|
|
54
|
+
DeprecationWarning,
|
|
55
|
+
r"build_archive\(\): text_encoding defaults to 'base64' but will default to "
|
|
56
|
+
r"'auto' in 1\.0; pass text_encoding explicitly",
|
|
57
|
+
) as caught:
|
|
58
|
+
build_archive(
|
|
59
|
+
root=self.source,
|
|
60
|
+
output_path=self.archive,
|
|
61
|
+
source_label="source",
|
|
62
|
+
respect_gitignore=False,
|
|
63
|
+
)
|
|
64
|
+
self.assertEqual(caught.filename, __file__)
|
|
65
|
+
self.assertNotIn("utf8", file_encodings(self.archive))
|
|
66
|
+
|
|
67
|
+
def test_respect_gitignore_default_warns(self) -> None:
|
|
68
|
+
with self.assertWarnsRegex(
|
|
69
|
+
DeprecationWarning,
|
|
70
|
+
r"build_archive\(\): respect_gitignore defaults to False but will default to "
|
|
71
|
+
r"True in 1\.0; pass respect_gitignore explicitly",
|
|
72
|
+
) as caught:
|
|
73
|
+
build_archive(
|
|
74
|
+
root=self.source,
|
|
75
|
+
output_path=self.archive,
|
|
76
|
+
source_label="source",
|
|
77
|
+
text_encoding="auto",
|
|
78
|
+
)
|
|
79
|
+
self.assertEqual(caught.filename, __file__)
|
|
80
|
+
|
|
81
|
+
def test_explicit_options_do_not_warn(self) -> None:
|
|
82
|
+
with warnings.catch_warnings():
|
|
83
|
+
warnings.simplefilter("error", DeprecationWarning)
|
|
84
|
+
self.explicit_build()
|
|
85
|
+
self.assertEqual(file_encodings(self.archive), {"utf8"})
|
|
86
|
+
|
|
87
|
+
def test_positional_options_warn(self) -> None:
|
|
88
|
+
with self.assertWarnsRegex(
|
|
89
|
+
DeprecationWarning,
|
|
90
|
+
r"build_archive\(\): passing options positionally is deprecated; pass them as "
|
|
91
|
+
r"keyword arguments \(required from 1\.0\)",
|
|
92
|
+
) as caught:
|
|
93
|
+
build_archive( # type: ignore[misc]
|
|
94
|
+
self.source,
|
|
95
|
+
self.archive,
|
|
96
|
+
"source",
|
|
97
|
+
False,
|
|
98
|
+
text_encoding="auto",
|
|
99
|
+
respect_gitignore=False,
|
|
100
|
+
)
|
|
101
|
+
self.assertEqual(caught.filename, __file__)
|
|
102
|
+
|
|
103
|
+
def test_restore_positional_options_warn(self) -> None:
|
|
104
|
+
self.explicit_build()
|
|
105
|
+
with self.assertWarnsRegex(
|
|
106
|
+
DeprecationWarning, r"restore_archive\(\): passing options positionally"
|
|
107
|
+
):
|
|
108
|
+
restore_archive(self.archive, self.tmp / "out", False, False, False) # type: ignore[misc]
|
|
109
|
+
self.assertTrue((self.tmp / "out" / "a.txt").is_file())
|
|
110
|
+
|
|
111
|
+
def test_restore_keyword_defaults(self) -> None:
|
|
112
|
+
self.explicit_build()
|
|
113
|
+
with warnings.catch_warnings():
|
|
114
|
+
warnings.simplefilter("error", DeprecationWarning)
|
|
115
|
+
restore_archive(archive_path=self.archive, output_dir=self.tmp / "out")
|
|
116
|
+
self.assertEqual((self.tmp / "out" / "a.txt").read_text(encoding="utf-8"), "hello\n")
|
|
117
|
+
|
|
118
|
+
def test_cli_pack_emits_no_deprecation_warning(self) -> None:
|
|
119
|
+
result = subprocess.run(
|
|
120
|
+
[
|
|
121
|
+
sys.executable,
|
|
122
|
+
"-W",
|
|
123
|
+
"error::DeprecationWarning",
|
|
124
|
+
"-m",
|
|
125
|
+
"flat_packager.pack",
|
|
126
|
+
str(self.source),
|
|
127
|
+
str(self.archive),
|
|
128
|
+
],
|
|
129
|
+
capture_output=True,
|
|
130
|
+
text=True,
|
|
131
|
+
env={**os.environ, "PYTHONPATH": str(SRC)},
|
|
132
|
+
)
|
|
133
|
+
self.assertEqual(result.returncode, 0, result.stderr)
|
|
134
|
+
self.assertNotIn("DeprecationWarning", result.stderr)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
if __name__ == "__main__":
|
|
138
|
+
unittest.main()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Every archive written by an earlier release must still restore exactly."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
import tempfile
|
|
9
|
+
import unittest
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
13
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
14
|
+
|
|
15
|
+
import golden_tree
|
|
16
|
+
|
|
17
|
+
from flat_packager import restore_archive
|
|
18
|
+
|
|
19
|
+
FIXTURES = Path(__file__).resolve().parent / "fixtures" / "archives"
|
|
20
|
+
EXPECTED_FIXTURES = {
|
|
21
|
+
"0.4.2/v1-base64.flat.txt",
|
|
22
|
+
"0.4.2/v2-base64.flat.txt",
|
|
23
|
+
"0.4.2/v2-base64.flat.txt.gz",
|
|
24
|
+
"0.5.2/v1-utf8.flat.txt",
|
|
25
|
+
"0.5.2/v2-auto.flat.txt",
|
|
26
|
+
"0.5.2/v2-auto.flat.txt.gz",
|
|
27
|
+
}
|
|
28
|
+
# Windows runners can't reliably create symlinks or keep exec bits.
|
|
29
|
+
ON_WINDOWS = os.name == "nt"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def fixture_paths(root: Path = FIXTURES) -> list[str]:
|
|
33
|
+
"""Fixture archives under ``root``, ignoring dotfiles such as Finder's .DS_Store."""
|
|
34
|
+
return sorted(
|
|
35
|
+
path.relative_to(root).as_posix()
|
|
36
|
+
for path in root.glob("*/*")
|
|
37
|
+
if path.is_file() and not path.name.startswith(".")
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class GoldenArchiveTests(unittest.TestCase):
|
|
42
|
+
def setUp(self) -> None:
|
|
43
|
+
self._tmp = tempfile.TemporaryDirectory(prefix="flat-packager-golden-")
|
|
44
|
+
self.tmp = Path(self._tmp.name)
|
|
45
|
+
|
|
46
|
+
def tearDown(self) -> None:
|
|
47
|
+
self._tmp.cleanup()
|
|
48
|
+
|
|
49
|
+
def test_fixture_paths_ignore_dotfiles(self) -> None:
|
|
50
|
+
(self.tmp / "9.9.9").mkdir()
|
|
51
|
+
(self.tmp / "9.9.9" / "v2.flat.txt").write_text("{}\n", encoding="utf-8")
|
|
52
|
+
(self.tmp / "9.9.9" / ".DS_Store").write_bytes(b"\0")
|
|
53
|
+
self.assertEqual(fixture_paths(self.tmp), ["9.9.9/v2.flat.txt"])
|
|
54
|
+
|
|
55
|
+
def test_fixture_matrix_is_complete(self) -> None:
|
|
56
|
+
self.assertEqual(set(fixture_paths()), EXPECTED_FIXTURES)
|
|
57
|
+
|
|
58
|
+
def test_fixture_bytes_match_sha256sums(self) -> None:
|
|
59
|
+
recorded = {}
|
|
60
|
+
for line in (FIXTURES / "SHA256SUMS").read_text(encoding="utf-8").splitlines():
|
|
61
|
+
digest, name = line.split(maxsplit=1)
|
|
62
|
+
recorded[name] = digest
|
|
63
|
+
self.assertEqual(set(recorded), set(fixture_paths()))
|
|
64
|
+
for name, digest in recorded.items():
|
|
65
|
+
with self.subTest(fixture=name):
|
|
66
|
+
actual = hashlib.sha256((FIXTURES / name).read_bytes()).hexdigest()
|
|
67
|
+
self.assertEqual(actual, digest)
|
|
68
|
+
|
|
69
|
+
def test_every_fixture_restores_to_canonical_tree(self) -> None:
|
|
70
|
+
expected = golden_tree.expected(symlinks_as_files=ON_WINDOWS, check_exec=not ON_WINDOWS)
|
|
71
|
+
for name in fixture_paths():
|
|
72
|
+
with self.subTest(fixture=name):
|
|
73
|
+
output = self.tmp / name.replace("/", "_")
|
|
74
|
+
restore_archive(
|
|
75
|
+
archive_path=FIXTURES / name,
|
|
76
|
+
output_dir=output,
|
|
77
|
+
overwrite=False,
|
|
78
|
+
verify_only=False,
|
|
79
|
+
no_symlinks=ON_WINDOWS,
|
|
80
|
+
)
|
|
81
|
+
actual = golden_tree.describe(output, check_exec=not ON_WINDOWS)
|
|
82
|
+
self.assertEqual(actual, expected)
|
|
83
|
+
|
|
84
|
+
def test_every_fixture_verifies(self) -> None:
|
|
85
|
+
for name in fixture_paths():
|
|
86
|
+
with self.subTest(fixture=name):
|
|
87
|
+
restore_archive(
|
|
88
|
+
archive_path=FIXTURES / name,
|
|
89
|
+
output_dir=self.tmp / "unused",
|
|
90
|
+
overwrite=False,
|
|
91
|
+
verify_only=True,
|
|
92
|
+
no_symlinks=False,
|
|
93
|
+
)
|
|
94
|
+
self.assertFalse((self.tmp / "unused").exists())
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
unittest.main()
|
|
@@ -131,7 +131,13 @@ class MarkdownOutputTests(MarkdownTestCase):
|
|
|
131
131
|
|
|
132
132
|
(self.source / "package-lock.json").write_text("{}\n")
|
|
133
133
|
archive = self.work_dir / "out.txt"
|
|
134
|
-
build_archive(
|
|
134
|
+
build_archive(
|
|
135
|
+
root=self.source,
|
|
136
|
+
output_path=archive,
|
|
137
|
+
source_label="x",
|
|
138
|
+
text_encoding="base64",
|
|
139
|
+
respect_gitignore=False,
|
|
140
|
+
)
|
|
135
141
|
paths = {r.get("path") for _l, r in read_json_lines(archive)}
|
|
136
142
|
self.assertIn("package-lock.json", paths)
|
|
137
143
|
|
|
@@ -200,7 +206,7 @@ class MarkdownCliTests(MarkdownTestCase):
|
|
|
200
206
|
[sys.executable, "-m", command, str(self.output)],
|
|
201
207
|
capture_output=True,
|
|
202
208
|
text=True,
|
|
203
|
-
env={"PYTHONPATH": str(Path(__file__).resolve().parents[1] / "src")},
|
|
209
|
+
env={**os.environ, "PYTHONPATH": str(Path(__file__).resolve().parents[1] / "src")},
|
|
204
210
|
)
|
|
205
211
|
self.assertNotEqual(result.returncode, 0, command)
|
|
206
212
|
self.assertIn("Markdown export", result.stderr, command)
|
|
@@ -17,9 +17,9 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
|
17
17
|
|
|
18
18
|
from flat_packager.archive import read_json_lines
|
|
19
19
|
from flat_packager.pack import (
|
|
20
|
+
_prepare_source,
|
|
20
21
|
build_archive,
|
|
21
22
|
is_excluded,
|
|
22
|
-
prepare_source,
|
|
23
23
|
repo_name_from_source,
|
|
24
24
|
safe_relative_path,
|
|
25
25
|
)
|
|
@@ -62,6 +62,8 @@ def pack(root: Path, archive: Path, **kwargs) -> tuple[int, int]:
|
|
|
62
62
|
"include_git": False,
|
|
63
63
|
"exclude_patterns": [],
|
|
64
64
|
"max_file_bytes": None,
|
|
65
|
+
"text_encoding": "base64",
|
|
66
|
+
"respect_gitignore": False,
|
|
65
67
|
}
|
|
66
68
|
options.update(kwargs)
|
|
67
69
|
return build_archive(root=root, output_path=archive, **options)
|
|
@@ -272,7 +274,7 @@ class RemoteRootNameTests(unittest.TestCase):
|
|
|
272
274
|
def test_remote_clone_directory_uses_repo_name(self) -> None:
|
|
273
275
|
with patch("flat_packager.pack.subprocess.run") as run:
|
|
274
276
|
run.return_value = subprocess.CompletedProcess(args=[], returncode=0)
|
|
275
|
-
clone_path, temp_dir =
|
|
277
|
+
clone_path, temp_dir = _prepare_source("owner/widgets")
|
|
276
278
|
self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True)
|
|
277
279
|
self.assertEqual(clone_path.name, "widgets")
|
|
278
280
|
self.assertEqual(run.call_args.args[0][-1], str(Path(temp_dir) / "widgets"))
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""The stable public surface of the flat_packager package."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
import tempfile
|
|
7
|
+
import unittest
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
11
|
+
|
|
12
|
+
import flat_packager
|
|
13
|
+
|
|
14
|
+
STABLE_NAMES = {
|
|
15
|
+
"ArchiveManifest",
|
|
16
|
+
"__version__",
|
|
17
|
+
"build_archive",
|
|
18
|
+
"inspect_data",
|
|
19
|
+
"restore_archive",
|
|
20
|
+
}
|
|
21
|
+
DEPRECATED_INTERNAL_NAMES = ("prepare_source", "process_archive", "load_and_validate_archive")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class PublicApiTests(unittest.TestCase):
|
|
25
|
+
def test_all_is_the_stable_surface(self) -> None:
|
|
26
|
+
self.assertEqual(set(flat_packager.__all__), STABLE_NAMES)
|
|
27
|
+
for name in flat_packager.__all__:
|
|
28
|
+
self.assertTrue(hasattr(flat_packager, name), msg=name)
|
|
29
|
+
|
|
30
|
+
def test_old_internal_names_warn(self) -> None:
|
|
31
|
+
for name in DEPRECATED_INTERNAL_NAMES:
|
|
32
|
+
with self.subTest(name=name):
|
|
33
|
+
with self.assertWarnsRegex(
|
|
34
|
+
DeprecationWarning, rf"flat_packager\.{name} is internal"
|
|
35
|
+
):
|
|
36
|
+
function = getattr(flat_packager, name)
|
|
37
|
+
self.assertTrue(callable(function))
|
|
38
|
+
|
|
39
|
+
def test_unknown_attribute_raises(self) -> None:
|
|
40
|
+
with self.assertRaises(AttributeError):
|
|
41
|
+
flat_packager.does_not_exist # noqa: B018
|
|
42
|
+
|
|
43
|
+
def test_inspect_data_loads_archive_when_no_manifest(self) -> None:
|
|
44
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
45
|
+
source = Path(tmp) / "source"
|
|
46
|
+
source.mkdir()
|
|
47
|
+
(source / "a.txt").write_text("hello\n", encoding="utf-8")
|
|
48
|
+
archive = Path(tmp) / "out.flat.txt"
|
|
49
|
+
flat_packager.build_archive(
|
|
50
|
+
root=source,
|
|
51
|
+
output_path=archive,
|
|
52
|
+
source_label="source",
|
|
53
|
+
tracked_only=False,
|
|
54
|
+
include_git=False,
|
|
55
|
+
exclude_patterns=[],
|
|
56
|
+
max_file_bytes=None,
|
|
57
|
+
text_encoding="auto",
|
|
58
|
+
respect_gitignore=False,
|
|
59
|
+
)
|
|
60
|
+
data = flat_packager.inspect_data(archive)
|
|
61
|
+
self.assertEqual(data["files"], 1)
|
|
62
|
+
self.assertEqual(data["version"], 2)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
unittest.main()
|
|
@@ -16,8 +16,8 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
|
16
16
|
|
|
17
17
|
from flat_packager.archive import ARCHIVE_KIND, emit_json_line, read_json_lines
|
|
18
18
|
from flat_packager.inspect import inspect_data
|
|
19
|
-
from flat_packager.pack import
|
|
20
|
-
from flat_packager.unpack import
|
|
19
|
+
from flat_packager.pack import _prepare_source, build_archive
|
|
20
|
+
from flat_packager.unpack import _load_and_validate_archive, restore_archive
|
|
21
21
|
from flat_packager.unpack import main as unpack_main
|
|
22
22
|
|
|
23
23
|
|
|
@@ -90,6 +90,8 @@ class RoundTripTests(unittest.TestCase):
|
|
|
90
90
|
include_git=False,
|
|
91
91
|
exclude_patterns=[],
|
|
92
92
|
max_file_bytes=None,
|
|
93
|
+
text_encoding="base64",
|
|
94
|
+
respect_gitignore=False,
|
|
93
95
|
)
|
|
94
96
|
|
|
95
97
|
restored_entries, restored_files = restore_archive(
|
|
@@ -127,6 +129,8 @@ class RoundTripTests(unittest.TestCase):
|
|
|
127
129
|
exclude_patterns=[],
|
|
128
130
|
max_file_bytes=None,
|
|
129
131
|
chunk_size=4,
|
|
132
|
+
text_encoding="base64",
|
|
133
|
+
respect_gitignore=False,
|
|
130
134
|
)
|
|
131
135
|
|
|
132
136
|
records = [record for _line, record in read_json_lines(archive)]
|
|
@@ -164,9 +168,11 @@ class RoundTripTests(unittest.TestCase):
|
|
|
164
168
|
max_file_bytes=None,
|
|
165
169
|
chunk_size=3,
|
|
166
170
|
compression="gzip",
|
|
171
|
+
text_encoding="base64",
|
|
172
|
+
respect_gitignore=False,
|
|
167
173
|
)
|
|
168
174
|
|
|
169
|
-
manifest =
|
|
175
|
+
manifest = _load_and_validate_archive(archive)
|
|
170
176
|
data = inspect_data(archive, manifest)
|
|
171
177
|
self.assertEqual(data["compression"], "gzip")
|
|
172
178
|
self.assertEqual(data["version"], 2)
|
|
@@ -198,6 +204,8 @@ class RoundTripTests(unittest.TestCase):
|
|
|
198
204
|
include_git=False,
|
|
199
205
|
exclude_patterns=[],
|
|
200
206
|
max_file_bytes=None,
|
|
207
|
+
text_encoding="base64",
|
|
208
|
+
respect_gitignore=False,
|
|
201
209
|
)
|
|
202
210
|
|
|
203
211
|
entries, files = restore_archive(
|
|
@@ -496,7 +504,7 @@ class RoundTripTests(unittest.TestCase):
|
|
|
496
504
|
)
|
|
497
505
|
|
|
498
506
|
with self.assertRaisesRegex(ValueError, "line 2: x.txt: content is not valid UTF-8"):
|
|
499
|
-
|
|
507
|
+
_load_and_validate_archive(archive)
|
|
500
508
|
|
|
501
509
|
def test_non_empty_output_without_overwrite_raises_file_exists_error(self) -> None:
|
|
502
510
|
source = self.work_dir / "source"
|
|
@@ -515,6 +523,8 @@ class RoundTripTests(unittest.TestCase):
|
|
|
515
523
|
include_git=False,
|
|
516
524
|
exclude_patterns=[],
|
|
517
525
|
max_file_bytes=None,
|
|
526
|
+
text_encoding="base64",
|
|
527
|
+
respect_gitignore=False,
|
|
518
528
|
)
|
|
519
529
|
|
|
520
530
|
with self.assertRaisesRegex(FileExistsError, "not empty"):
|
|
@@ -545,6 +555,8 @@ class RoundTripTests(unittest.TestCase):
|
|
|
545
555
|
include_git=False,
|
|
546
556
|
exclude_patterns=[],
|
|
547
557
|
max_file_bytes=None,
|
|
558
|
+
text_encoding="base64",
|
|
559
|
+
respect_gitignore=False,
|
|
548
560
|
)
|
|
549
561
|
|
|
550
562
|
with patch.object(sys, "argv", ["flat-unpack", str(archive), str(output)]):
|
|
@@ -574,6 +586,8 @@ class RoundTripTests(unittest.TestCase):
|
|
|
574
586
|
include_git=False,
|
|
575
587
|
exclude_patterns=[],
|
|
576
588
|
max_file_bytes=None,
|
|
589
|
+
text_encoding="base64",
|
|
590
|
+
respect_gitignore=False,
|
|
577
591
|
)
|
|
578
592
|
|
|
579
593
|
restore_archive(
|
|
@@ -647,6 +661,7 @@ class RoundTripTests(unittest.TestCase):
|
|
|
647
661
|
exclude_patterns=[],
|
|
648
662
|
max_file_bytes=None,
|
|
649
663
|
text_encoding="auto",
|
|
664
|
+
respect_gitignore=False,
|
|
650
665
|
)
|
|
651
666
|
|
|
652
667
|
archive_text = archive.read_text(encoding="utf-8")
|
|
@@ -670,7 +685,7 @@ class RoundTripTests(unittest.TestCase):
|
|
|
670
685
|
def test_remote_clone_options_are_passed_to_git(self) -> None:
|
|
671
686
|
with patch("flat_packager.pack.subprocess.run") as run:
|
|
672
687
|
run.return_value = subprocess.CompletedProcess(args=[], returncode=0)
|
|
673
|
-
_clone_path, temp_dir =
|
|
688
|
+
_clone_path, temp_dir = _prepare_source(
|
|
674
689
|
"owner/repo",
|
|
675
690
|
branch="release",
|
|
676
691
|
recurse_submodules=True,
|
|
@@ -7,7 +7,6 @@ from pathlib import Path
|
|
|
7
7
|
|
|
8
8
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
9
9
|
|
|
10
|
-
import flat_packager
|
|
11
10
|
from flat_packager import __version__
|
|
12
11
|
|
|
13
12
|
|
|
@@ -23,21 +22,6 @@ class VersionTests(unittest.TestCase):
|
|
|
23
22
|
return
|
|
24
23
|
self.fail("version not found in pyproject.toml")
|
|
25
24
|
|
|
26
|
-
def test_public_api_exports(self) -> None:
|
|
27
|
-
expected = {
|
|
28
|
-
"ArchiveManifest",
|
|
29
|
-
"__version__",
|
|
30
|
-
"build_archive",
|
|
31
|
-
"inspect_data",
|
|
32
|
-
"load_and_validate_archive",
|
|
33
|
-
"prepare_source",
|
|
34
|
-
"process_archive",
|
|
35
|
-
"restore_archive",
|
|
36
|
-
}
|
|
37
|
-
self.assertEqual(set(flat_packager.__all__), expected)
|
|
38
|
-
for name in flat_packager.__all__:
|
|
39
|
-
self.assertTrue(hasattr(flat_packager, name), msg=name)
|
|
40
|
-
|
|
41
25
|
def test_installed_metadata_matches_module_version(self) -> None:
|
|
42
26
|
try:
|
|
43
27
|
installed = version("flat-packager")
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"""Pack and restore repositories through a single flat text archive."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from flat_packager.inspect import inspect_data
|
|
6
|
-
from flat_packager.pack import build_archive, prepare_source
|
|
7
|
-
from flat_packager.unpack import (
|
|
8
|
-
ArchiveManifest,
|
|
9
|
-
load_and_validate_archive,
|
|
10
|
-
process_archive,
|
|
11
|
-
restore_archive,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
__version__ = "0.5.2"
|
|
15
|
-
|
|
16
|
-
__all__ = [
|
|
17
|
-
"ArchiveManifest",
|
|
18
|
-
"__version__",
|
|
19
|
-
"build_archive",
|
|
20
|
-
"inspect_data",
|
|
21
|
-
"load_and_validate_archive",
|
|
22
|
-
"prepare_source",
|
|
23
|
-
"process_archive",
|
|
24
|
-
"restore_archive",
|
|
25
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|