def get_repository(args, name): """Returns a Repo object that will allow us to determine the path where the new package file should be created. Args: args (argparse.Namespace): The arguments given to ``spack create`` name (str): The name of the package to create Returns: spack.repo.Repo: A Repo object capable of determining the path to the package file """ spec = Spec(name) # Figure out namespace for spec if spec.namespace and args.namespace and spec.namespace != args.namespace: tty.die("Namespaces '{0}' and '{1}' do not match.".format( spec.namespace, args.namespace)) if not spec.namespace and args.namespace: spec.namespace = args.namespace # Figure out where the new package should live repo_path = args.repo if repo_path is not None: repo = spack.repo.Repo(repo_path) if spec.namespace and spec.namespace != repo.namespace: tty.die("Can't create package with namespace {0} in repo with " "namespace {1}".format(spec.namespace, repo.namespace)) else: if spec.namespace: repo = spack.repo.path.get_repo(spec.namespace, None) if not repo: tty.die("Unknown namespace: '{0}'".format(spec.namespace)) else: repo = spack.repo.path.first_repo() # Set the namespace on the spec if it's not there already if not spec.namespace: spec.namespace = repo.namespace return repo
def get_repository(args, name): """Returns a Repo object that will allow us to determine the path where the new package file should be created. Args: args (argparse.Namespace): The arguments given to ``spack create`` name (str): The name of the package to create Returns: Repo: A Repo object capable of determining the path to the package file """ spec = Spec(name) # Figure out namespace for spec if spec.namespace and args.namespace and spec.namespace != args.namespace: tty.die("Namespaces '{0}' and '{1}' do not match.".format( spec.namespace, args.namespace)) if not spec.namespace and args.namespace: spec.namespace = args.namespace # Figure out where the new package should live repo_path = args.repo if repo_path is not None: repo = Repo(repo_path) if spec.namespace and spec.namespace != repo.namespace: tty.die("Can't create package with namespace {0} in repo with " "namespace {0}".format(spec.namespace, repo.namespace)) else: if spec.namespace: repo = spack.repo.get_repo(spec.namespace, None) if not repo: tty.die("Unknown namespace: '{0}'".format(spec.namespace)) else: repo = spack.repo.first_repo() # Set the namespace on the spec if it's not there already if not spec.namespace: spec.namespace = repo.namespace return repo