diff --git a/src/mepo/cmdline/parser.py b/src/mepo/cmdline/parser.py index 4cee79d..81f252c 100644 --- a/src/mepo/cmdline/parser.py +++ b/src/mepo/cmdline/parser.py @@ -77,6 +77,12 @@ def __init(self): choices=["naked", "prefix", "postfix"], help="Style of directory file, default: prefix, allowed options: %(choices)s", ) + init.add_argument( + "--fixture", + metavar="url", + default=None, + help="Remote URL of fixture (default: None)", + ) def __clone(self): clone = self.subparsers.add_parser( @@ -129,6 +135,12 @@ def __clone(self): choices=["off", "blobless", "treeless"], help='Style of partial clone, default: None, allowed options: %(choices)s. Off means a "normal" full git clone, blobless means cloning with "--filter=blob:none" and treeless means cloning with "--filter=tree:0". NOTE: We do *not* recommend using "treeless" as it is very aggressive and will cause problems with many git commands.', ) + clone.add_argument( + "--fixture", + metavar="url", + default=None, + help="Remote URL of fixture (default: None)", + ) def __list(self): listcomps = self.subparsers.add_parser( diff --git a/src/mepo/command/init.py b/src/mepo/command/init.py index 83d15e3..9f5c9fe 100644 --- a/src/mepo/command/init.py +++ b/src/mepo/command/init.py @@ -17,7 +17,7 @@ def run(args): else: style = None - _ = MepoState.initialize(args.registry, style) + _ = MepoState.initialize(args.registry, style, args.fixture) if not style: print(f"Initializing mepo using {args.registry}") diff --git a/src/mepo/component.py b/src/mepo/component.py index ef732ba..a49783b 100644 --- a/src/mepo/component.py +++ b/src/mepo/component.py @@ -1,7 +1,7 @@ import os import shlex -from urllib.parse import urlparse +from urllib.parse import urlparse, urljoin from .utilities import shellcmd from .utilities.version import MepoVersion @@ -55,33 +55,40 @@ def __repr__(self): f" ignore_submodules: {_ignore_submodules}" ) - def __set_original_version(self, comp_details): + def __set_original_version(self, comp_details, fixture_url): if self.fixture: - cmd_if_branch = "git symbolic-ref HEAD" - # Have to use 'if not' since 0 is a good status - if not shellcmd.run(cmd_if_branch.split(), status=True): - output = shellcmd.run(cmd_if_branch.split(), output=True).rstrip() - ver_name = output.replace("refs/heads/", "") - ver_type = "b" - is_detached = False + if fixture_url is not None: + ver_name = "UNKNOWN" + ver_type = "NOT APPLICABLE" + is_detached = "NOT APPLICABLE" else: - # On some CI systems, git is handled oddly. As such, sometimes - # tags aren't found due to shallow clones - cmd_for_tag = "git describe --tags" + cmd_if_branch = "git symbolic-ref HEAD" # Have to use 'if not' since 0 is a good status - if not shellcmd.run(cmd_for_tag.split(), status=True): - ver_name = shellcmd.run(cmd_for_tag.split(), output=True).rstrip() - ver_type = "t" - is_detached = True + if not shellcmd.run(cmd_if_branch.split(), status=True): + output = shellcmd.run(cmd_if_branch.split(), output=True).rstrip() + ver_name = output.replace("refs/heads/", "") + ver_type = "b" + is_detached = False else: - # Per internet, describe always should always work, though mepo - # will return weirdness (a grafted branch, probably a hash) - cmd_for_always = "git describe --always" - ver_name = shellcmd.run( - cmd_for_always.split(), output=True - ).rstrip() - ver_type = "h" - is_detached = True + # On some CI systems, git is handled oddly. As such, sometimes + # tags aren't found due to shallow clones + cmd_for_tag = "git describe --tags" + # Have to use 'if not' since 0 is a good status + if not shellcmd.run(cmd_for_tag.split(), status=True): + ver_name = shellcmd.run( + cmd_for_tag.split(), output=True + ).rstrip() + ver_type = "t" + is_detached = True + else: + # Per internet, describe always should always work, though mepo + # will return weirdness (a grafted branch, probably a hash) + cmd_for_always = "git describe --always" + ver_name = shellcmd.run( + cmd_for_always.split(), output=True + ).rstrip() + ver_type = "h" + is_detached = True else: if comp_details.get("branch", None): # SPECIAL HANDLING of 'detached head' branches @@ -100,16 +107,18 @@ def __set_original_version(self, comp_details): is_detached = True self.version = MepoVersion(ver_name, ver_type, is_detached) - def registry_to_component(self, comp_name, comp_details, comp_style): + def registry_to_component(self, comp_name, comp_details, comp_style, fixture_url): self.name = comp_name self.fixture = comp_details.get("fixture", False) # local/remote - start if self.fixture: self.local = "." - repo_url = get_current_remote_url() - p = urlparse(repo_url) - last_url_node = p.path.rsplit("/")[-1] - self.remote = "../" + last_url_node + self.remote = fixture_url + if self.remote is None: + repo_url = get_current_remote_url() + p = urlparse(repo_url) + last_url_node = p.path.rsplit("/")[-1] + self.remote = "../" + last_url_node else: # Assume the flag for repostories is commercial-at repo_flag = "@" @@ -141,6 +150,8 @@ def registry_to_component(self, comp_name, comp_details, comp_style): # print(f'final self.local: {self.local}') self.remote = comp_details["remote"] + if fixture_url and self.remote.startswith("../"): + self.remote = urljoin(fixture_url, os.path.basename(self.remote)) # local/remote - end self.sparse = comp_details.get("sparse", None) # sparse is optional self.develop = comp_details.get("develop", None) # develop is optional @@ -150,7 +161,7 @@ def registry_to_component(self, comp_name, comp_details, comp_style): self.ignore_submodules = comp_details.get( "ignore_submodules", None ) # ignore_submodules is optional - self.__set_original_version(comp_details) + self.__set_original_version(comp_details, fixture_url) return self def to_registry_format(self): diff --git a/src/mepo/state.py b/src/mepo/state.py index a2e196f..883a37d 100644 --- a/src/mepo/state.py +++ b/src/mepo/state.py @@ -64,14 +64,16 @@ def state_exists(cls, old_style=False): return False @classmethod - def initialize(cls, project_registry, directory_style): + def initialize(cls, project_registry, directory_style, fixture_url): if cls.state_exists(): raise StateAlreadyInitializedError("Error! mepo state already exists") input_components = Registry(project_registry).read_file() complist = list() for name, comp in input_components.items(): complist.append( - MepoComponent().registry_to_component(name, comp, directory_style) + MepoComponent().registry_to_component( + name, comp, directory_style, fixture_url + ) ) cls.write_state(complist) diff --git a/tests/test_mepo_commands.py b/tests/test_mepo_commands.py index 19966da..2bf8720 100644 --- a/tests/test_mepo_commands.py +++ b/tests/test_mepo_commands.py @@ -71,6 +71,7 @@ def __mepo_clone(cls): branch=None, directory=None, partial="blobless", + fixture=None, ) mepo_clone.run(args) print(flush=True)