flat-packager 0.4.2__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. flat_packager-0.5.0/PKG-INFO +404 -0
  2. flat_packager-0.5.0/README.md +369 -0
  3. {flat_packager-0.4.2 → flat_packager-0.5.0}/pyproject.toml +15 -1
  4. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager/__init__.py +1 -1
  5. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager/archive.py +15 -4
  6. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager/content.py +0 -1
  7. flat_packager-0.5.0/src/flat_packager/markdown.py +391 -0
  8. flat_packager-0.5.0/src/flat_packager/pack.py +1205 -0
  9. flat_packager-0.5.0/src/flat_packager/patterns.py +194 -0
  10. flat_packager-0.5.0/src/flat_packager/secret_files.py +39 -0
  11. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager/unpack.py +11 -6
  12. flat_packager-0.5.0/src/flat_packager.egg-info/PKG-INFO +404 -0
  13. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager.egg-info/SOURCES.txt +6 -0
  14. flat_packager-0.5.0/src/flat_packager.egg-info/requires.txt +9 -0
  15. flat_packager-0.5.0/tests/test_markdown.py +253 -0
  16. flat_packager-0.5.0/tests/test_pack.py +1015 -0
  17. flat_packager-0.5.0/tests/test_restore_fuzz.py +198 -0
  18. {flat_packager-0.4.2 → flat_packager-0.5.0}/tests/test_roundtrip.py +45 -2
  19. {flat_packager-0.4.2 → flat_packager-0.5.0}/tests/test_version.py +0 -1
  20. flat_packager-0.4.2/PKG-INFO +0 -276
  21. flat_packager-0.4.2/README.md +0 -245
  22. flat_packager-0.4.2/src/flat_packager/pack.py +0 -568
  23. flat_packager-0.4.2/src/flat_packager.egg-info/PKG-INFO +0 -276
  24. flat_packager-0.4.2/src/flat_packager.egg-info/requires.txt +0 -4
  25. {flat_packager-0.4.2 → flat_packager-0.5.0}/LICENSE +0 -0
  26. {flat_packager-0.4.2 → flat_packager-0.5.0}/setup.cfg +0 -0
  27. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager/inspect.py +0 -0
  28. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager/text_encoding.py +0 -0
  29. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager/verify.py +0 -0
  30. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager.egg-info/dependency_links.txt +0 -0
  31. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager.egg-info/entry_points.txt +0 -0
  32. {flat_packager-0.4.2 → flat_packager-0.5.0}/src/flat_packager.egg-info/top_level.txt +0 -0
@@ -0,0 +1,404 @@
1
+ Metadata-Version: 2.4
2
+ Name: flat-packager
3
+ Version: 0.5.0
4
+ Summary: Pack a repository into one flat text archive and restore it later.
5
+ Author: Thomas
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/tomanizer/flat-packager
8
+ Project-URL: Repository, https://github.com/tomanizer/flat-packager
9
+ Project-URL: Documentation, https://github.com/tomanizer/flat-packager#readme
10
+ Project-URL: Changelog, https://github.com/tomanizer/flat-packager/blob/main/CHANGELOG.md
11
+ Keywords: archive,repository,github,packaging,restore
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Version Control :: Git
23
+ Classifier: Topic :: System :: Archiving
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Provides-Extra: test
28
+ Requires-Dist: hypothesis>=6.100; extra == "test"
29
+ Requires-Dist: coverage[toml]>=7.4; extra == "test"
30
+ Provides-Extra: dev
31
+ Requires-Dist: build>=1.2; extra == "dev"
32
+ Requires-Dist: twine>=5.0; extra == "dev"
33
+ Requires-Dist: flat-packager[test]; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # Flat Packager
37
+
38
+ Flat Packager turns a repository into one flat text archive, then rebuilds the
39
+ original folder structure from that archive.
40
+
41
+ The default archive format is newline-delimited JSON. Text files up to 4 MiB
42
+ are stored inline as readable UTF-8, and other files as chunked base64. Text
43
+ files, binary files, empty directories, and symlinks survive the round trip
44
+ byte for byte. Restores validate archive paths, duplicate entries, symlink
45
+ ancestry, chunk ordering, and recorded SHA-256 hashes before writing file
46
+ contents.
47
+
48
+ ## Install
49
+
50
+ From PyPI:
51
+
52
+ ```bash
53
+ python3 -m pip install flat-packager
54
+ ```
55
+
56
+ From a checkout:
57
+
58
+ ```bash
59
+ python3 -m pip install .
60
+ ```
61
+
62
+ For development:
63
+
64
+ ```bash
65
+ python3 -m pip install -e ".[dev]"
66
+ make test
67
+ ```
68
+
69
+ This installs four console commands:
70
+
71
+ ```bash
72
+ flat-pack --help
73
+ flat-unpack --help
74
+ flat-inspect --help
75
+ flat-verify --help
76
+ ```
77
+
78
+ The repository also keeps compatibility wrappers:
79
+
80
+ ```bash
81
+ python3 pack_repo.py --help
82
+ python3 unpack_repo.py --help
83
+ ```
84
+
85
+ ## Upgrading from 0.4
86
+
87
+ 0.5.0 changes some `flat-pack` defaults, so the same command can produce a
88
+ different archive than before:
89
+
90
+ | Change | To get the 0.4 behaviour |
91
+ |---|---|
92
+ | Files ignored by git (`.gitignore`, `.git/info/exclude`) are skipped | `--no-gitignore` |
93
+ | Known text files are stored as readable UTF-8, which `flat-unpack` older than 0.4.1 cannot restore | `--text-encoding base64` |
94
+ | `--exclude` uses gitignore-style patterns: `name` matches at any depth, `*` no longer crosses `/` (use `**`) | Anchor patterns with a leading `/` or use `**` |
95
+ | Nested `.git` directories and submodule `.git` files are skipped | `--include-git` |
96
+
97
+ Restoring is unchanged: `flat-unpack` 0.5.0 restores archives made by any
98
+ earlier version. The Python API (`build_archive()`) keeps the 0.4 defaults for
99
+ text encoding (`base64`) and `.gitignore` (not respected), but uses the new
100
+ exclude matching. See [CHANGELOG.md](CHANGELOG.md) for the full list.
101
+
102
+ ## Pack a Repository
103
+
104
+ Pack a local repository:
105
+
106
+ ```bash
107
+ flat-pack /path/to/repo repo.flat.txt
108
+ ```
109
+
110
+ Pack a public GitHub repository by shorthand or Git URL:
111
+
112
+ ```bash
113
+ flat-pack owner/repo repo.flat.txt
114
+ flat-pack https://github.com/owner/repo.git repo.flat.txt
115
+ ```
116
+
117
+ Remote repositories are cloned with `--depth 1` by default. You can select a
118
+ branch or tag, include submodules, or request a full clone:
119
+
120
+ ```bash
121
+ flat-pack owner/repo repo.flat.txt --branch main
122
+ flat-pack owner/repo repo.flat.txt --recurse-submodules
123
+ flat-pack owner/repo repo.flat.txt --no-shallow
124
+ ```
125
+
126
+ By default, `flat-pack` packs every file and directory under the source except
127
+ git metadata: any `.git` directory, and the `.git` pointer files of submodules
128
+ and worktrees (`--include-git` keeps them). When the source is a git working
129
+ tree, it also skips everything git ignores (`.gitignore`, `.git/info/exclude`
130
+ and your global excludes, plus the ignore rules of checked-out submodules), the
131
+ same files `git status` hides. Tracked files are always included, even if they match
132
+ an ignore rule. This only applies when the source is the top level of a
133
+ repository, or a directory with files tracked in it. A plain directory that
134
+ happens to sit inside another repository, such as a home-directory dotfiles
135
+ repo, is packed in full, with a warning. To pack ignored files as well:
136
+
137
+ ```bash
138
+ flat-pack /path/to/repo repo.flat.txt --no-gitignore
139
+ ```
140
+
141
+ `flat-pack` warns on stderr when it packs a file that commonly holds
142
+ credentials, such as `.env`, `.env.*`, `*.pem`, `*.key`, `id_rsa*`, `.npmrc`,
143
+ `.pypirc`, `.netrc` or `credentials*.json`. Templates (`.env.example`) and
144
+ public keys (`*.pub`) don't trigger the warning. Use `--fail-on-secrets`, for
145
+ example in CI, to make this an error. If packing fails, the partially written
146
+ archive is removed.
147
+
148
+ To include only tracked git files:
149
+
150
+ ```bash
151
+ flat-pack /path/to/repo repo.flat.txt --tracked-only
152
+ ```
153
+
154
+ With `--tracked-only`, files of checked-out submodules are included. Tracked
155
+ files deleted from the working tree, and submodules that are not checked out,
156
+ are skipped with a warning.
157
+
158
+ Useful options:
159
+
160
+ ```bash
161
+ flat-pack /path/to/repo repo.flat.txt --exclude node_modules
162
+ flat-pack /path/to/repo repo.flat.txt --max-file-bytes 10485760
163
+ flat-pack /path/to/repo repo.flat.txt --include-git
164
+ flat-pack /path/to/repo repo.flat.txt --text-encoding base64
165
+ ```
166
+
167
+ `--exclude` patterns use gitignore-style matching against repo-relative paths:
168
+
169
+ - A pattern without `/` matches at any depth: `node_modules` or `*.pyc`.
170
+ - A pattern with `/` is anchored to the repo root: `docs/build` or `/dist`.
171
+ - `*` and `?` do not cross `/`, and `**` matches any number of directories,
172
+ as in `src/**/*.gen.py` or `**/fixtures`.
173
+ - Excluding a directory excludes everything inside it. A trailing `/` is
174
+ allowed and ignored.
175
+
176
+ To pack only part of a repository, use `--subdir` for one directory and
177
+ `--include` for globs, which use the same syntax as `--exclude`. They can be
178
+ combined. Archive paths stay relative to the repository root, so a restore
179
+ recreates the familiar layout:
180
+
181
+ ```bash
182
+ flat-pack /path/to/repo src.flat.txt --subdir src/mypkg
183
+ flat-pack owner/repo py.flat.txt --include "**/*.py" --include README.md
184
+ flat-pack /path/to/repo docs.flat.txt --subdir docs --include "*.md" --exclude drafts
185
+ ```
186
+
187
+ An `--include` pattern that matches a directory includes everything below it.
188
+ `--exclude` and `.gitignore` are still applied, and parent directories of
189
+ included files are recorded with their modes. Packing fails if `--include`
190
+ matches nothing, or if `--subdir` is missing, is not a directory, or is a
191
+ symlink.
192
+
193
+ Paths must be valid UTF-8. Packing fails with a clear error on other file
194
+ names, so rename or exclude them.
195
+
196
+ ## Markdown Output for Reading and LLM Context
197
+
198
+ `--output-format markdown` writes a one-way Markdown document instead of a
199
+ restorable archive. It is meant for reading the code, or for pasting it into
200
+ an LLM as context:
201
+
202
+ ```bash
203
+ flat-pack /path/to/repo repo.md --output-format markdown
204
+ flat-pack owner/repo repo.md --output-format markdown --subdir src --include "*.py"
205
+ ```
206
+
207
+ The document contains:
208
+
209
+ - a short header with the source, commit, date and file count;
210
+ - a file tree, with symlinks shown as `name -> target`;
211
+ - every readable UTF-8 text file up to 4 MiB as a heading followed by a fenced
212
+ code block. The block has a language hint, and its fence is longer than any
213
+ backtick run in the file;
214
+ - one line per binary or larger file with its size and SHA-256, but not its
215
+ contents;
216
+ - a list of paths skipped by the default excludes.
217
+
218
+ By default, Markdown output skips noise that rarely helps a reader:
219
+
220
+ - lockfiles, such as `package-lock.json`, `yarn.lock`, `poetry.lock`,
221
+ `uv.lock`, `Cargo.lock` and `go.sum`;
222
+ - dependency and build directories: `node_modules`, `vendor`, `.venv`,
223
+ `dist`, `build` and caches;
224
+ - minified files and source maps: `*.min.js`, `*.min.css` and `*.map`.
225
+
226
+ Use `--no-default-excludes` to include them. These defaults never apply to the
227
+ JSONL archive. `.gitignore`, `--exclude`, `--include`, `--subdir`,
228
+ `--tracked-only` and the secret-file warnings work the same way in both
229
+ formats.
230
+
231
+ `--format-version`, `--chunk-size` and `--text-encoding` only affect JSONL
232
+ archives. Markdown exports cannot be restored. `flat-unpack`, `flat-inspect` and
233
+ `flat-verify` reject them with a clear error.
234
+
235
+ ## Text Encoding
236
+
237
+ By default (`--text-encoding auto`), known text files such as `.py`, `.md`,
238
+ `.yaml` and `.json` that are valid UTF-8 are stored as plain UTF-8 JSON
239
+ strings, so archives are readable and diffable. Everything else, including
240
+ binaries and text files with invalid UTF-8, is stored as base64 chunks. Both
241
+ restore byte for byte.
242
+
243
+ In the archive, text files look like:
244
+
245
+ ```json
246
+ {"encoding":"utf8","path":"src/app.py","content":"def main():\n ..."}
247
+ ```
248
+
249
+ Use `--text-encoding utf8` to store any valid UTF-8 file as readable text.
250
+ Only text files up to 4 MiB are stored inline. Larger files always use base64
251
+ chunks, so packing never holds a large file in memory.
252
+
253
+ `--text-encoding base64` encodes every file as base64. Use it when the archive
254
+ will be restored with `flat-unpack` older than 0.4.1, which does not understand
255
+ UTF-8 records:
256
+
257
+ ```bash
258
+ flat-pack /path/to/repo repo.flat.txt --text-encoding base64
259
+ ```
260
+
261
+ ## Format and Compression
262
+
263
+ New archives use format version 2 by default. Version 2 stores binary and
264
+ large files as metadata plus base64 chunk records. Small text files may be
265
+ stored inline as UTF-8. This keeps memory use bounded while packing and
266
+ restoring large files. The full format is specified in
267
+ [docs/FORMAT.md](docs/FORMAT.md). Each source file is read
268
+ once. If a file changes while it is being packed, `flat-pack` stops with a
269
+ clear error instead of writing an inconsistent archive.
270
+
271
+ ```bash
272
+ flat-pack /path/to/repo repo.flat.txt --chunk-size 1048576
273
+ ```
274
+
275
+ To write the legacy inline format:
276
+
277
+ ```bash
278
+ flat-pack /path/to/repo repo.v1.flat.txt --format-version 1
279
+ ```
280
+
281
+ To gzip-compress an archive:
282
+
283
+ ```bash
284
+ flat-pack /path/to/repo repo.flat.txt.gz --compress gzip
285
+ ```
286
+
287
+ `--compress auto` is the default and writes gzip when the output path ends in
288
+ `.gz`. Restore, inspect, and verify commands auto-detect gzip archives.
289
+
290
+ ## Restore a Repository
291
+
292
+ ```bash
293
+ flat-unpack repo.flat.txt restored-repo
294
+ ```
295
+
296
+ If the output directory already contains files:
297
+
298
+ ```bash
299
+ flat-unpack repo.flat.txt restored-repo --overwrite
300
+ ```
301
+
302
+ Restores are staged in a temporary sibling directory and moved into place only
303
+ after the full archive validates and writes successfully. If validation fails,
304
+ the existing output directory is left unchanged.
305
+
306
+ Validate an archive without writing files:
307
+
308
+ ```bash
309
+ flat-unpack repo.flat.txt restored-repo --verify-only
310
+ ```
311
+
312
+ You can also validate without naming an output directory:
313
+
314
+ ```bash
315
+ flat-verify repo.flat.txt
316
+ ```
317
+
318
+ On systems where symlink creation is unavailable:
319
+
320
+ ```bash
321
+ flat-unpack repo.flat.txt restored-repo --no-symlinks
322
+ ```
323
+
324
+ ## Inspect an Archive
325
+
326
+ ```bash
327
+ flat-inspect repo.flat.txt
328
+ flat-inspect repo.flat.txt --json
329
+ flat-inspect repo.flat.txt --limit 20
330
+ ```
331
+
332
+ Inspection validates the archive first, then reports version, compression,
333
+ source metadata, entry counts, total file bytes, chunk count, largest files, and
334
+ symlinks.
335
+
336
+ ## Safety Model
337
+
338
+ Flat Packager is intended for moving repository snapshots, not for executing or
339
+ trusting their contents. Treat archives from untrusted sources the same way you
340
+ would treat a zip file from an untrusted source.
341
+
342
+ The restore step rejects:
343
+
344
+ - absolute archive paths
345
+ - `..`, `.`, empty, or backslash path segments
346
+ - duplicate archive paths
347
+ - file or directory records nested underneath an archived symlink or file,
348
+ checked before anything is written for that record
349
+ - a symlink or file that would replace a directory other entries live in
350
+ - chunk records that are missing, out of order, corrupt, or attached to the
351
+ wrong file
352
+ - corrupt base64, size, or SHA-256 data
353
+
354
+ As a second layer, restores create directories one component at a time without
355
+ following symlinks and create files exclusively (`O_EXCL`/`O_NOFOLLOW`). Writes
356
+ therefore cannot be routed outside the output directory, including through
357
+ names that collide on case-insensitive filesystems such as default macOS.
358
+
359
+ [docs/FORMAT.md](docs/FORMAT.md#7-validation-performed-on-restore) lists
360
+ every validation rule.
361
+
362
+ Setuid, setgid, and sticky mode bits are stripped on restore. Pass
363
+ `--preserve-special-bits` to keep them for archives you trust.
364
+
365
+ Restored symlinks may still point outside the restored repository, because that
366
+ is valid repository content. Use `--no-symlinks` if you want symlink targets
367
+ written as text files instead.
368
+
369
+ ## Limitations
370
+
371
+ - Binary files, and any file with `--text-encoding base64`, are base64
372
+ encoded, so they take about a third more space than the raw bytes. Use gzip
373
+ compression when archive size matters.
374
+ - Legacy format version 1 stores each file as one JSON record and is
375
+ memory-heavy for large files. Version 2 is chunked and is the default.
376
+ - Remote GitHub packing depends on local `git` and whatever authentication your
377
+ git installation already has configured.
378
+ - Git LFS files are captured as whatever exists in the cloned checkout. If LFS
379
+ smudge is disabled or unavailable, pointer files may be archived instead of
380
+ large objects.
381
+ - This stores file bytes, directory modes, file modes, and symlink targets. It
382
+ does not preserve owners, groups, extended attributes, ACLs, hard links,
383
+ timestamps, git history, or ignored remote refs.
384
+
385
+ ## Test
386
+
387
+ ```bash
388
+ python3 -m unittest discover -s tests
389
+ ```
390
+
391
+ Build a wheel:
392
+
393
+ ```bash
394
+ python3 -m pip install ".[dev]"
395
+ python3 -m build
396
+ ```
397
+
398
+ ## Release
399
+
400
+ See [CHANGELOG.md](CHANGELOG.md) and [docs/RELEASING.md](docs/RELEASING.md).
401
+
402
+ ```bash
403
+ make release-check
404
+ ```