(
tmpdir, # type: Any
compress, # type: bool
)
| 252 | ], |
| 253 | ) |
| 254 | def test_pex_builder_packed( |
| 255 | tmpdir, # type: Any |
| 256 | compress, # type: bool |
| 257 | ): |
| 258 | # type: (...) -> None |
| 259 | |
| 260 | pex_root = os.path.join(str(tmpdir), "pex_root") |
| 261 | pex_app = os.path.join(str(tmpdir), "app.pex") |
| 262 | source_file = os.path.join(str(tmpdir), "src") |
| 263 | touch(source_file) |
| 264 | |
| 265 | with ENV.patch(PEX_ROOT=pex_root), make_bdist(name="my_project") as dist: |
| 266 | pb = PEXBuilder(copy_mode=CopyMode.SYMLINK) |
| 267 | pb.add_source(source_file, "a.file") |
| 268 | pb.add_dist_location(dist.location) |
| 269 | pb.set_script("shell_script") |
| 270 | pb.build(pex_app, layout=Layout.PACKED, compress=compress) |
| 271 | |
| 272 | assert "hello world from shell script\n" == subprocess.check_output( |
| 273 | args=[os.path.join(pex_app, "__main__.py")] |
| 274 | ).decode("utf-8") |
| 275 | |
| 276 | spread_dist_bootstrap = os.path.join(pex_app, pb.info.bootstrap) |
| 277 | assert zipfile.is_zipfile(spread_dist_bootstrap) |
| 278 | |
| 279 | cached_bootstrap_zip = CacheDir.BOOTSTRAP_ZIPS.path( |
| 280 | pb.info.bootstrap_hash, "defN" if compress else "stor", pb.info.bootstrap, pex_root=pex_root |
| 281 | ) |
| 282 | assert zipfile.is_zipfile(cached_bootstrap_zip) |
| 283 | |
| 284 | assert filecmp.cmp(spread_dist_bootstrap, cached_bootstrap_zip, shallow=False) |
| 285 | |
| 286 | assert os.path.isfile(os.path.join(pex_app, "a.file")) |
| 287 | for root, dirs, files in os.walk(pex_app, followlinks=False): |
| 288 | for f in files: |
| 289 | path = os.path.join(root, f) |
| 290 | assert not os.path.islink(path) or pex_app == safe_commonpath( |
| 291 | [pex_app, os.path.realpath(path)] |
| 292 | ), ( |
| 293 | "All packed layout files should be real files inside the packed layout root that " |
| 294 | "are divorced from either the PEXBuilder chroot or PEX_ROOT caches." |
| 295 | ) |
| 296 | |
| 297 | assert 1 == len(pb.info.distributions) |
| 298 | location, sha = next(iter(pb.info.distributions.items())) |
| 299 | |
| 300 | spread_dist_zip = os.path.join(pex_app, pb.info.internal_cache, location) |
| 301 | assert zipfile.is_zipfile(spread_dist_zip) |
| 302 | |
| 303 | cached_dist_zip = CacheDir.PACKED_WHEELS.path( |
| 304 | sha, "defN" if compress else "stor", location, pex_root=pex_root |
| 305 | ) |
| 306 | assert zipfile.is_zipfile(cached_dist_zip) |
| 307 | |
| 308 | assert filecmp.cmp(spread_dist_zip, cached_dist_zip, shallow=False) |
| 309 | |
| 310 | |
| 311 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected