def verify_git_repo(git_dir, git_url, expected_rev='HEAD'): env = os.environ.copy() if not expected_rev: return False env['GIT_DIR'] = git_dir try: # Verify current commit matches expected commit current_commit = subprocess.check_output(["git", "log", "-n1", "--format=%H"], env=env, stderr=subprocess.STDOUT) current_commit = current_commit.decode('utf-8') expected_tag_commit = subprocess.check_output(["git", "log", "-n1", "--format=%H", expected_rev], env=env, stderr=subprocess.STDOUT) expected_tag_commit = expected_tag_commit.decode('utf-8') if current_commit != expected_tag_commit: return False # Verify correct remote url. Need to find the git cache directory, # and check the remote from there. cache_details = subprocess.check_output(["git", "remote", "-v"], env=env, stderr=subprocess.STDOUT) cache_details = cache_details.decode('utf-8') cache_dir = cache_details.split('\n')[0].split()[1] if not isinstance(cache_dir, str): # On Windows, subprocess env can't handle unicode. cache_dir = cache_dir.encode(sys.getfilesystemencoding() or 'utf-8') remote_details = subprocess.check_output(["git", "--git-dir", cache_dir, "remote", "-v"], env=env, stderr=subprocess.STDOUT) remote_details = remote_details.decode('utf-8') remote_url = remote_details.split('\n')[0].split()[1] # on windows, remote URL comes back to us as cygwin or msys format. Python doesn't # know how to normalize it. Need to convert it to a windows path. if sys.platform == 'win32' and remote_url.startswith('/'): remote_url = utils.convert_unix_path_to_win(git_url) if os.path.exists(remote_url): # Local filepaths are allowed, but make sure we normalize them remote_url = normpath(remote_url) # If the current source directory in conda-bld/work doesn't match the user's # metadata git_url or git_rev, then we aren't looking at the right source. if remote_url.lower() != git_url.lower(): logging.debug("\nremote does not match git_url\n") logging.debug("Remote: " + remote_url.lower() + "\n") logging.debug("git_url: " + git_url.lower() + "\n") return False except subprocess.CalledProcessError as error: logging.warn("Error obtaining git information. Error was: ") logging.warn(error) return False return True
def meta_vars(meta, config): d = {} for var_name in ensure_list(meta.get_value('build/script_env', [])): value = os.getenv(var_name) if value is None: warnings.warn( "The environment variable '%s' is undefined." % var_name, UserWarning ) else: d[var_name] = value git_dir = join(config.work_dir, '.git') hg_dir = join(config.work_dir, '.hg') if not isinstance(git_dir, str): # On Windows, subprocess env can't handle unicode. git_dir = git_dir.encode(sys.getfilesystemencoding() or 'utf-8') if external.find_executable('git', config.build_prefix) and os.path.exists(git_dir): git_url = meta.get_value('source/git_url') if os.path.exists(git_url): if sys.platform == 'win32': git_url = utils.convert_unix_path_to_win(git_url) # If git_url is a relative path instead of a url, convert it to an abspath git_url = normpath(join(meta.path, git_url)) _x = False if git_url: _x = verify_git_repo(git_dir, git_url, config.git_commits_since_tag, config.debug, meta.get_value('source/git_rev', 'HEAD')) if _x or meta.get_value('source/path'): d.update(get_git_info(git_dir, config.debug)) elif external.find_executable('hg', config.build_prefix) and os.path.exists(hg_dir): d.update(get_hg_build_info(hg_dir)) # use `get_value` to prevent early exit while name is still unresolved during rendering d['PKG_NAME'] = meta.get_value('package/name') d['PKG_VERSION'] = meta.version() d['PKG_BUILDNUM'] = str(meta.build_number() or 0) if meta.final: d['PKG_BUILD_STRING'] = str(meta.build_id()) d['RECIPE_DIR'] = (meta.path if meta.path else meta.meta.get('extra', {}).get('parent_recipe', {}).get('path', '')) return d
def meta_vars(meta, config): d = {} for var_name in ensure_list(meta.get_value('build/script_env', [])): value = os.getenv(var_name) if value is None: warnings.warn( "The environment variable '%s' is undefined." % var_name, UserWarning) else: d[var_name] = value git_dir = join(config.work_dir, '.git') hg_dir = join(config.work_dir, '.hg') if not isinstance(git_dir, str): # On Windows, subprocess env can't handle unicode. git_dir = git_dir.encode(sys.getfilesystemencoding() or 'utf-8') if external.find_executable( 'git', config.build_prefix) and os.path.exists(git_dir): git_url = meta.get_value('source/git_url') if os.path.exists(git_url): if sys.platform == 'win32': git_url = utils.convert_unix_path_to_win(git_url) # If git_url is a relative path instead of a url, convert it to an abspath git_url = normpath(join(meta.path, git_url)) _x = False if git_url: _x = verify_git_repo(git_dir, git_url, config, meta.get_value('source/git_rev', 'HEAD')) if _x or meta.get_value('source/path'): d.update(get_git_info(git_dir, config)) elif external.find_executable( 'hg', config.build_prefix) and os.path.exists(hg_dir): d.update(get_hg_build_info(hg_dir)) # use `get_value` to prevent early exit while name is still unresolved during rendering d['PKG_NAME'] = meta.get_value('package/name') d['PKG_VERSION'] = meta.version() d['PKG_BUILDNUM'] = str(meta.build_number()) d['PKG_BUILD_STRING'] = str(meta.build_id()) d['RECIPE_DIR'] = meta.path return d
def meta_vars(meta, config): d = {} for var_name in meta.get_value('build/script_env', []): value = os.getenv(var_name) if value is None: warnings.warn( "The environment variable '%s' is undefined." % var_name, UserWarning ) else: d[var_name] = value git_dir = join(source.get_dir(config), '.git') hg_dir = join(source.get_dir(config), '.hg') if not isinstance(git_dir, str): # On Windows, subprocess env can't handle unicode. git_dir = git_dir.encode(sys.getfilesystemencoding() or 'utf-8') if external.find_executable('git', config.build_prefix) and os.path.exists(git_dir): git_url = meta.get_value('source/git_url') if os.path.exists(git_url): if sys.platform == 'win32': git_url = utils.convert_unix_path_to_win(git_url) # If git_url is a relative path instead of a url, convert it to an abspath git_url = normpath(join(meta.path, git_url)) _x = False if git_url: _x = verify_git_repo(git_dir, git_url, config, meta.get_value('source/git_rev', 'HEAD')) if _x or meta.get_value('source/path'): d.update(get_git_info(git_dir, config)) elif external.find_executable('hg', config.build_prefix) and os.path.exists(hg_dir): d.update(get_hg_build_info(hg_dir)) d['PKG_NAME'] = meta.name() d['PKG_VERSION'] = meta.version() d['PKG_BUILDNUM'] = str(meta.build_number()) d['PKG_BUILD_STRING'] = str(meta.build_id()) d['RECIPE_DIR'] = meta.path return d
def meta_vars(meta, config): d = {} for var_name in ensure_list(meta.get_value("build/script_env", [])): value = os.getenv(var_name) if value is None: warnings.warn("The environment variable '%s' is undefined." % var_name, UserWarning) else: d[var_name] = value git_dir = join(config.work_dir, ".git") hg_dir = join(config.work_dir, ".hg") if not isinstance(git_dir, str): # On Windows, subprocess env can't handle unicode. git_dir = git_dir.encode(sys.getfilesystemencoding() or "utf-8") if external.find_executable("git", config.build_prefix) and os.path.exists(git_dir): git_url = meta.get_value("source/git_url") if os.path.exists(git_url): if sys.platform == "win32": git_url = utils.convert_unix_path_to_win(git_url) # If git_url is a relative path instead of a url, convert it to an abspath git_url = normpath(join(meta.path, git_url)) _x = False if git_url: _x = verify_git_repo(git_dir, git_url, config, meta.get_value("source/git_rev", "HEAD")) if _x or meta.get_value("source/path"): d.update(get_git_info(git_dir, config)) elif external.find_executable("hg", config.build_prefix) and os.path.exists(hg_dir): d.update(get_hg_build_info(hg_dir)) # use `get_value` to prevent early exit while name is still unresolved during rendering d["PKG_NAME"] = meta.get_value("package/name") d["PKG_VERSION"] = meta.version() d["PKG_BUILDNUM"] = str(meta.build_number()) d["PKG_BUILD_STRING"] = str(meta.build_id()) d["RECIPE_DIR"] = meta.path return d
def git_mirror_checkout_recursive(git, mirror_dir, checkout_dir, git_url, config, git_ref=None, git_depth=-1, is_top_level=True): """ Mirror (and checkout) a Git repository recursively. It's not possible to use `git submodule` on a bare repository, so the checkout must be done before we know which submodules there are. Worse, submodules can be identified by using either absolute URLs or relative paths. If relative paths are used those need to be relocated upon mirroring, but you could end up with `../../../../blah` and in that case conda-build could be tricked into writing to the root of the drive and overwriting the system folders unless steps are taken to prevent that. """ if config.verbose: stdout = None stderr = None else: FNULL = open(os.devnull, 'w') stdout = FNULL stderr = FNULL if not mirror_dir.startswith(config.git_cache + os.sep): sys.exit("Error: Attempting to mirror to %s which is outside of GIT_CACHE %s" % (mirror_dir, config.git_cache)) # This is necessary for Cygwin git and m2-git, although it is fixed in newer MSYS2. git_mirror_dir = convert_path_for_cygwin_or_msys2(git, mirror_dir) git_checkout_dir = convert_path_for_cygwin_or_msys2(git, checkout_dir) if not isdir(os.path.dirname(mirror_dir)): os.makedirs(os.path.dirname(mirror_dir)) if isdir(mirror_dir): if git_ref != 'HEAD': check_call_env([git, 'fetch'], cwd=mirror_dir, stdout=stdout, stderr=stderr) else: # Unlike 'git clone', fetch doesn't automatically update the cache's HEAD, # So here we explicitly store the remote HEAD in the cache's local refs/heads, # and then explicitly set the cache's HEAD. # This is important when the git repo is a local path like "git_url: ../", # but the user is working with a branch other than 'master' without # explicitly providing git_rev. check_call_env([git, 'fetch', 'origin', '+HEAD:_conda_cache_origin_head'], cwd=mirror_dir, stdout=stdout, stderr=stderr) check_call_env([git, 'symbolic-ref', 'HEAD', 'refs/heads/_conda_cache_origin_head'], cwd=mirror_dir, stdout=stdout, stderr=stderr) else: args = [git, 'clone', '--mirror'] if git_depth > 0: args += ['--depth', str(git_depth)] try: check_call_env(args + [git_url, git_mirror_dir], stdout=stdout, stderr=stderr) except CalledProcessError: # on windows, remote URL comes back to us as cygwin or msys format. Python doesn't # know how to normalize it. Need to convert it to a windows path. if sys.platform == 'win32' and git_url.startswith('/'): git_url = convert_unix_path_to_win(git_url) if os.path.exists(git_url): # Local filepaths are allowed, but make sure we normalize them git_url = normpath(git_url) check_call_env(args + [git_url, git_mirror_dir], stdout=stdout, stderr=stderr) assert isdir(mirror_dir) # Now clone from mirror_dir into checkout_dir. check_call_env([git, 'clone', git_mirror_dir, git_checkout_dir], stdout=stdout, stderr=stderr) if is_top_level: checkout = git_ref if git_url.startswith('.'): output = check_output_env([git, "rev-parse", checkout], stdout=stdout, stderr=stderr) checkout = output.decode('utf-8') if config.verbose: print('checkout: %r' % checkout) if checkout: check_call_env([git, 'checkout', checkout], cwd=checkout_dir, stdout=stdout, stderr=stderr) # submodules may have been specified using relative paths. # Those paths are relative to git_url, and will not exist # relative to mirror_dir, unless we do some work to make # it so. try: submodules = check_output_env([git, 'config', '--file', '.gitmodules', '--get-regexp', 'url'], stderr=stdout, cwd=checkout_dir) submodules = submodules.decode('utf-8').splitlines() except CalledProcessError: submodules = [] for submodule in submodules: matches = git_submod_re.match(submodule) if matches and matches.group(2)[0] == '.': submod_name = matches.group(1) submod_rel_path = matches.group(2) submod_url = urljoin(git_url + '/', submod_rel_path) submod_mirror_dir = os.path.normpath( os.path.join(mirror_dir, submod_rel_path)) if config.verbose: print('Relative submodule %s found: url is %s, submod_mirror_dir is %s' % ( submod_name, submod_url, submod_mirror_dir)) with TemporaryDirectory() as temp_checkout_dir: git_mirror_checkout_recursive(git, submod_mirror_dir, temp_checkout_dir, submod_url, config, git_ref, git_depth, False) if is_top_level: # Now that all relative-URL-specified submodules are locally mirrored to # relatively the same place we can go ahead and checkout the submodules. check_call_env([git, 'submodule', 'update', '--init', '--recursive'], cwd=checkout_dir, stdout=stdout, stderr=stderr) git_info(config) if not config.verbose: FNULL.close()
def verify_git_repo(git_exe, git_dir, git_url, git_commits_since_tag, debug=False, expected_rev='HEAD'): env = os.environ.copy() log = utils.get_logger(__name__) if debug: stderr = None else: FNULL = open(os.devnull, 'w') stderr = FNULL if not expected_rev: return False OK = True env['GIT_DIR'] = git_dir try: # Verify current commit (minus our locally applied patches) matches expected commit current_commit = utils.check_output_env([ git_exe, "log", "-n1", "--format=%H", "HEAD" + "^" * git_commits_since_tag ], env=env, stderr=stderr) current_commit = current_commit.decode('utf-8') expected_tag_commit = utils.check_output_env( [git_exe, "log", "-n1", "--format=%H", expected_rev], env=env, stderr=stderr) expected_tag_commit = expected_tag_commit.decode('utf-8') if current_commit != expected_tag_commit: return False # Verify correct remote url. Need to find the git cache directory, # and check the remote from there. cache_details = utils.check_output_env([git_exe, "remote", "-v"], env=env, stderr=stderr) cache_details = cache_details.decode('utf-8') cache_dir = cache_details.split('\n')[0].split()[1] if not isinstance(cache_dir, str): # On Windows, subprocess env can't handle unicode. cache_dir = cache_dir.encode(sys.getfilesystemencoding() or 'utf-8') try: remote_details = utils.check_output_env( [git_exe, "--git-dir", cache_dir, "remote", "-v"], env=env, stderr=stderr) except subprocess.CalledProcessError: if sys.platform == 'win32' and cache_dir.startswith('/'): cache_dir = utils.convert_unix_path_to_win(cache_dir) remote_details = utils.check_output_env( [git_exe, "--git-dir", cache_dir, "remote", "-v"], env=env, stderr=stderr) remote_details = remote_details.decode('utf-8') remote_url = remote_details.split('\n')[0].split()[1] # on windows, remote URL comes back to us as cygwin or msys format. Python doesn't # know how to normalize it. Need to convert it to a windows path. if sys.platform == 'win32' and remote_url.startswith('/'): remote_url = utils.convert_unix_path_to_win(git_url) if os.path.exists(remote_url): # Local filepaths are allowed, but make sure we normalize them remote_url = normpath(remote_url) # If the current source directory in conda-bld/work doesn't match the user's # metadata git_url or git_rev, then we aren't looking at the right source. if not os.path.isdir( remote_url) and remote_url.lower() != git_url.lower(): log.debug("remote does not match git_url") log.debug("Remote: " + remote_url.lower()) log.debug("git_url: " + git_url.lower()) OK = False except subprocess.CalledProcessError as error: log.debug( "Error obtaining git information in verify_git_repo. Error was: ") log.debug(str(error)) OK = False finally: if not debug: FNULL.close() return OK
def meta_vars(meta, skip_build_id=False): d = {} for var_name in ensure_list(meta.get_value('build/script_env', [])): if '=' in var_name: value = var_name.split('=')[-1] var_name = var_name.split('=')[0] else: value = os.getenv(var_name) if value is None: warnings.warn( "The environment variable '%s' is undefined." % var_name, UserWarning) else: d[var_name] = value warnings.warn( "The environment variable '%s' is being passed through with value '%s'. " "If you are splitting build and test phases with --no-test, please ensure " "that this value is also set similarly at test time." % (var_name, "<hidden>" if meta.config.suppress_variables else value), UserWarning) folder = meta.get_value('source/0/folder', '') repo_dir = join(meta.config.work_dir, folder) git_dir = join(repo_dir, '.git') hg_dir = join(repo_dir, '.hg') if not isinstance(git_dir, str): # On Windows, subprocess env can't handle unicode. git_dir = git_dir.encode(sys.getfilesystemencoding() or 'utf-8') git_exe = external.find_executable('git', meta.config.build_prefix) if git_exe and os.path.exists(git_dir): # We set all 'source' metavars using the FIRST source entry in meta.yaml. git_url = meta.get_value('source/0/git_url') if os.path.exists(git_url): if sys.platform == 'win32': git_url = utils.convert_unix_path_to_win(git_url) # If git_url is a relative path instead of a url, convert it to an abspath git_url = normpath(join(meta.path, git_url)) _x = False if git_url: _x = verify_git_repo(git_exe, git_dir, git_url, meta.config.git_commits_since_tag, meta.config.debug, meta.get_value('source/0/git_rev', 'HEAD')) if _x or meta.get_value('source/0/path'): d.update(get_git_info(git_exe, git_dir, meta.config.debug)) elif external.find_executable( 'hg', meta.config.build_prefix) and os.path.exists(hg_dir): d.update(get_hg_build_info(hg_dir)) # use `get_value` to prevent early exit while name is still unresolved during rendering d['PKG_NAME'] = meta.get_value('package/name') d['PKG_VERSION'] = meta.version() d['PKG_BUILDNUM'] = str(meta.build_number() or 0) if meta.final and not skip_build_id: d['PKG_BUILD_STRING'] = str(meta.build_id()) d['PKG_HASH'] = meta.hash_dependencies() else: d['PKG_BUILD_STRING'] = 'placeholder' d['PKG_HASH'] = '1234567' d['RECIPE_DIR'] = meta.path return d
def verify_git_repo(git_dir, git_url, config, expected_rev="HEAD"): env = os.environ.copy() if config.verbose: stderr = None else: FNULL = open(os.devnull, "w") stderr = FNULL log.setLevel(logging.ERROR) if not expected_rev: return False OK = True env["GIT_DIR"] = git_dir try: # Verify current commit matches expected commit current_commit = subprocess.check_output(["git", "log", "-n1", "--format=%H"], env=env, stderr=stderr) current_commit = current_commit.decode("utf-8") expected_tag_commit = subprocess.check_output( ["git", "log", "-n1", "--format=%H", expected_rev], env=env, stderr=stderr ) expected_tag_commit = expected_tag_commit.decode("utf-8") if current_commit != expected_tag_commit: return False # Verify correct remote url. Need to find the git cache directory, # and check the remote from there. cache_details = subprocess.check_output(["git", "remote", "-v"], env=env, stderr=stderr) cache_details = cache_details.decode("utf-8") cache_dir = cache_details.split("\n")[0].split()[1] if not isinstance(cache_dir, str): # On Windows, subprocess env can't handle unicode. cache_dir = cache_dir.encode(sys.getfilesystemencoding() or "utf-8") try: remote_details = subprocess.check_output( ["git", "--git-dir", cache_dir, "remote", "-v"], env=env, stderr=stderr ) except subprocess.CalledProcessError: if sys.platform == "win32" and cache_dir.startswith("/"): cache_dir = utils.convert_unix_path_to_win(cache_dir) remote_details = subprocess.check_output( ["git", "--git-dir", cache_dir, "remote", "-v"], env=env, stderr=stderr ) remote_details = remote_details.decode("utf-8") remote_url = remote_details.split("\n")[0].split()[1] # on windows, remote URL comes back to us as cygwin or msys format. Python doesn't # know how to normalize it. Need to convert it to a windows path. if sys.platform == "win32" and remote_url.startswith("/"): remote_url = utils.convert_unix_path_to_win(git_url) if os.path.exists(remote_url): # Local filepaths are allowed, but make sure we normalize them remote_url = normpath(remote_url) # If the current source directory in conda-bld/work doesn't match the user's # metadata git_url or git_rev, then we aren't looking at the right source. if not os.path.isdir(remote_url) and remote_url.lower() != git_url.lower(): log.debug("remote does not match git_url") log.debug("Remote: " + remote_url.lower()) log.debug("git_url: " + git_url.lower()) OK = False except subprocess.CalledProcessError as error: log.warn("Error obtaining git information in verify_git_repo. Error was: ") log.warn(str(error)) OK = False finally: if not config.verbose: FNULL.close() return OK
def verify_git_repo(git_dir, git_url, expected_rev='HEAD'): env = os.environ.copy() if not expected_rev: return False env['GIT_DIR'] = git_dir try: # Verify current commit matches expected commit current_commit = subprocess.check_output( ["git", "log", "-n1", "--format=%H"], env=env, stderr=subprocess.STDOUT) current_commit = current_commit.decode('utf-8') expected_tag_commit = subprocess.check_output( ["git", "log", "-n1", "--format=%H", expected_rev], env=env, stderr=subprocess.STDOUT) expected_tag_commit = expected_tag_commit.decode('utf-8') if current_commit != expected_tag_commit: return False # Verify correct remote url. Need to find the git cache directory, # and check the remote from there. cache_details = subprocess.check_output(["git", "remote", "-v"], env=env, stderr=subprocess.STDOUT) cache_details = cache_details.decode('utf-8') cache_dir = cache_details.split('\n')[0].split()[1] if not isinstance(cache_dir, str): # On Windows, subprocess env can't handle unicode. cache_dir = cache_dir.encode(sys.getfilesystemencoding() or 'utf-8') remote_details = subprocess.check_output( ["git", "--git-dir", cache_dir, "remote", "-v"], env=env, stderr=subprocess.STDOUT) remote_details = remote_details.decode('utf-8') remote_url = remote_details.split('\n')[0].split()[1] # on windows, remote URL comes back to us as cygwin or msys format. Python doesn't # know how to normalize it. Need to convert it to a windows path. if sys.platform == 'win32' and remote_url.startswith('/'): remote_url = utils.convert_unix_path_to_win(git_url) if os.path.exists(remote_url): # Local filepaths are allowed, but make sure we normalize them remote_url = normpath(remote_url) # If the current source directory in conda-bld/work doesn't match the user's # metadata git_url or git_rev, then we aren't looking at the right source. if remote_url.lower() != git_url.lower(): logging.debug("\nremote does not match git_url\n") logging.debug("Remote: " + remote_url.lower() + "\n") logging.debug("git_url: " + git_url.lower() + "\n") return False except subprocess.CalledProcessError as error: logging.warn("Error obtaining git information. Error was: ") logging.warn(error) return False return True
def verify_git_repo(git_dir, git_url, git_commits_since_tag, debug=False, expected_rev='HEAD'): env = os.environ.copy() log = utils.get_logger(__name__) if debug: stderr = None else: FNULL = open(os.devnull, 'w') stderr = FNULL if not expected_rev: return False OK = True env['GIT_DIR'] = git_dir try: # Verify current commit (minus our locally applied patches) matches expected commit current_commit = utils.check_output_env(["git", "log", "-n1", "--format=%H", "HEAD" + "^" * git_commits_since_tag], env=env, stderr=stderr) current_commit = current_commit.decode('utf-8') expected_tag_commit = utils.check_output_env(["git", "log", "-n1", "--format=%H", expected_rev], env=env, stderr=stderr) expected_tag_commit = expected_tag_commit.decode('utf-8') if current_commit != expected_tag_commit: return False # Verify correct remote url. Need to find the git cache directory, # and check the remote from there. cache_details = utils.check_output_env(["git", "remote", "-v"], env=env, stderr=stderr) cache_details = cache_details.decode('utf-8') cache_dir = cache_details.split('\n')[0].split()[1] if not isinstance(cache_dir, str): # On Windows, subprocess env can't handle unicode. cache_dir = cache_dir.encode(sys.getfilesystemencoding() or 'utf-8') try: remote_details = utils.check_output_env(["git", "--git-dir", cache_dir, "remote", "-v"], env=env, stderr=stderr) except subprocess.CalledProcessError: if sys.platform == 'win32' and cache_dir.startswith('/'): cache_dir = utils.convert_unix_path_to_win(cache_dir) remote_details = utils.check_output_env(["git", "--git-dir", cache_dir, "remote", "-v"], env=env, stderr=stderr) remote_details = remote_details.decode('utf-8') remote_url = remote_details.split('\n')[0].split()[1] # on windows, remote URL comes back to us as cygwin or msys format. Python doesn't # know how to normalize it. Need to convert it to a windows path. if sys.platform == 'win32' and remote_url.startswith('/'): remote_url = utils.convert_unix_path_to_win(git_url) if os.path.exists(remote_url): # Local filepaths are allowed, but make sure we normalize them remote_url = normpath(remote_url) # If the current source directory in conda-bld/work doesn't match the user's # metadata git_url or git_rev, then we aren't looking at the right source. if not os.path.isdir(remote_url) and remote_url.lower() != git_url.lower(): log.debug("remote does not match git_url") log.debug("Remote: " + remote_url.lower()) log.debug("git_url: " + git_url.lower()) OK = False except subprocess.CalledProcessError as error: log.debug("Error obtaining git information in verify_git_repo. Error was: ") log.debug(str(error)) OK = False finally: if not debug: FNULL.close() return OK
def meta_vars(meta, config, skip_build_id=False): d = {} for var_name in ensure_list(meta.get_value('build/script_env', [])): value = os.getenv(var_name) if value is None: warnings.warn( "The environment variable '%s' is undefined." % var_name, UserWarning ) else: d[var_name] = value warnings.warn( "The environment variable '%s' is being passed through with value %s. " "If you are splitting build and test phases with --no-test, please ensure " "that this value is also set similarly at test time." % (var_name, value), UserWarning ) folder = meta.get_value('source/0/folder', '') repo_dir = join(config.work_dir, folder) git_dir = join(repo_dir, '.git') hg_dir = join(repo_dir, '.hg') if not isinstance(git_dir, str): # On Windows, subprocess env can't handle unicode. git_dir = git_dir.encode(sys.getfilesystemencoding() or 'utf-8') git_exe = external.find_executable('git', config.build_prefix) if git_exe and os.path.exists(git_dir): # We set all 'source' metavars using the FIRST source entry in meta.yaml. git_url = meta.get_value('source/0/git_url') if os.path.exists(git_url): if sys.platform == 'win32': git_url = utils.convert_unix_path_to_win(git_url) # If git_url is a relative path instead of a url, convert it to an abspath git_url = normpath(join(meta.path, git_url)) _x = False if git_url: _x = verify_git_repo(git_exe, git_dir, git_url, config.git_commits_since_tag, config.debug, meta.get_value('source/0/git_rev', 'HEAD')) if _x or meta.get_value('source/0/path'): d.update(get_git_info(git_exe, git_dir, config.debug)) elif external.find_executable('hg', config.build_prefix) and os.path.exists(hg_dir): d.update(get_hg_build_info(hg_dir)) # use `get_value` to prevent early exit while name is still unresolved during rendering d['PKG_NAME'] = meta.get_value('package/name') d['PKG_VERSION'] = meta.version() d['PKG_BUILDNUM'] = str(meta.build_number() or 0) if meta.final and not skip_build_id: d['PKG_BUILD_STRING'] = str(meta.build_id()) d['PKG_HASH'] = meta.hash_dependencies() else: d['PKG_BUILD_STRING'] = 'placeholder' d['PKG_HASH'] = '1234567' d['RECIPE_DIR'] = (meta.path if meta.path else meta.meta.get('extra', {}).get('parent_recipe', {}).get('path', '')) return d