Skip to content

Commit

Permalink
Merge pull request #72 from cpenv/remove-real-name
Browse files Browse the repository at this point in the history
Remove extraneous real_name attribute on modules.
  • Loading branch information
danbradham committed Sep 11, 2023
2 parents 951dc80 + 1f46fba commit 767b0eb
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions cpenv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def clone(module, from_repo=None, where=None, overwrite=False):

module = module_spec.repo.download(
module_spec,
where=paths.normalize(where or ".", module_spec.real_name),
where=paths.normalize(where or ".", module_spec.qual_name),
overwrite=overwrite,
)

Expand Down Expand Up @@ -286,7 +286,7 @@ def add_active_module(module):
if module not in _active_modules:
_active_modules.append(module)

module_names = os.pathsep.join([m.real_name for m in _active_modules])
module_names = os.pathsep.join([m.qual_name for m in _active_modules])
os.environ["CPENV_ACTIVE_MODULES"] = str(module_names)


Expand All @@ -300,7 +300,7 @@ def remove_active_module(module):
if module in _active_modules:
_active_modules.remove(module)

module_names = os.pathsep.join([m.real_name for m in _active_modules])
module_names = os.pathsep.join([m.qual_name for m in _active_modules])
os.environ["CPENV_ACTIVE_MODULES"] = str(module_names)


Expand Down
6 changes: 3 additions & 3 deletions cpenv/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def start_resolve(self, requirements):
core.echo()

def resolve_requirement(self, requirement, module_spec):
core.echo(" %s - %s" % (module_spec.real_name, module_spec.path))
core.echo(" %s - %s" % (module_spec.qual_name, module_spec.path))

def end_resolve(self, resolved, unresolved):
core.echo()
Expand All @@ -89,12 +89,12 @@ def start_progress(self, label, max_size, data):
if "download" in label.lower():
spec = data["module_spec"]
core.echo(" Downloading %s from %s..." % (spec.qual_name, spec.repo.name))
desc = spec.real_name
desc = spec.qual_name
elif "upload" in label.lower():
module = data["module"]
to_repo = data["to_repo"]
core.echo(" Uploading %s to %s..." % (module.qual_name, to_repo.name))
desc = module.real_name
desc = module.qual_name
else:
desc = label

Expand Down
4 changes: 2 additions & 2 deletions cpenv/cli/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def run(self, args):
core.echo("Error: Failed to resolve " + args.module)
core.exit(1)

where = paths.normalize(args.where or ".", module_spec.real_name)
where = paths.normalize(args.where or ".", module_spec.qual_name)
if os.path.isdir(where):
core.echo("Error: Directory already exists - " + where)
core.exit(1)

core.echo("- Cloning %s..." % module_spec.real_name)
core.echo("- Cloning %s..." % module_spec.qual_name)
core.echo()
try:
module = module_spec.repo.download(
Expand Down
6 changes: 3 additions & 3 deletions cpenv/cli/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run(self, args):
core.echo(
core.format_columns(
"[*] Active",
[m.real_name for m in sort_modules(active_modules)],
[m.qual_name for m in sort_modules(active_modules)],
)
)
core.echo()
Expand All @@ -59,9 +59,9 @@ def run(self, args):
module_names = []
for module in sort_modules(repo_modules):
if module in active_modules:
module_names.append("* " + module.real_name)
module_names.append("* " + module.qual_name)
else:
module_names.append(" " + module.real_name)
module_names.append(" " + module.qual_name)

if module_names:
found_modules = True
Expand Down
2 changes: 1 addition & 1 deletion cpenv/cli/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ def run(self, args):

core.echo()
core.echo("Activate your module:")
core.echo(" cpenv activate %s" % published.real_name)
core.echo(" cpenv activate %s" % published.qual_name)
core.echo()
4 changes: 2 additions & 2 deletions cpenv/cli/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run(self, args):
if not module:
core.echo("Error: %s not found..." % requirement)
core.exit(1)
core.echo(" %s - %s" % (module.real_name, module.path))
core.echo(" %s - %s" % (module.qual_name, module.path))
modules_to_remove.append(module)

core.echo()
Expand All @@ -52,7 +52,7 @@ def run(self, args):
core.echo("- Removing modules...")
core.echo()
for module in modules_to_remove:
core.echo(" " + module.real_name)
core.echo(" " + module.qual_name)
api.remove(module, from_repo)

core.echo()
Expand Down
19 changes: 5 additions & 14 deletions cpenv/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

ModuleSpec = namedtuple(
"ModuleSpec",
["name", "real_name", "qual_name", "version", "path", "repo"],
["name", "qual_name", "version", "path", "repo"],
)


Expand Down Expand Up @@ -66,8 +66,7 @@ def __init__(self, path, name=None, version=None, repo=None):
self._config = None
self._env = None

# Determine name, version, qual_name, and real_name

# Determine name, version, qual_name
if name and version:

# Use name and version if explicitly passed
Expand All @@ -92,12 +91,6 @@ def __init__(self, path, name=None, version=None, repo=None):

self.qual_name = self.name + "-" + self.version.string

base_name = os.path.basename(self.path)
if self.version.string != base_name:
self.real_name = base_name
else:
self.real_name = self.qual_name

def __eq__(self, other):
if hasattr(other, "path"):
return self.path == other.path
Expand Down Expand Up @@ -133,7 +126,6 @@ def to_spec(self, **kwargs):
name=kwargs.get("name", self.name),
path=kwargs.get("path", self.path),
qual_name=kwargs.get("qual_name", self.qual_name),
real_name=kwargs.get("real_name", self.real_name),
repo=kwargs.get("repo", self.repo),
version=kwargs.get("version", self.version),
)
Expand Down Expand Up @@ -173,7 +165,7 @@ def remove(self):
def is_active(self):
from . import api

return self.real_name in api.get_active_modules()
return self.qual_name in api.get_active_modules()

@property
def exists(self):
Expand Down Expand Up @@ -222,7 +214,7 @@ def email(self):
def environment(self):
if self._env is None:
self._env = self.config.get("environment", {})
self._env["CPENV_ACTIVE_MODULES"] = {"append": self.real_name}
self._env["CPENV_ACTIVE_MODULES"] = {"append": self.qual_name}

return self._env

Expand Down Expand Up @@ -266,7 +258,7 @@ def read_config(module_file, config_vars=None, data=None):
def sort_modules(modules, reverse=False):
"""Sort a list of Modules or ModuleSpecs by version."""

return sorted(modules, key=lambda m: (m.real_name, m.version), reverse=reverse)
return sorted(modules, key=lambda m: (m.qual_name, m.version), reverse=reverse)


def is_module(path):
Expand Down Expand Up @@ -328,7 +320,6 @@ def is_exact_match(requirement, module_spec):
name, version = parse_module_requirement(requirement)
return (
module_spec.qual_name == requirement
or module_spec.real_name == requirement
or (version and module_spec.name == name and module_spec.version == version)
)

Expand Down
1 change: 0 additions & 1 deletion cpenv/repos/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ def entity_to_module_spec(entity, repo):
)
return ModuleSpec(
name=entity["code"],
real_name=qual_name,
qual_name=qual_name,
version=version,
path=url,
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
@pytest.fixture(scope="session", autouse=True)
def setup_and_teardown():

# Clear all locally configured repositories...
for repo in cpenv.get_repos():
cpenv.remove_repo(repo)

# Setup
cpenv.set_home_path(data_path("home"))

Expand Down
4 changes: 4 additions & 0 deletions tests/test_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Local imports
import cpenv
from cpenv import paths

from . import data_path

Expand Down Expand Up @@ -41,6 +42,9 @@ def setup_module():
description="A test module",
)

def teardown_module():
paths.rmtree(data_path("modules"))


def test_LocalRepo_init():
"""Initialize a LocalRepo"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def setup_module():


def teardown_module():
paths.rmtree(data_path("modules"))
paths.rmtree(data_path("home"))
paths.rmtree(data_path("not_home"))

Expand Down

0 comments on commit 767b0eb

Please sign in to comment.