Verified Commit 1d3465b4 authored by Duncan Macleod's avatar Duncan Macleod
Browse files

search.py: refactoring

and fixed a bug for noarch
[skip deploy]

(cherry picked from commit 20a3d2e3)
parent bfc0d5f7
Pipeline #303767 skipped
......@@ -41,6 +41,29 @@ def _is_pypy_build(package):
return True
def conda_search_platforms(
package,
version,
build,
platforms,
**kwargs,
):
for platform in platforms:
for subdir in SUBDIRS[platform]:
try:
pkgs = conda_search(name, version, build, subdir, **kwargs)
except RuntimeError:
if not subdir.endswith("-64"): # skip over non x86_64
continue
raise
for package in pkgs:
yield package
# only search once for noarch
if package["subdir"] == "noarch":
return
def conda_search(package, version, build, subdir, conda="conda", **kwargs):
key = "=".join((package, version) + ((build,) if build else ()))
cmd = [
......@@ -85,94 +108,97 @@ def yaml_build_string(packagedata):
return text
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"package",
help="name of package to find",
)
parser.add_argument(
"version",
help="version of package to find",
)
parser.add_argument(
"-b",
"--build",
help="build string of package to find",
)
parser.add_argument(
"-l",
"--skip-linux",
action="store_true",
help="skip linux",
)
parser.add_argument(
"-o",
"--skip-osx",
action="store_true",
help="skip osx",
)
parser.add_argument(
"-w",
"--skip-windows",
action="store_true",
help="skip windows",
)
parser.add_argument(
"-c",
"--conda",
default=CONDA,
help="path of conda executable",
)
parser.add_argument(
"-f",
"--format",
choices=["ascii", "yaml"],
default="yaml",
help="output format",
)
args = parser.parse_args()
name = args.package
version = args.version
build = args.build
conda = args.conda
# -- execute searches
if args.format == "yaml":
print(
"package:\n"
" name: {}\n"
" version: {}".format(name, version)
def create_parser():
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"package",
help="name of package to find",
)
parser.add_argument(
"version",
help="version of package to find",
)
parser.add_argument(
"-b",
"--build",
help="build string of package to find",
)
parser.add_argument(
"-l",
"--skip-linux",
action="store_true",
help="skip linux",
)
parser.add_argument(
"-o",
"--skip-osx",
action="store_true",
help="skip osx",
)
parser.add_argument(
"-w",
"--skip-windows",
action="store_true",
help="skip windows",
)
parser.add_argument(
"-c",
"--conda",
default=CONDA,
help="path of conda executable",
)
parser.add_argument(
"-f",
"--format",
choices=["ascii", "yaml"],
default="yaml",
help="output format",
)
return parser
if __name__ == "__main__":
parser = create_parser()
args = parser.parse_args()
name = args.package
version = args.version
build = args.build
conda = args.conda
# -- execute searches
if args.format == "yaml":
print(
"package:\n"
" name: {}\n"
" version: {}".format(name, version)
)
# pick platforms
platforms = [
platform for skip, platform in [
(args.skip_linux, "linux"),
(args.skip_osx, "osx"),
(args.skip_windows, "win"),
] if not skip
]
for skip, platform in [
(args.skip_linux, "linux"),
(args.skip_osx, "osx"),
(args.skip_windows, "win"),
]:
if skip:
continue
for subdir in SUBDIRS[platform]:
try:
for package in conda_search(name, version, build, subdir, conda=conda):
if args.format == "yaml":
print(yaml_build_string(package))
else:
print(
"{0[subdir]:9s} {0[name]} {0[version]} {0[build]}".format(
package,
),
)
except RuntimeError:
if not subdir.endswith("-64"): # skip over non x86_64
continue
raise
if package["subdir"] == "noarch": # only search once for noarch
break
# search for all packages across all platforms
for package in conda_search_platforms(
name,
version,
build,
platforms,
conda=conda,
):
if args.format == "yaml":
print(yaml_build_string(package))
else:
print(
"{0[subdir]:9s} {0[name]} {0[version]} {0[build]}".format(
package,
),
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment