Package: rust-matchspec
MatchSpecA Conda MatchSpec implementation in pure Rust. This allows you to parse a matchspec and validate it against a package to see if it matches.Python LibraryThis library exposes a few simple functions:match_against_matchspec()Takes amatchspecas astrand matches it against apackage_nameandversion(bothstr). Returns abool.importrust_matchspecrust_matchspec.match_against_matchspec('python>=3.0','python','3.10.1')# returns Truefilter_package_list()Takes alistofdictsand returns all the dicts inside that match a given matchspec. Thedictsmust have anamekey with astrvalue, but all other fields are optional.importrust_matchspeclist=[{'name':'tensorflow','version':'2.10.0'},{'name':'pytorch','version':'2.0.0'},{'name':'pytorch','version':'1.11.1'}]rust_matchspec.filter_package_list('pytorch>1.12',list)# returns [PackageCandidate(name=pytorch)]Possible keys:KeyExpected TypeRequired?namestryesversionstrbuildstrbuild_numberu32depends[str]licensestrmd5strsha256strsizeu64subdirstrtimestampu64parallel_filter_package_list()Using all available cores will take alistofdictsand returns all the dicts inside that match a given matchspec. Thedictsmust have anamekey with astrvalue, but all other fields are optional.NoteProbably won't show any noticable speed improvements until your list of packages is in the millions.importrust_matchspeclist=[{'name':'tensorflow','version':'2.10.0'},{'name':'pytorch','version':'2.0.0'},{'name':'pytorch','version':'1.11.1'}]rust_matchspec.parallel_filter_package_list('pytorch>1.12',list)# returns [PackageCandidate(name=pytorch)]parallel_filter_package_list_with_matchspec_list()Using all available cores will take alistofdictsand alistof Matchspecs (asstr) and returns all the dicts inside that match any given matchspec. Thedictsmust have anamekey with astrvalue, but all other fields are optional.May contain duplicatessince it runs all of the matchspecs against the package list in parallel and does not dedup the resulting matches.In my testing this has a very small overhead, but matching 4 matchspecs is approximately the same speed as matching a single matchspec with the other functions.importrust_matchspecpackage_list=[{'name':'tensorflow','version':'2.10.0'},{'name':'pytorch','version':'2.0.0'},{'name':'pytorch','version':'1.11.1'}]matchspec_list=['python>=3.9.1','pytorch>1.12']rust_matchspec.parallel_filter_package_list_with_matchspec_list(matchspec_list,package_list)# returns [PackageCandidate(name=pytorch)]Rust LibraryExampleThe way you instantiate a MatchSpec is by parsing a string into the type:userust_matchspec::{CompoundSelector,MatchSpec,Selector};// Create the MatchSpec by parsing a String or &strletmatchspec:MatchSpec="main/linux-64::pytorch>1.10.2".parse().unwrap();// You then have the data accessible inside the MatchSpec struct if you want it// Package name is the only mandatory field in a matchspecassert_eq!(&matchspec.package,"pytorch");// These are optional, so they will be wrapped in an Optionassert_eq!(matchspec.channel,Some("main".to_string()));assert_eq!(matchspec.version,Some(CompoundSelector::Single{selector:Selector::GreaterThan,version:"1.10.2".to_string(),}));// You can also check to see if a package name and version match the spec.// This is a faster function that allows us to bypass some sometimes unnecessary tests like channel or subdirassert!(matchspec.is_package_version_match(&"pytorch",&"1.11.0"))BenchmarkingThis library contains benchmarks aimed at checking the speed of our implementation against other languages and ensure speed doesn't regress. These are contrived benchmarks to test raw speed, so take them (and all benchmarks) with a bit of skepticism. Benchmark harnesses and the data all need to be identical for a benchmark to really provide value.PythonThe Python benchmarks usepytest-benchmark.Steps to run the benchmarks:# Setup the conda envcondaenvcreate-f./environment.yml
condaactivaterust_matchspec# Build an optimized wheelmaturinbuild--release# install itpipinstall./target/wheels/rust_matchspec*.whl# Finally, run the benchmarkpytestRustThe Rust benchmarks useCriterion.rsto provide the benchmarking framework. Its pretty easy to run the benchmarks on stable rust:cargobench# Or if you're on mac and get errors with Invalid Symbols:cargobench--no-default-featuresThis will automatically track benchmark timings across runs. If you do this on a laptop or workstation be aware that you may have regressions show up if you have background processes or other things happening. I would recommend always running the benchmarks at a similar level of CPU load. If you want consistent testing its probably best to quit your browser or anything in the background that might be eating CPU or doing IO.