gpt4 book ai didi

conda - 如何使用 conda MatchSpec?

转载 作者:行者123 更新时间:2023-12-03 18:31:36 26 4
gpt4 key购买 nike

How to list package versions available with conda有有用的答案,其中之一在 https://stackoverflow.com/a/47795843/257924它使用两个等号。 conda search -h没有完全说明 MatchSpec 语法允许的内容,只给出了一些简单的例子。

比如我想查看python最新版本下有哪些包存在,对于一个叫jedi的包.我不得不求助于实验和猜测来找到正确的语法,因为上面缺少 MatchSpec 语法的详细文档。我结束了:

$ condaw search 'jedi[build=py37*]' --json | grep '"build"' 
"build": "py37_1",
"build": "py37_0",
"build": "py37_0",
"build": "py37_0",
"build": "py37_0",
$

以上 --json选项只是为了我可以找出什么关键字,例如 build可能是语法的一部分。

那么,MatchSpec 语法在哪里有正式和完整的文档,这样我就不必猜测了?我现在得出结论 -h输出是唯一的。

最佳答案

some (possibly outdated) documentation in the conda-build docs .但是,我仍然认为他们代码中的文档更清晰。它可以从激活的 中读取底座 环境使用

python -c "from conda.models.match_spec import MatchSpec; help(MatchSpec)"
或在 the GitHub repo .
从技术上讲,代码文档更多地是关于序列化 MatchSpec object 到字符串表示,而不是解析字符串的另一个方向,但它涵盖了所有的可能性。

匹配规范字符串
部分文档描述了类本身,但这里是类的字符串文字表示的相关部分:

The canonical string representation can generically be represented by

(channel(/subdir):(namespace):)name(version(build))[key1=value1,key2=value2]

where () indicate optional fields. The rules for constructing acanonical string representation are:

  1. name (i.e. "package name") is required, but its value can be '*'. Its position is always outside the key-value brackets.
  2. If version is an exact version, it goes outside the key-value brackets and is prepended by ==. If version is a "fuzzy" value(e.g. 1.11.*), it goes outside the key-value brackets with the.* left off and is prepended by =. Otherwise version isincluded inside key-value brackets.
  3. If version is an exact version, and build is an exact value, build goes outside key-value brackets prepended by a =.Otherwise, build goes inside key-value brackets. build_stringis an alias for build.
  4. The namespace position is being held for a future conda feature.
  5. If channel is included and is an exact value, a :: separator is ued between channel and name. channel can either be acanonical channel name or a channel url. In the canonical stringrepresentation, the canonical channel name will always be used.
  6. If channel is an exact value and subdir is an exact value, subdir is appended to channel with a / separator. Otherwise,subdir is included in the key-value brackets.
  7. Key-value brackets can be delimited by comma, space, or comma+space. Value can optionally be wrapped in single or doublequotes, but must be wrapped if value contains a comma, space, orequal sign. The canonical format uses comma delimiters and singlequotes.
  8. When constructing a :class:MatchSpec instance from a string, any key-value pair given inside the key-value brackets overrides anymatching parameter given outside the brackets.


支持的键
除了字符串中明确表示的字段外,还支持以下键:
  • build_number
  • track_features
  • features
  • url
  • md5
  • license
  • license_family
  • fn

  • 注: fn代表 f 文件 嗯。
    例子
    文档继续给出示例,展示如何使用此 MatchSpec生成这些规范字符串的类:
    >>> str(MatchSpec(name='foo', build='py2*', channel='conda-forge'))
    'conda-forge::foo[build=py2*]'

    >>> str(MatchSpec('foo 1.0 py27_0'))
    'foo==1.0=py27_0'

    >>> str(MatchSpec('foo=1.0=py27_0'))
    'foo==1.0=py27_0'

    >>> str(MatchSpec('conda-forge::foo[version=1.0.*]'))
    'conda-forge::foo=1.0'

    >>> str(MatchSpec('conda-forge/linux-64::foo>=1.0'))
    "conda-forge/linux-64::foo[version='>=1.0']"

    >>> str(MatchSpec('*/linux-64::foo>=1.0'))
    "foo[subdir=linux-64,version='>=1.0']"

    关于conda - 如何使用 conda MatchSpec?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57538225/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com