Commit bc9651d2 authored by Ben Couturier's avatar Ben Couturier
Browse files

Moved factory to class

parent f7a1dd52
......@@ -36,7 +36,7 @@ def stack_filename(repository, name):
return Path(repository) / f"{name}.yml"
def load_stack_file(filename):
def _load_stack_file(filename):
""" Load stack information by name from the specified repository """
with open(filename) as file:
info = load(file.read(), STACK_SCHEMA)
......@@ -58,11 +58,11 @@ def incomplete_stacks(stack_paths, siteroot):
for path in stack_paths:
if os.path.isdir(path):
for _, filename in _list_stacks_in_dir(path):
s = load_stack(filename, siteroot)
s = Stack.load(filename, siteroot)
if s.has_missing_projects():
inc_stacks.append(s)
else:
s = load_stack(filename, siteroot)
s = Stack.load(filename, siteroot)
if s.has_missing_projects():
inc_stacks.append(s)
......@@ -71,7 +71,7 @@ def incomplete_stacks(stack_paths, siteroot):
def list_stacks_to_release(stack_paths, siteroot):
""" Generate the JSON file with the stacks that should be released """
# 1. Get the diff between what should be released, and what is in the repository
# 1. Get the list of incomplete stacks
inc_stacks = incomplete_stacks(stack_paths, siteroot)
# 2. Iterate to generate the stack in the exported format
......@@ -101,21 +101,21 @@ def list_stacks_to_release(stack_paths, siteroot):
return sorted([d for d, _ in tobuild], key=lambda d: d["name"])
def load_stack(filename, siteroot):
""" Factory method returning a stack object of the correct type """
info = load_stack_file(filename)
stack = None
stack_type = info["type"].lower()
if stack_type == "lhcbcmake":
stack = LHCbClassicStack(siteroot, info, "cmake")
elif stack_type == "cmt":
stack = LHCbClassicStack(siteroot, info, "cmt")
else:
raise NotImplementedError(f"Stack type {info['type']} not implemented")
return stack
class Stack:
@classmethod
def load(cls, filename, siteroot):
""" Factory method returning a stack object of the correct type """
info = _load_stack_file(filename)
stack = None
stack_type = info["type"].lower()
if stack_type == "lhcbcmake":
stack = LHCbClassicStack(siteroot, info, "cmake")
elif stack_type == "cmt":
stack = LHCbClassicStack(siteroot, info, "cmt")
else:
raise NotImplementedError(f"Stack type {info['type']} not implemented")
return stack
def __init__(self, siteroot, stack_info):
self.siteroot_path = Path(siteroot)
self.info = stack_info
......
......@@ -37,7 +37,7 @@ TEST_PLATFORM = "x86_64-centos7-gcc9-opt"
def lhcb_install_area(tmp_path):
""" Create a fake install with a missing platform and missing projects """
lhcb_dir = tmp_path
s = lhcbstacks.load_stack(
s = lhcbstacks.Stack.load(
lhcbstacks.stack_filename(STACK_DIR, TEST_STACK), lhcb_dir
)
......@@ -55,14 +55,14 @@ def lhcb_install_area(tmp_path):
def test_load_info():
stack_info = lhcbstacks.load_stack_file(
stack_info = lhcbstacks._load_stack_file(
lhcbstacks.stack_filename(STACK_DIR, TEST_STACK)
)
assert stack_info["type"] == "lhcbcmake"
def test_load_stack():
a = lhcbstacks.load_stack(
a = lhcbstacks.Stack.load(
lhcbstacks.stack_filename(STACK_DIR, TEST_STACK), LHCBSITEROOT
)
ps = [p for (p, _, _) in a.project_paths()]
......@@ -74,7 +74,7 @@ def test_load_stack():
def test_list_platforms():
a = lhcbstacks.load_stack(
a = lhcbstacks.Stack.load(
lhcbstacks.stack_filename(STACK_DIR, TEST_STACK), LHCBSITEROOT
)
assert a.platforms() == PLATFORMS
......@@ -86,7 +86,7 @@ def test_list_stacks_in_dir():
def test_list_binary_paths():
a = lhcbstacks.load_stack(
a = lhcbstacks.Stack.load(
lhcbstacks.stack_filename(STACK_DIR, TEST_STACK), LHCBSITEROOT
)
dv = [p for p in a.binary_paths()[TEST_PLATFORM] if TEST_PROJECT.upper() in str(p)]
......@@ -97,7 +97,7 @@ def test_list_binary_paths():
def test_missing(lhcb_install_area):
a = lhcbstacks.load_stack(
a = lhcbstacks.Stack.load(
lhcbstacks.stack_filename(STACK_DIR, TEST_STACK), lhcb_install_area
)
missing = a.missing_projects()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment