-
-
Save cat-bro/34eb208ed4018c90134a78a358e50327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import argparse | |
# Adapted from this gist by natefoo: https://gist.github.com/natefoo/7a13e5bf6f4bbf961db73a3d6e9f9e1c | |
# and https://github.com/galaxyproject/galaxy/blob/release_21.01/lib/galaxy/tool_util/deps/conda_util.py | |
def main(): | |
parser = argparse.ArgumentParser(description='Get a Galaxy style virtual environment name from a list of conda requirements') | |
parser.add_argument('requirements', help='One or more conda requirements e.g. balloon=1.1 or fish=0.0+galaxy6', nargs='+') | |
args = parser.parse_args() | |
targets = [] | |
for req in args.requirements: | |
if '=' in req: | |
name, version = req.split('=') | |
else: | |
name, version = [req, None] | |
targets.append((name, version)) | |
print(get_env_name(targets)) | |
def install_environment(target): | |
package, version = target | |
if version: | |
return "__%s@%s" % (package, version) | |
else: | |
return "__%s@_uv_" % (package) | |
def hash_conda_packages(targets): | |
h = hashlib.new('sha256') | |
for target in targets: | |
h.update(install_environment(target).encode('utf-8')) | |
return h.hexdigest() | |
def get_env_name(targets): | |
if len(targets) == 1: | |
return install_environment(targets[0]) | |
else: | |
return 'mulled-v1-' + hash_conda_packages(targets) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment