SparseRepoData#
PackageFormatSelection #
Bases: Enum
Enum that describes what to do if both a .tar.bz2
and a .conda
package is available.
BOTH
class-attribute
instance-attribute
#
Use both the .tar.bz2
and the .conda
packages.
ONLY_CONDA
class-attribute
instance-attribute
#
Only use the .conda
packages, ignore all .tar.bz2
packages.
ONLY_TAR_BZ2
class-attribute
instance-attribute
#
Only use the .tar.bz2
packages, ignore all .conda
packages.
PREFER_CONDA
class-attribute
instance-attribute
#
Only use the .conda
packages if there are both a .tar.bz2
and a .conda
package available.
SparseRepoData #
A class to enable loading records from a repodata.json
file on demand.
Since most of the time you don't need all the records from the repodata.json
this can help provide some significant speedups.
__enter__ #
Returns the SparseRepoData
instance itself. This is used to
enable the use of the with
statement to automatically close
the instance when done.
Examples#
close #
Closes any mapped resources associated with this SparseRepoData
instance. It is good practice to call this method when you are done
with it. This is especially important if you want to modify or delete
the file from which this instance was created.
This method will release all resources associated with this instance, including those that are currently being used on another thread. This method will block until all resources are released.
This method has no effect if the file is already closed. Once the
instance is closed, any operation on the instance will raise a
ValueError
.
As a convenience, it is allowed to call this method more than once; only the first call, however, will have an effect.
Examples#
>>> from rattler import Channel, ChannelConfig
>>> channel = Channel("dummy", ChannelConfig())
>>> path = "../test-data/channels/dummy/linux-64/repodata.json"
>>> sparse_data = SparseRepoData(channel, "linux-64", path)
>>> sparse_data.close()
>>> sparse_data.package_names() # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ValueError: I/O operation on closed file.
>>>
load_all_records #
Returns all the records for the specified package name.
Examples#
>>> from rattler import Channel, ChannelConfig, RepoDataRecord, PackageName
>>> channel = Channel("dummy", ChannelConfig())
>>> path = "../test-data/channels/dummy/linux-64/repodata.json"
>>> sparse_data = SparseRepoData(channel, "linux-64", path)
>>> records = sparse_data.load_all_records()
>>> records
[...]
>>> isinstance(records[0], RepoDataRecord)
True
>>>
load_matching_records #
Returns all the records that match any of the specified MatchSpecs.
Examples#
>>> from rattler import Channel, ChannelConfig, RepoDataRecord, PackageName
>>> channel = Channel("dummy", ChannelConfig())
>>> path = "../test-data/channels/dummy/linux-64/repodata.json"
>>> sparse_data = SparseRepoData(channel, "linux-64", path)
>>> [record.file_name for record in sparse_data.load_matching_records([MatchSpec("* 12.5")])]
['cuda-version-12.5-hd4f0392_3.conda']
>>>
load_records #
Returns all the records for the specified package name.
Examples#
>>> from rattler import Channel, ChannelConfig, RepoDataRecord, PackageName
>>> channel = Channel("dummy", ChannelConfig())
>>> path = "../test-data/channels/dummy/linux-64/repodata.json"
>>> sparse_data = SparseRepoData(channel, "linux-64", path)
>>> package_name = PackageName(sparse_data.package_names()[0])
>>> records = sparse_data.load_records(package_name)
>>> records
[...]
>>> isinstance(records[0], RepoDataRecord)
True
>>>
load_records_recursive
staticmethod
#
load_records_recursive(
repo_data,
package_names,
package_format_selection=PackageFormatSelection.PREFER_CONDA,
)
Given a set of [SparseRepoData
]s load all the records
for the packages with the specified names and all the packages
these records depend on. This will parse the records for the
specified packages as well as all the packages these records
depend on.
Examples#
>>> from rattler import Channel, ChannelConfig, PackageName
>>> channel = Channel("dummy")
>>> subdir = "test-data/dummy/linux-64"
>>> path = "../test-data/channels/dummy/linux-64/repodata.json"
>>> sparse_data = SparseRepoData(channel, "linux-64", path)
>>> package_name = PackageName("python")
>>> SparseRepoData.load_records_recursive([sparse_data], [package_name])
[...]
>>>
package_names #
Returns a list over all package names in this repodata file.
This works by iterating over all elements in the packages
and
conda_packages
fields of the repodata and returning the unique
package names.
Examples#
>>> from rattler import Channel, ChannelConfig
>>> channel = Channel("dummy", ChannelConfig())
>>> path = "../test-data/channels/dummy/linux-64/repodata.json"
>>> sparse_data = SparseRepoData(channel, "linux-64", path)
>>> package_names = sparse_data.package_names()
>>> package_names
[...]
>>> isinstance(package_names[0], str)
True
>>>
record_count #
Returns the total number of packages in this repodata file. :return: