Skip to content
Snippets Groups Projects
Select Git revision
  • b7bdb413a67fa0f15d8e5d0cb0675f1f4eb077ca
  • master default protected
  • conda-forge-tensorflow-feedstock
  • py39
  • mxnet
5 results

check_exists.py

Blame
  • user avatar
    Amir MOHAMMADI authored
    a965f402
    History
    check_exists.py 2.16 KiB
    #!/usr/bin/env python
    # Mon 26 Feb 11:11:30 2018 CET
    
    # Checks if the combination of package-name, version and build number already
    # exist on the provided channel. If so, exits with 0 - otherwise, non-zero.
    
    import os
    import re
    import sys
    import yaml
    import subprocess
    from conda.exports import get_index
    
    
    def check_on_channel(channel_url, name, version, build_number):
      """Checks on the given channel if a package with the specs exist"""
    
      # get the channel index
      print('Retrieving conda channel index (%s)...' % channel_url)
      index = get_index(channel_urls=[channel_url], prepend=False)
    
      # search if package with the same version/py_ver/build_number exists
      print('Checking for %s-%s_*_%s...' % (name, version, build_number))
      urls = []
      for dist in index:
        #print('checking %s-%s_%s' % (dist.name, dist.version, dist.build_string))
        if dist.name == name and \
            dist.version == version and \
            dist.build_string.endswith('_%s' % build_number):
          print('Found matching package (%s-%s_%s)' % \
              (dist.name, dist.version, dist.build_string))
          return True
    
      print('No matches found among %d packages' % len(index))
      return False
    
    
    def get_rendered_recipe(build_config, path):
    
      print('Rendering conda recipe (%s)...' % path)
    
      conda=os.path.join(os.path.dirname(sys.executable), 'conda')
    
      cmd = [conda, 'render', '--variant-config-files', build_config, path]
      print('$ %s' % ' '.join(cmd))
    
      from conda_build.api import get_or_merge_config, render, output_yaml
      config = get_or_merge_config(None, variant_config_files=build_config)
      metadata = render(path, config=config)
      output = output_yaml(metadata[0][0])
      return yaml.load(output)
    
    
    def main():
    
      parsed = get_rendered_recipe(sys.argv[1], sys.argv[2])
      if parsed is not None:
        if check_on_channel(sys.argv[3], parsed['package']['name'],
            parsed['package']['version'], parsed['build']['number']):
          sys.exit(0)
      else:
        print('Recipe %s is not enabled for the current architecture' % sys.argv[2])
        sys.exit(0)
    
      sys.exit(1)
    
    
    if __name__ == '__main__':
      if len(sys.argv) != 4:
        print('usage: %s build-config recipe-dir channel' % sys.argv[0])
        sys.exit(1)
      main()