conda: only ignore simple builds during environment.yml parsing

This commit is contained in:
DavHau 2020-11-20 10:50:12 +07:00
parent ce9dc7cf66
commit f69e56c381
3 changed files with 44 additions and 48 deletions

View file

@ -85,45 +85,51 @@ rec {
pkgs."${python_arg}" ;
preProcessRequirements = str:
if isCondaEnvironmentYml str then
condaYml2reqs (fromYAML str)
else {
requirements = str;
providers = [];
};
condaYml2reqs = data:
{
requirements =
concatStringsSep "\n" (flatten (map (d:
let
split = splitString "=" d;
name = elemAt split 0;
ver = elemAt split 1;
build = elemAt split 2;
in
if hasPrefix "_" name || elem name [ "python" "conda" ] then
[]
else
"${name} ${ver} ${build}"
) data.dependencies));
providers = flatten (map (c:
if c == "defaults" then
[ "conda/main" "conda/r" ]
else
"conda/" + c
) data.channels);
} // (
let
pyDep = filter (d: hasPrefix "python=" d) data.dependencies;
condaYml2reqs = data:
{
requirements =
concatStringsSep "\n" (flatten (map (d:
let
split = splitString "=" d;
name = elemAt split 0;
ver = elemAt split 1;
build = elemAt split 2;
build'=
if isNull (match "py[[:digit:]]+_[[:digit:]]+" build) && isNull (match "[[:digit:]]+" build) then
build
else
"*";
in
if hasPrefix "_" name || elem name [ "python" "conda" ] then
[]
else
"${name} ${ver} ${build'}"
) data.dependencies));
providers = flatten (map (c:
if c == "defaults" then
[ "conda/main" "conda/r" ]
else
"conda/" + c
) data.channels);
} // (
let
pyDep = filter (d: hasPrefix "python=" d) data.dependencies;
in
if pyDep == [] then {}
else let
pyVer = splitString "." (elemAt (splitString "=" (elemAt pyDep 0)) 1); # example: [ 3 7 2 ]
in
{ python = "python${elemAt pyVer 0}${elemAt pyVer 1}"; }
);
in
if pyDep == [] then {}
else let
pyVer = splitString "." (elemAt (splitString "=" (elemAt pyDep 0)) 1); # example: [ 3 7 2 ]
in
{ python = "python${elemAt pyVer 0}${elemAt pyVer 1}"; }
);
if isCondaEnvironmentYml str then
condaYml2reqs (fromYAML str)
else {
requirements = str;
providers = [];
};
parseProviders = providers:
let

View file

@ -96,10 +96,7 @@ def parse_reqs_line(line):
ver_spec = f"=={ver_spec}"
line = f"{name}{ver_spec}"
if build is None \
or build == "*"\
or re.match(r"(py)?\d+_\d+", build)\
or re.match(r"\d+", build):
if build == "*":
build = None
return line, build

View file

@ -36,13 +36,6 @@ from mach_nix.requirements import parse_reqs_line
# test 3 parts non-conda
(None, 'python >=2.6, !=3.0.*', 'python >=2.6, !=3.0.*'),
# ignoring builds
(None, 'requests==2.24.0', ' requests 2.24.0 py37_2'),
(None, 'requests==2.24.0', ' requests 2.24.0 0'),
(None, 'requests==2.24.0', ' requests 2.24.0 *'),
(None, 'ca-certificates>=2020.10.14', 'ca-certificates >=2020.10.14 0'),
('py35hd5e75dd_0', 'requests==2.24.0', ' requests 2.24.0 py35hd5e75dd_0'),
])
def test_parse_requirements(exp_build, exp_line, line):
new_line, build = parse_reqs_line(line)