py-rattler 0.22.0__cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.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.
Files changed (68) hide show
  1. py_rattler-0.22.0.dist-info/METADATA +208 -0
  2. py_rattler-0.22.0.dist-info/RECORD +68 -0
  3. py_rattler-0.22.0.dist-info/WHEEL +4 -0
  4. rattler/__init__.py +114 -0
  5. rattler/channel/__init__.py +5 -0
  6. rattler/channel/channel.py +94 -0
  7. rattler/channel/channel_config.py +43 -0
  8. rattler/channel/channel_priority.py +14 -0
  9. rattler/exceptions.py +120 -0
  10. rattler/explicit_environment/__init__.py +3 -0
  11. rattler/explicit_environment/environment.py +69 -0
  12. rattler/index/__init__.py +3 -0
  13. rattler/index/index.py +112 -0
  14. rattler/install/__init__.py +3 -0
  15. rattler/install/installer.py +96 -0
  16. rattler/lock/__init__.py +23 -0
  17. rattler/lock/channel.py +52 -0
  18. rattler/lock/environment.py +213 -0
  19. rattler/lock/hash.py +33 -0
  20. rattler/lock/lock_file.py +118 -0
  21. rattler/lock/package.py +302 -0
  22. rattler/match_spec/__init__.py +4 -0
  23. rattler/match_spec/match_spec.py +294 -0
  24. rattler/match_spec/nameless_match_spec.py +185 -0
  25. rattler/networking/__init__.py +21 -0
  26. rattler/networking/client.py +74 -0
  27. rattler/networking/fetch_repo_data.py +103 -0
  28. rattler/networking/middleware.py +234 -0
  29. rattler/package/__init__.py +26 -0
  30. rattler/package/about_json.py +329 -0
  31. rattler/package/index_json.py +437 -0
  32. rattler/package/no_arch_type.py +142 -0
  33. rattler/package/package_name.py +204 -0
  34. rattler/package/package_name_matcher.py +81 -0
  35. rattler/package/paths_json.py +696 -0
  36. rattler/package/run_exports_json.py +268 -0
  37. rattler/package_streaming/__init__.py +26 -0
  38. rattler/platform/__init__.py +4 -0
  39. rattler/platform/arch.py +59 -0
  40. rattler/platform/platform.py +217 -0
  41. rattler/prefix/__init__.py +4 -0
  42. rattler/prefix/prefix_paths.py +442 -0
  43. rattler/prefix/prefix_record.py +234 -0
  44. rattler/pty/__init__.py +25 -0
  45. rattler/pty/pty_process.py +391 -0
  46. rattler/pty/pty_session.py +241 -0
  47. rattler/py.typed +0 -0
  48. rattler/rattler.abi3.so +0 -0
  49. rattler/repo_data/__init__.py +19 -0
  50. rattler/repo_data/gateway.py +337 -0
  51. rattler/repo_data/package_record.py +938 -0
  52. rattler/repo_data/patch_instructions.py +22 -0
  53. rattler/repo_data/record.py +164 -0
  54. rattler/repo_data/repo_data.py +74 -0
  55. rattler/repo_data/source.py +85 -0
  56. rattler/repo_data/sparse.py +356 -0
  57. rattler/shell/__init__.py +3 -0
  58. rattler/shell/shell.py +134 -0
  59. rattler/solver/__init__.py +3 -0
  60. rattler/solver/solver.py +220 -0
  61. rattler/utils/rattler_version.py +19 -0
  62. rattler/version/__init__.py +5 -0
  63. rattler/version/version.py +591 -0
  64. rattler/version/version_spec.py +184 -0
  65. rattler/version/with_source.py +80 -0
  66. rattler/virtual_package/__init__.py +4 -0
  67. rattler/virtual_package/generic.py +136 -0
  68. rattler/virtual_package/virtual_package.py +201 -0
@@ -0,0 +1,696 @@
1
+ from __future__ import annotations
2
+ import os
3
+ from pathlib import Path
4
+ from typing import List, Optional, Literal
5
+ from rattler.rattler import (
6
+ PyPathsJson,
7
+ PyPathsEntry,
8
+ PyPathType,
9
+ PyPrefixPlaceholder,
10
+ PyFileMode,
11
+ )
12
+
13
+
14
+ class PathsJson:
15
+ """
16
+ A representation of the `paths.json` file found in package archives.
17
+ The `paths.json` file contains information about every file included with the package.
18
+ """
19
+
20
+ _inner: PyPathsJson
21
+
22
+ @staticmethod
23
+ def from_package_archive(path: os.PathLike[str]) -> PathsJson:
24
+ """
25
+ Parses the package file from archive.
26
+ Note: If you want to extract multiple `info/*` files then this will be slightly
27
+ slower than manually iterating over the archive entries with
28
+ custom logic as this skips over the rest of the archive
29
+
30
+
31
+ """
32
+ return PathsJson._from_py_paths_json(PyPathsJson.from_package_archive(path))
33
+
34
+ @staticmethod
35
+ def from_path(path: os.PathLike[str]) -> PathsJson:
36
+ """
37
+ Parses the object from a file specified by a `path`, using a format
38
+ appropriate for the file type.
39
+
40
+ For example, if the file is in JSON format, this function reads the data
41
+ from the file at the specified path, parse the JSON string and return the
42
+ resulting object. If the file is not in a parsable format or if the file
43
+ could not read, this function returns an error.
44
+
45
+ Examples
46
+ --------
47
+ ```python
48
+ >>> paths_json = PathsJson.from_path(
49
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
50
+ ... )
51
+ >>> paths_json
52
+ PathsJson()
53
+ >>>
54
+ ```
55
+ """
56
+ return PathsJson._from_py_paths_json(PyPathsJson.from_path(Path(path)))
57
+
58
+ @staticmethod
59
+ def from_package_directory(path: os.PathLike[str]) -> PathsJson:
60
+ """
61
+ Parses the object by looking up the appropriate file from the root of the
62
+ specified Conda archive directory, using a format appropriate for the file
63
+ type.
64
+
65
+ For example, if the file is in JSON format, this function reads the
66
+ appropriate file from the archive, parse the JSON string and return the
67
+ resulting object. If the file is not in a parsable format or if the file
68
+ could not be read, this function returns an error.
69
+ """
70
+ return PathsJson._from_py_paths_json(PyPathsJson.from_package_directory(Path(path)))
71
+
72
+ @staticmethod
73
+ def from_str(string: str) -> PathsJson:
74
+ """
75
+ Parses the object from a string, using a format appropriate for the file
76
+ type.
77
+
78
+ For example, if the file is in JSON format, this function parses the JSON
79
+ string and returns the resulting object. If the file is not in a parsable
80
+ format, this function returns an error.
81
+ """
82
+ return PathsJson._from_py_paths_json(PyPathsJson.from_str(string))
83
+
84
+ @staticmethod
85
+ def package_path() -> Path:
86
+ """
87
+ Returns the path to the file within the Conda archive.
88
+
89
+ The path is relative to the root of the archive and includes any necessary
90
+ directories.
91
+ """
92
+ return PathsJson.package_path()
93
+
94
+ @staticmethod
95
+ def from_deprecated_package_directory(path: os.PathLike[str]) -> PathsJson:
96
+ """
97
+ Constructs a new instance by reading older (deprecated) files from a package directory.
98
+
99
+ In older package archives the `paths.json` file does not exist. These packages contain the
100
+ information normally present in the `paths.json` file spread over different files in the
101
+ archive.
102
+
103
+ This function reads the different files and tries to reconstruct a `paths.json` from it.
104
+ """
105
+ return PathsJson._from_py_paths_json(PyPathsJson.from_deprecated_package_directory(path))
106
+
107
+ @staticmethod
108
+ def from_package_directory_with_deprecated_fallback(
109
+ path: os.PathLike[str],
110
+ ) -> PathsJson:
111
+ """
112
+ Reads the file from a package archive directory. If the `paths.json` file could not be found
113
+ use the `from_deprecated_package_directory` method as a fallback.
114
+ """
115
+ return PathsJson._from_py_paths_json(PyPathsJson.from_package_directory_with_deprecated_fallback(path))
116
+
117
+ @property
118
+ def paths(self) -> List[PathsEntry]:
119
+ """
120
+ All entries included in the package.
121
+
122
+ Examples
123
+ --------
124
+ ```python
125
+ >>> paths_json = PathsJson.from_path(
126
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
127
+ ... )
128
+ >>> paths_json.paths
129
+ [PathsEntry(relative_path="Lib/site-packages/conda-22.9.0-py3.8.egg-info/PKG-INFO", no_link=False, path_type=PathType(hardlink=True), prefix_placeholder="None", sha256="1323efbd9b3abb527b06435392b39de11710eb3a814e87a8174230c8f5a0826a", size_in_bytes=1229), ...]
130
+ >>> paths_json.paths = [PathsEntry(relative_path="new/path", no_link=True, path_type=PathType("softlink"), prefix_placeholder=None, sha256=None, size_in_bytes=None)]
131
+ >>> len(paths_json.paths)
132
+ 1
133
+ >>>
134
+ ```
135
+ """
136
+ return [PathsEntry._from_py_paths_entry(path) for path in self._inner.paths]
137
+
138
+ @paths.setter
139
+ def paths(self, paths: List[PathsEntry]) -> None:
140
+ self._inner.paths = [entry._inner for entry in paths]
141
+
142
+ @property
143
+ def paths_version(self) -> int:
144
+ """
145
+ The version of the file.
146
+
147
+ Examples
148
+ --------
149
+ ```python
150
+ >>> paths_json = PathsJson.from_path(
151
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
152
+ ... )
153
+ >>> paths_json.paths_version
154
+ 1
155
+ >>> paths_json.paths_version = 2
156
+ >>> paths_json.paths_version
157
+ 2
158
+ >>>
159
+ ```
160
+ """
161
+ return self._inner.paths_version
162
+
163
+ @paths_version.setter
164
+ def paths_version(self, version: int) -> None:
165
+ self._inner.paths_version = version
166
+
167
+ @classmethod
168
+ def _from_py_paths_json(cls, py_paths_json: PyPathsJson) -> PathsJson:
169
+ paths_json = cls.__new__(cls)
170
+ paths_json._inner = py_paths_json
171
+
172
+ return paths_json
173
+
174
+ def __repr__(self) -> str:
175
+ """
176
+ Returns a representation of the PathsJson.
177
+ """
178
+ return "PathsJson()"
179
+
180
+
181
+ class PathsEntry:
182
+ """
183
+ A single entry in the `paths.json` file.
184
+ """
185
+
186
+ _inner: PyPathsEntry
187
+
188
+ def __init__(
189
+ self,
190
+ relative_path: str,
191
+ no_link: bool,
192
+ path_type: PathType,
193
+ prefix_placeholder: Optional[PrefixPlaceholder],
194
+ sha256: Optional[bytes],
195
+ size_in_bytes: Optional[int],
196
+ ) -> None:
197
+ """
198
+ Create a new paths entry.
199
+
200
+ Parameters
201
+ ----------
202
+ relative_path : str
203
+ The relative path from the root of the package
204
+ no_link : bool
205
+ Whether or not this file should be linked when installing the package
206
+ path_type : PathType
207
+ How to include the file when installing the package (hardlink, softlink, or directory)
208
+ prefix_placeholder : Optional[PrefixPlaceholder]
209
+ The placeholder prefix used in the file, if any
210
+ sha256 : Optional[bytes]
211
+ The SHA256 hash of the file contents (only used in paths.json version 1)
212
+ size_in_bytes : Optional[int]
213
+ The size of the file in bytes (only used in paths.json version 1)
214
+
215
+ Examples
216
+ --------
217
+ ```python
218
+ >>> # Create a basic file entry
219
+ >>> entry = PathsEntry(
220
+ ... relative_path="lib/file.txt",
221
+ ... no_link=False,
222
+ ... path_type=PathType("hardlink"),
223
+ ... prefix_placeholder=None,
224
+ ... sha256=None,
225
+ ... size_in_bytes=None
226
+ ... )
227
+ >>> str(entry.relative_path)
228
+ 'lib/file.txt'
229
+ >>> entry.no_link
230
+ False
231
+ >>> entry.path_type.hardlink
232
+ True
233
+ >>>
234
+ >>> # Create an entry with prefix placeholder
235
+ >>> placeholder = PrefixPlaceholder(FileMode("text"), "/old/prefix")
236
+ >>> sha256 = bytes.fromhex("c609c2f1a8594abf959388e559d76241e51b0216faa7b37f529255eb1fc2c5eb")
237
+ >>> entry = PathsEntry(
238
+ ... relative_path="bin/script",
239
+ ... no_link=False,
240
+ ... path_type=PathType("hardlink"),
241
+ ... prefix_placeholder=placeholder,
242
+ ... sha256=sha256,
243
+ ... size_in_bytes=1234
244
+ ... )
245
+ >>> entry.prefix_placeholder.placeholder
246
+ '/old/prefix'
247
+ >>> entry.size_in_bytes
248
+ 1234
249
+ >>>
250
+ ```
251
+ """
252
+ if prefix_placeholder is not None:
253
+ prefix_placeholder = prefix_placeholder._inner
254
+ self._inner = PyPathsEntry(relative_path, no_link, path_type._inner, prefix_placeholder, sha256, size_in_bytes)
255
+
256
+ @property
257
+ def relative_path(self) -> Path:
258
+ """
259
+ The relative path from the root of the package.
260
+
261
+ Examples
262
+ --------
263
+ ```python
264
+ >>> paths_json = PathsJson.from_path(
265
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
266
+ ... )
267
+ >>> entry = paths_json.paths[0]
268
+ >>> str(entry.relative_path)
269
+ 'Lib/site-packages/conda-22.9.0-py3.8.egg-info/PKG-INFO'
270
+ >>> entry.relative_path = "new/path"
271
+ >>> str(entry.relative_path)
272
+ 'new/path'
273
+ >>>
274
+ ```
275
+ """
276
+ return self._inner.relative_path
277
+
278
+ @relative_path.setter
279
+ def relative_path(self, path: str) -> None:
280
+ self._inner.relative_path = path
281
+
282
+ @property
283
+ def no_link(self) -> bool:
284
+ """
285
+ Whether or not this file should be linked or not when installing the package.
286
+
287
+ Examples
288
+ --------
289
+ ```python
290
+ >>> paths_json = PathsJson.from_path(
291
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
292
+ ... )
293
+ >>> entry = paths_json.paths[0]
294
+ >>> entry.no_link
295
+ False
296
+ >>> entry.no_link = True
297
+ >>> entry.no_link
298
+ True
299
+ >>>
300
+ ```
301
+ """
302
+ return self._inner.no_link
303
+
304
+ @no_link.setter
305
+ def no_link(self, no_link: bool) -> None:
306
+ self._inner.no_link = no_link
307
+
308
+ @property
309
+ def path_type(self) -> PathType:
310
+ """
311
+ Determines how to include the file when installing the package.
312
+
313
+ Examples
314
+ --------
315
+ ```python
316
+ >>> paths_json = PathsJson.from_path(
317
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
318
+ ... )
319
+ >>> entry = paths_json.paths[0]
320
+ >>> entry.path_type
321
+ PathType(hardlink=True)
322
+ >>> new_type = PathType("softlink")
323
+ >>> entry.path_type = new_type
324
+ >>> entry.path_type
325
+ PathType(softlink=True)
326
+ >>>
327
+ ```
328
+ """
329
+ return PathType._from_py_path_type(self._inner.path_type)
330
+
331
+ @path_type.setter
332
+ def path_type(self, path_type: "PathType") -> None:
333
+ self._inner.path_type = path_type._inner
334
+
335
+ @property
336
+ def prefix_placeholder(self) -> Optional[PrefixPlaceholder]:
337
+ """
338
+ Optionally the placeholder prefix used in the file. If this value is `None`
339
+ the prefix is not present in the file.
340
+
341
+ Examples
342
+ --------
343
+ ```python
344
+ >>> paths_json = PathsJson.from_path(
345
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
346
+ ... )
347
+ >>> entry = paths_json.paths[0]
348
+ >>> entry.prefix_placeholder
349
+ >>> new_placeholder = PrefixPlaceholder(FileMode("text"), "placeholder")
350
+ >>> entry.prefix_placeholder = new_placeholder
351
+ >>> entry.prefix_placeholder
352
+ PrefixPlaceholder(file_mode=FileMode("text"), placeholder="placeholder")
353
+ >>>
354
+ ```
355
+ """
356
+ if placeholder := self._inner.prefix_placeholder:
357
+ return PrefixPlaceholder._from_py_prefix_placeholder(placeholder)
358
+
359
+ return None
360
+
361
+ @prefix_placeholder.setter
362
+ def prefix_placeholder(self, placeholder: Optional[PrefixPlaceholder]) -> None:
363
+ if placeholder is None:
364
+ self._inner.prefix_placeholder = None
365
+ else:
366
+ self._inner.prefix_placeholder = placeholder._inner
367
+
368
+ @property
369
+ def sha256(self) -> Optional[bytes]:
370
+ """
371
+ A hex representation of the SHA256 hash of the contents of the file.
372
+ This entry is only present in version 1 of the paths.json file.
373
+
374
+ Examples
375
+ --------
376
+ ```python
377
+ >>> paths_json = PathsJson.from_path(
378
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
379
+ ... )
380
+ >>> entry = paths_json.paths[0]
381
+ >>> entry.sha256.hex()
382
+ '1323efbd9b3abb527b06435392b39de11710eb3a814e87a8174230c8f5a0826a'
383
+ >>> entry.sha256 = bytes.fromhex('058016a01bb3845320c81755882a367e03a449c1898a3de4f3ea54112fb3eba4')
384
+ >>> entry.sha256.hex()
385
+ '058016a01bb3845320c81755882a367e03a449c1898a3de4f3ea54112fb3eba4'
386
+ >>>
387
+ ```
388
+ """
389
+ return self._inner.sha256
390
+
391
+ @sha256.setter
392
+ def sha256(self, sha: Optional[bytes]) -> None:
393
+ self._inner.sha256 = sha
394
+
395
+ @property
396
+ def size_in_bytes(self) -> Optional[int]:
397
+ """
398
+ The size of the file in bytes.
399
+ This entry is only present in version 1 of the paths.json file.
400
+
401
+ Examples
402
+ --------
403
+ ```python
404
+ >>> paths_json = PathsJson.from_path(
405
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
406
+ ... )
407
+ >>> entry = paths_json.paths[0]
408
+ >>> entry.size_in_bytes
409
+ 1229
410
+ >>> entry.size_in_bytes = 42
411
+ >>> entry.size_in_bytes
412
+ 42
413
+ >>>
414
+ ```
415
+ """
416
+ if size := self._inner.size_in_bytes:
417
+ return size
418
+
419
+ return None
420
+
421
+ @size_in_bytes.setter
422
+ def size_in_bytes(self, size: Optional[int]) -> None:
423
+ self._inner.size_in_bytes = size
424
+
425
+ @classmethod
426
+ def _from_py_paths_entry(cls, py_paths_entry: PyPathsEntry) -> PathsEntry:
427
+ paths_entry = cls.__new__(cls)
428
+ paths_entry._inner = py_paths_entry
429
+
430
+ return paths_entry
431
+
432
+ def __repr__(self) -> str:
433
+ """
434
+ Returns a representation of the PathsEntry.
435
+ """
436
+ sha256_str = self.sha256.hex() if self.sha256 else None
437
+ return f'PathsEntry(relative_path="{self.relative_path}", no_link={self.no_link}, path_type={self.path_type}, prefix_placeholder="{self.prefix_placeholder}", sha256="{sha256_str}", size_in_bytes={self.size_in_bytes})'
438
+
439
+
440
+ class PathType:
441
+ """
442
+ The path type of the path entry
443
+ """
444
+
445
+ _inner: PyPathType
446
+
447
+ def __init__(self, path_type: Literal["hardlink", "softlink", "directory"]) -> None:
448
+ self._inner = PyPathType(path_type)
449
+
450
+ @property
451
+ def hardlink(self) -> bool:
452
+ """
453
+ The path should be hard linked (the default).
454
+
455
+ Examples
456
+ --------
457
+ ```python
458
+ >>> paths_json = PathsJson.from_path(
459
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
460
+ ... )
461
+ >>> entry = paths_json.paths[0]
462
+ >>> path_type = entry.path_type
463
+ >>> path_type.hardlink
464
+ True
465
+ >>>
466
+ ```
467
+ """
468
+ return self._inner.hardlink
469
+
470
+ @property
471
+ def softlink(self) -> bool:
472
+ """
473
+ The path should be soft linked.
474
+
475
+ Examples
476
+ --------
477
+ ```python
478
+ >>> paths_json = PathsJson.from_path(
479
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
480
+ ... )
481
+ >>> entry = paths_json.paths[0]
482
+ >>> path_type = entry.path_type
483
+ >>> path_type.softlink
484
+ False
485
+ >>>
486
+ ```
487
+ """
488
+ return self._inner.softlink
489
+
490
+ @property
491
+ def directory(self) -> bool:
492
+ """
493
+ This should explicitly create an empty directory.
494
+
495
+ Examples
496
+ --------
497
+ ```python
498
+ >>> paths_json = PathsJson.from_path(
499
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
500
+ ... )
501
+ >>> entry = paths_json.paths[0]
502
+ >>> path_type = entry.path_type
503
+ >>> path_type.directory
504
+ False
505
+ >>>
506
+ ```
507
+ """
508
+ return self._inner.directory
509
+
510
+ @classmethod
511
+ def _from_py_path_type(cls, py_paths_type: PyPathType) -> PathType:
512
+ path_type = cls.__new__(cls)
513
+ path_type._inner = py_paths_type
514
+
515
+ return path_type
516
+
517
+ def __repr__(self) -> str:
518
+ """
519
+ Returns a representation of the PathType.
520
+ """
521
+ if self._inner.hardlink:
522
+ return "PathType(hardlink=True)"
523
+ elif self._inner.softlink:
524
+ return "PathType(softlink=True)"
525
+ else:
526
+ return "PathType(directory=True)"
527
+
528
+
529
+ class PrefixPlaceholder:
530
+ """
531
+ Description off a placeholder text found in a file that must be replaced
532
+ when installing the file into the prefix.
533
+ """
534
+
535
+ _inner: PyPrefixPlaceholder
536
+
537
+ def __init__(self, file_mode: FileMode, placeholder: str) -> None:
538
+ """
539
+ Create a new prefix placeholder.
540
+
541
+ Parameters
542
+ ----------
543
+ file_mode: FileMode
544
+ The file mode of the entry.
545
+ placeholder: str
546
+ The placeholder prefix used in the file.
547
+
548
+ Examples
549
+ --------
550
+ ```python
551
+ >>> placeholder = PrefixPlaceholder(FileMode("text"), "placeholder")
552
+ >>> placeholder
553
+ PrefixPlaceholder(file_mode=FileMode("text"), placeholder="placeholder")
554
+ >>>
555
+ ```
556
+ """
557
+ self._inner = PyPrefixPlaceholder(file_mode._inner, placeholder)
558
+
559
+ @property
560
+ def file_mode(self) -> FileMode:
561
+ """
562
+ The type of the file, either binary or text.
563
+
564
+ Examples
565
+ --------
566
+ ```python
567
+ >>> paths_json = PathsJson.from_path(
568
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
569
+ ... )
570
+ >>> entry = paths_json.paths[-1]
571
+ >>> entry.prefix_placeholder.file_mode
572
+ FileMode("text")
573
+ >>>
574
+ ```
575
+ """
576
+ return FileMode._from_py_file_mode(self._inner.file_mode)
577
+
578
+ @property
579
+ def placeholder(self) -> str:
580
+ """
581
+ The placeholder prefix used in the file. This is the path of the
582
+ prefix when the package was build.
583
+
584
+ Examples
585
+ --------
586
+ ```python
587
+ >>> paths_json = PathsJson.from_path(
588
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
589
+ ... )
590
+ >>> entry = paths_json.paths[-1]
591
+ >>> entry.prefix_placeholder.placeholder
592
+ 'D:\\\\bld\\\\conda_1667595064120\\\\_h_env'
593
+ >>>
594
+ ```
595
+ """
596
+ return self._inner.placeholder
597
+
598
+ @classmethod
599
+ def _from_py_prefix_placeholder(cls, py_prefix_placeholder: PyPrefixPlaceholder) -> PrefixPlaceholder:
600
+ prefix_placeholder = cls.__new__(cls)
601
+ prefix_placeholder._inner = py_prefix_placeholder
602
+
603
+ return prefix_placeholder
604
+
605
+ def __repr__(self) -> str:
606
+ """
607
+ Returns a representation of the PrefixPlaceholder.
608
+ """
609
+ return f'PrefixPlaceholder(file_mode={self.file_mode}, placeholder="{self.placeholder}")'
610
+
611
+
612
+ class FileMode:
613
+ """
614
+ The file mode of the entry.
615
+ """
616
+
617
+ _inner: PyFileMode | None = None
618
+
619
+ def __init__(self, file_mode: Literal["binary", "text"]) -> None:
620
+ self._inner = PyFileMode(file_mode)
621
+
622
+ @property
623
+ def binary(self) -> bool:
624
+ """
625
+ The file is a binary file (needs binary prefix replacement).
626
+
627
+ Examples
628
+ --------
629
+ ```python
630
+ >>> paths_json = PathsJson.from_path(
631
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
632
+ ... )
633
+ >>> entry = paths_json.paths[-1]
634
+ >>> file_mode = entry.prefix_placeholder.file_mode
635
+ >>> file_mode.binary
636
+ False
637
+ >>>
638
+ ```
639
+ """
640
+ return self._inner.binary if self._inner else False
641
+
642
+ @property
643
+ def text(self) -> bool:
644
+ """
645
+ The file is a text file (needs text prefix replacement).
646
+
647
+ Examples
648
+ --------
649
+ ```python
650
+ >>> paths_json = PathsJson.from_path(
651
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
652
+ ... )
653
+ >>> entry = paths_json.paths[-1]
654
+ >>> file_mode = entry.prefix_placeholder.file_mode
655
+ >>> file_mode.text
656
+ True
657
+ >>>
658
+ ```
659
+ """
660
+ return self._inner.text if self._inner else False
661
+
662
+ @property
663
+ def unknown(self) -> bool:
664
+ """
665
+ The file mode is unknown/unspecified
666
+ Examples
667
+ --------
668
+ ```python
669
+ >>> paths_json = PathsJson.from_path(
670
+ ... "../test-data/conda-22.9.0-py38haa244fe_2-paths.json"
671
+ ... )
672
+ >>> entry = paths_json.paths[-1]
673
+ >>> file_mode = entry.prefix_placeholder.file_mode
674
+ >>> file_mode.unknown
675
+ False
676
+ >>>
677
+ """
678
+ return self._inner is None
679
+
680
+ @classmethod
681
+ def _from_py_file_mode(cls, py_file_mode: PyFileMode) -> FileMode:
682
+ file_mode = cls.__new__(cls)
683
+ file_mode._inner = py_file_mode
684
+
685
+ return file_mode
686
+
687
+ def __repr__(self) -> str:
688
+ """
689
+ Returns a representation of the FileMode.
690
+ """
691
+ if self.binary:
692
+ return 'FileMode("binary")'
693
+ elif self.text:
694
+ return 'FileMode("text")'
695
+ else:
696
+ return "FileMode()"