From e42fe69f651f0d79721924c33d75b960eae9f8fd Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Sat, 3 Feb 2024 14:49:48 -0600 Subject: [PATCH 1/3] Add support for ContextDir to DirPathCalc (#87) --- src/anchovy/paths.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/anchovy/paths.py b/src/anchovy/paths.py index 706fbf2..01b64b6 100644 --- a/src/anchovy/paths.py +++ b/src/anchovy/paths.py @@ -6,6 +6,7 @@ from pathlib import Path from .core import Context, ContextDir, Matcher, PathCalc +from .custody import CONTEXT_DIR_KEYS T = t.TypeVar('T') @@ -51,13 +52,20 @@ class DirPathCalc(PathCalc[T]): extension information for the input paths, allowing for meaningful work with extensions that `pathlib.Path` does not reflect, like `.tar.gz`. """ - def __init__(self, dest: Path, ext: str | None = None, transform: t.Callable[[Path], Path] | None = None): + def __init__(self, + dest: Path | ContextDir, + ext: str | None = None, + transform: t.Callable[[Path], Path] | None = None): self.dest = dest self.ext = ext self.transform = transform def __call__(self, context: Context, path: Path, match: T) -> Path: - return _to_dir_inner(self.dest, self.ext, context, path, match, self.transform) + if self.dest in CONTEXT_DIR_KEYS: + dest = context[self.dest] + else: + dest = Path(self.dest) + return _to_dir_inner(dest, self.ext, context, path, match, self.transform) class OutputDirPathCalc(PathCalc[T]): From 1310d0d75b731317e6093a2659cb9817f779ee27 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Sat, 3 Feb 2024 14:51:19 -0600 Subject: [PATCH 2/3] Make OutputDirPathCalc and WorkingDirPathCalc subclasses of DirPathCalc (#87) --- src/anchovy/paths.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/anchovy/paths.py b/src/anchovy/paths.py index 01b64b6..6174a29 100644 --- a/src/anchovy/paths.py +++ b/src/anchovy/paths.py @@ -68,7 +68,7 @@ def __call__(self, context: Context, path: Path, match: T) -> Path: return _to_dir_inner(dest, self.ext, context, path, match, self.transform) -class OutputDirPathCalc(PathCalc[T]): +class OutputDirPathCalc(DirPathCalc[T]): """ PathCalc which makes its input paths children of the Context's output directory. If @ext is specified, it will replace the extension of input @@ -77,15 +77,13 @@ class OutputDirPathCalc(PathCalc[T]): meaningful work with extensions that `pathlib.Path` does not reflect, like `.tar.gz`. """ - def __init__(self, ext: str | None = None, transform: t.Callable[[Path], Path] | None = None): - self.ext = ext - self.transform = transform - - def __call__(self, context: Context, path: Path, match: T) -> Path: - return _to_dir_inner(context['output_dir'], self.ext, context, path, match, self.transform) + def __init__(self, + ext: str | None = None, + transform: t.Callable[[Path], Path] | None = None): + super().__init__('output_dir', ext, transform) -class WorkingDirPathCalc(PathCalc[T]): +class WorkingDirPathCalc(DirPathCalc[T]): """ PathCalc which makes its input paths children of the Context's working directory. If @ext is specified, it will replace the extension of input @@ -94,12 +92,11 @@ class WorkingDirPathCalc(PathCalc[T]): meaningful work with extensions that `pathlib.Path` does not reflect, like `.tar.gz`. """ - def __init__(self, ext: str | None = None, transform: t.Callable[[Path], Path] | None = None): - self.ext = ext - self.transform = transform + def __init__(self, + ext: str | None = None, + transform: t.Callable[[Path], Path] | None = None): + super().__init__('working_dir', ext, transform) - def __call__(self, context: Context, path: Path, match: T) -> Path: - return _to_dir_inner(context['working_dir'], self.ext, context, path, match, self.transform) class REMatcher(Matcher[re.Match | None]): From d18127d4344a55bbaae0d72663448962aa1f92ed Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Sat, 3 Feb 2024 15:29:35 -0600 Subject: [PATCH 3/3] Update test artifacts to match lightningcss 0.2.0 --- test/artifacts/basic_site.json | 16 +++++++------- test/artifacts/code_index.json | 38 +++++++++++++++++----------------- test/artifacts/gallery.json | 26 +++++++++++------------ test/test_examples.py | 2 ++ 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/test/artifacts/basic_site.json b/test/artifacts/basic_site.json index a2b47f2..8f42075 100644 --- a/test/artifacts/basic_site.json +++ b/test/artifacts/basic_site.json @@ -54,7 +54,7 @@ "path", { "sha1": "1658ebaece18a76250c123fdeac8e6ad38b3d795", - "m_time": 1703199125.7663765, + "m_time": 1706995610.3326533, "size": 506 } ], @@ -62,7 +62,7 @@ "path", { "sha1": "2d329383d6bafbbd203c0fd3d90cfcfb675db587", - "m_time": 1703197638.1800685, + "m_time": 1703960959.0897603, "size": 267 } ], @@ -78,7 +78,7 @@ "path", { "sha1": "013e15a825ed0690e6cd9ad479f4185566d020f8", - "m_time": 1703199125.7738748, + "m_time": 1706995610.3371997, "size": 276 } ], @@ -94,7 +94,7 @@ "path", { "sha1": "203990dbc21656099ebf8e06339897ff59b1e569", - "m_time": 1703199125.7778723, + "m_time": 1706995610.3462749, "size": 890709 } ], @@ -110,7 +110,7 @@ "path", { "sha1": "9548f6b06d5a74ecc70a02ec1d6ee024396dc912", - "m_time": 1703199125.7903874, + "m_time": 1706995610.3808444, "size": 706821 } ], @@ -126,7 +126,7 @@ "path", { "sha1": "3b94e6a05cfb68faf1d4e15f82760ec306990295", - "m_time": 1703199125.8130672, + "m_time": 1706995610.4031894, "size": 679302 } ], @@ -142,7 +142,7 @@ "path", { "sha1": "d2b3364f1f5be5153295518a5b1ee61bd52cffe3", - "m_time": 1703199125.821573, + "m_time": 1706995610.4122894, "size": 482152 } ], @@ -158,7 +158,7 @@ "path", { "sha1": "23e6ad2efc9cb2ec65a010b43032f7569afab574", - "m_time": 1703199125.83395, + "m_time": 1706995610.4249547, "size": 447542 } ], diff --git a/test/artifacts/code_index.json b/test/artifacts/code_index.json index 0af0040..f967278 100644 --- a/test/artifacts/code_index.json +++ b/test/artifacts/code_index.json @@ -128,7 +128,7 @@ "path", { "sha1": "", - "m_time": 1703199123.4892223, + "m_time": 1706995623.6526809, "size": 4096 } ], @@ -136,7 +136,7 @@ "path", { "sha1": "c4983436e017a238d94796250a749d74cbc76835", - "m_time": 1703199123.4882276, + "m_time": 1706995623.6526809, "size": 1071 } ], @@ -144,7 +144,7 @@ "path", { "sha1": "3cdd5e3cc41664211b63f98b94a0791282f1ea4d", - "m_time": 1703199123.4892223, + "m_time": 1706995623.6526809, "size": 1407 } ], @@ -160,7 +160,7 @@ "path", { "sha1": "c361ccf60628e76f571f8229d9c896603f7042ab", - "m_time": 1703199123.4967394, + "m_time": 1706995623.6602678, "size": 298 } ], @@ -176,7 +176,7 @@ "path", { "sha1": "23b855543fd50b49b743413cc221e1bee266c6c9", - "m_time": 1703199123.5022552, + "m_time": 1706995623.6736958, "size": 306 } ], @@ -192,7 +192,7 @@ "path", { "sha1": "16d39823b42dfc58eb0b12d04cc54c233575f398", - "m_time": 1703199123.5092297, + "m_time": 1706995623.681307, "size": 5551 } ], @@ -208,7 +208,7 @@ "path", { "sha1": "0cc6ab8a6e988e4f3ff88a30dca17f4b8087a37b", - "m_time": 1703199123.5142365, + "m_time": 1706995623.6852465, "size": 36 } ], @@ -224,7 +224,7 @@ "path", { "sha1": "bf995c9fb6202933eb3d6b433b38bae484e2f7d1", - "m_time": 1703199123.5333054, + "m_time": 1706995623.7074897, "size": 1184 } ], @@ -232,7 +232,7 @@ "path", { "sha1": "e03d87bee6bd515e50c752acae7a24cc6700aef7", - "m_time": 1703199123.536311, + "m_time": 1706995623.7105067, "size": 1514 } ], @@ -240,7 +240,7 @@ "path", { "sha1": "e653663027dfc58550559eaa9d2ba816dd94b8e0", - "m_time": 1703199123.545324, + "m_time": 1706995623.7190287, "size": 427 } ], @@ -257,7 +257,7 @@ "path", { "sha1": "5620127ab0d2261762dac0c30d1fe79e86dcac03", - "m_time": 1703199123.550546, + "m_time": 1706995623.7240794, "size": 5859 } ], @@ -265,7 +265,7 @@ "path", { "sha1": "ffe41a786d2d6e21e277aa1db53db621384aa76f", - "m_time": 1703199123.6589215, + "m_time": 1706995623.8251395, "size": 4852 } ], @@ -281,23 +281,23 @@ "path", { "sha1": "607b78c4b55e9b7598d74c7dae26847536932758", - "m_time": 1703199123.668445, + "m_time": 1706995623.8331532, "size": 6386 } ], "output_dir/static/css_pack.css": [ "path", { - "sha1": "a8253d222c06b0cf4391d9b95471bc67d4033663", - "m_time": 1703199123.6757824, - "size": 2794 + "sha1": "c363895ad4c4f75aff899690c56eef2e300980be", + "m_time": 1706995623.8389888, + "size": 2800 } ], "output_dir/index.html": [ "path", { "sha1": "239ba6c1e7802f77005bcef7ce3eae4ef59df4ae", - "m_time": 1703199123.722618, + "m_time": 1706995623.8761384, "size": 263 } ], @@ -305,7 +305,7 @@ "path", { "sha1": "f217f536a707d91b90b6d50ab94fb5e9c310a5f2", - "m_time": 1703199123.7368248, + "m_time": 1706995623.9063706, "size": 4439 } ], @@ -313,7 +313,7 @@ "path", { "sha1": "ddac506b836ee7fffaed7f1dad18967bd11acf0e", - "m_time": 1703199123.7426379, + "m_time": 1706995623.9233155, "size": 5887 } ] diff --git a/test/artifacts/gallery.json b/test/artifacts/gallery.json index 4159343..a0bb9d7 100644 --- a/test/artifacts/gallery.json +++ b/test/artifacts/gallery.json @@ -79,7 +79,7 @@ "path", { "sha1": "1d3e421721ec906bc128e4d55864d82aa6a6c75d", - "m_time": 1703199130.0382843, + "m_time": 1706995629.7952046, "size": 894 } ], @@ -87,7 +87,7 @@ "path", { "sha1": "9f27b1b3c02eb311934b91670b75223332345e46", - "m_time": 1703198391.7599504, + "m_time": 1703960959.0921924, "size": 691 } ], @@ -103,7 +103,7 @@ "path", { "sha1": "b83692b7ecefc8f7258e668b3809c698b58215ad", - "m_time": 1703199130.2335155, + "m_time": 1706995629.9750297, "size": 130280 } ], @@ -119,7 +119,7 @@ "path", { "sha1": "f68028822c70dd10050e31fd94dddd118130367c", - "m_time": 1703199130.4975874, + "m_time": 1706995630.2949483, "size": 486084 } ], @@ -135,7 +135,7 @@ "path", { "sha1": "5487a4719f9444eb3dea1def8559a01d3987646d", - "m_time": 1703199130.7683768, + "m_time": 1706995630.5707417, "size": 384794 } ], @@ -151,7 +151,7 @@ "path", { "sha1": "9d8d12085d4fe45bf991ef213d6ec9d687f1aea0", - "m_time": 1703199130.8468206, + "m_time": 1706995630.659237, "size": 112870 } ], @@ -167,7 +167,7 @@ "path", { "sha1": "ec990618526da22c865fbbbef1709e0248a6db3c", - "m_time": 1703199131.0753412, + "m_time": 1706995630.9003868, "size": 213976 } ], @@ -183,7 +183,7 @@ "path", { "sha1": "cdc071ac8c1df352d311cc5f2953323d63f1d11f", - "m_time": 1703199131.1033309, + "m_time": 1706995630.9275067, "size": 3290 } ], @@ -191,7 +191,7 @@ "path", { "sha1": "5b0050327c24463e8c40dd5f719143395f83ed6c", - "m_time": 1703199131.1213686, + "m_time": 1706995630.945872, "size": 12328 } ], @@ -199,7 +199,7 @@ "path", { "sha1": "14a1a1a9bd5efa32ea61ce0bd21ec05a76222a4f", - "m_time": 1703199131.1536572, + "m_time": 1706995630.9749384, "size": 13700 } ], @@ -207,7 +207,7 @@ "path", { "sha1": "5c778a19692593bca5ddadb2fd0c97adca38451a", - "m_time": 1703199131.1856089, + "m_time": 1706995631.001175, "size": 11854 } ], @@ -215,7 +215,7 @@ "path", { "sha1": "813bcb7b2d5e97b6d432e18a0bc531f3f3fdf166", - "m_time": 1703199131.2138624, + "m_time": 1706995631.0337472, "size": 6042 } ], @@ -223,7 +223,7 @@ "path", { "sha1": "8a1e53893dea46843e962949774273166a4608f1", - "m_time": 1703199131.2183788, + "m_time": 1706995631.0469563, "size": 526 } ], diff --git a/test/test_examples.py b/test/test_examples.py index 39e4821..b10b6f3 100644 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -79,6 +79,8 @@ def test_example_cli(name, tmp_path): old_artifact = load_artifact(old_artifact_path) # TODO: Figure out why code_index doesn't work with purge_dirs=False. + # TODO: Files don't seem to survive in the test directory after a CLI run + # other than the artifact. context = run_example_cli(EXAMPLE_PATHS[name], tmp_path, purge_dirs=True) if not (new_artifact_path := context['custody_cache']): raise RuntimeError(f'No custody artifact generated for {name}')