def version_compare(recipe_dir, newest_conda_version): m = metadata.MetaData(recipe_dir) local_version = m.version() package = basename(recipe_dir) print("Local recipe for %s has version %s." % (package, local_version)) print("The version on CRAN for %s is %s." % (package, newest_conda_version)) return local_version == newest_conda_version
def package_to_inputs_dict(output_dir, output_suffix, git_tag, package): """ Converts `package` (*) into a tuple of: pkg_name (without leading 'r-') location (in a subdir of output_dir - may not exist - or at GitHub) old_git_rev (from existing metadata, so corresponds to the *old* version) metadata or None (if a recipe does *not* already exist) (*) `package` could be: 1. A package name beginning (or not) with 'r-' 2. A GitHub URL 3. A relative path to a recipe from output_dir 4. An absolute path to a recipe (fatal unless in the output_dir hierarchy) 5. Any of the above ending (or not) in sep or '/' So this function cleans all that up: Some packages may be from GitHub but we'd like the user not to have to worry about that on the command-line (for pre-existing recipes). Also, we may want to get version information from them (or existing metadata to merge) so lets load *all* existing recipes (later we will add or replace this metadata with any that we create). """ if isfile(package): return None print("Parsing input package %s:" % package) package = strip_end(package, '/') package = strip_end(package, sep) if 'github.com' in package: package = strip_end(package, '.git') pkg_name = basename(package).lower() pkg_name = strip_end(pkg_name, '-feedstock') if output_suffix: pkg_name = strip_end(pkg_name, output_suffix) if pkg_name.startswith('r-'): pkg_name = pkg_name[2:] if isabs(package): commp = commonprefix((package, output_dir)) if commp != output_dir: raise RuntimeError( "package %s specified with abs path outside of output-dir %s" % (package, output_dir)) location = package existing_location = existing_recipe_dir(output_dir, output_suffix, 'r-' + pkg_name) elif 'github.com' in package: location = package existing_location = existing_recipe_dir(output_dir, output_suffix, 'r-' + pkg_name) else: location = existing_location = existing_recipe_dir( output_dir, output_suffix, package) if existing_location: try: m = metadata.MetaData(existing_location) except: # Happens when the folder exists but contains no recipe. m = None else: m = None # It can still be the case that a package without 'github.com' in the location does really # come from there, for that we need to inspect the existing metadata's source/git_url. old_git_rev = git_tag if location and m and 'github.com' not in location: git_url = m.get_value('source/git_url', '') if 'github.com' in git_url: location = git_url old_git_rev = m.get_value('source/git_rev', None) new_location = join(output_dir, 'r-' + pkg_name + output_suffix) print(".. name: %s location: %s new_location: %s" % (pkg_name, location, new_location)) return dict({ 'pkg-name': pkg_name, 'location': location, 'old-git-rev': old_git_rev, 'old-metadata': m, 'new-location': new_location })