From 9b68c7daee5e017c26d7bac0821d57145a4ed6cc Mon Sep 17 00:00:00 2001 From: Benjamin Davis Date: Wed, 31 Jan 2024 14:14:13 -0500 Subject: [PATCH 1/5] Support adding beta depots (adds templates to EA_local_templates) --- pros/cli/conductor.py | 5 +++-- pros/conductor/conductor.py | 27 ++++++++++++--------------- pros/conductor/depots/http_depot.py | 4 ++-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index 06b26e86..fea3d633 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -330,15 +330,16 @@ def info_project(project: c.Project, ls_upgrades): @conductor.command('add-depot') @click.argument('name') @click.argument('url') +@click.option('--early-access/--disable-early-access', '--early/--disable-early', '-ea/-dea', 'early_access', '--beta/--disable-beta', is_flag=True, default=False) @default_options -def add_depot(name: str, url: str): +def add_depot(name: str, url: str, early_access: bool): """ Add a depot Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more """ _conductor = c.Conductor() - _conductor.add_depot(name, url) + _conductor.add_depot(name, url, early_access=early_access) ui.echo(f"Added depot {name} from {url}") diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index e3547134..8353d9ec 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -47,13 +47,13 @@ def __init__(self, file=None): if MAINLINE_NAME not in self.depots or \ not isinstance(self.depots[MAINLINE_NAME], HttpDepot) or \ self.depots[MAINLINE_NAME].location != MAINLINE_URL: - self.depots[MAINLINE_NAME] = HttpDepot(MAINLINE_NAME, MAINLINE_URL) + self.depots[MAINLINE_NAME] = HttpDepot(MAINLINE_NAME, MAINLINE_URL, beta=False) needs_saving = True # add early access depot as another remote depot if EARLY_ACCESS_NAME not in self.depots or \ not isinstance(self.depots[EARLY_ACCESS_NAME], HttpDepot) or \ self.depots[EARLY_ACCESS_NAME].location != EARLY_ACCESS_URL: - self.depots[EARLY_ACCESS_NAME] = HttpDepot(EARLY_ACCESS_NAME, EARLY_ACCESS_URL) + self.depots[EARLY_ACCESS_NAME] = HttpDepot(EARLY_ACCESS_NAME, EARLY_ACCESS_URL, beta=True) needs_saving = True if self.default_target is None: self.default_target = 'v5' @@ -107,7 +107,7 @@ def fetch_template(self, depot: Depot, template: BaseTemplate, **kwargs) -> Loca local_template = LocalTemplate(orig=template, location=destination) local_template.metadata['origin'] = depot.name click.echo(f'Adding {local_template.identifier} to registry...', nl=False) - if depot.name == EARLY_ACCESS_NAME: # check for early access + if depot.config.get("beta",False): # check for early access self.early_access_local_templates.add(local_template) else: self.local_templates.add(local_template) @@ -118,16 +118,13 @@ def fetch_template(self, depot: Depot, template: BaseTemplate, **kwargs) -> Loca return local_template def purge_template(self, template: LocalTemplate): - if template.metadata['origin'] == EARLY_ACCESS_NAME: - if template not in self.early_access_local_templates: - logger(__name__).info(f"{template.identifier} was not in the Conductor's local early access templates cache.") - else: - self.early_access_local_templates.remove(template) + if template in self.local_templates: + self.local_templates.remove(template) + elif template in self.early_access_local_templates: + self.early_access_local_templates.remove(template) else: - if template not in self.local_templates: - logger(__name__).info(f"{template.identifier} was not in the Conductor's local templates cache.") - else: - self.local_templates.remove(template) + logger(__name__).info(f'{template.identifier} was not in the Conductor\'s local templates cache.') + if os.path.abspath(template.location).startswith( os.path.abspath(os.path.join(self.directory, 'templates'))) \ @@ -161,7 +158,7 @@ def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online: if allow_online: for depot in self.depots.values(): # EarlyAccess depot will only be accessed when the --early-access flag is true - if depot.name != EARLY_ACCESS_NAME or (depot.name == EARLY_ACCESS_NAME and self.use_early_access): + if not depot.config.get("beta", False) or (depot.config.get("beta", False) and self.use_early_access): remote_templates = depot.get_remote_templates(force_check=force_refresh, **kwargs) online_results = list(filter(lambda t: t.satisfies(query, kernel_version=kernel_version), remote_templates)) @@ -346,7 +343,7 @@ def new_project(self, path: str, no_default_libs: bool = False, **kwargs) -> Pro logger(__name__).exception(e) return proj - def add_depot(self, name: str, url: str): + def add_depot(self, name: str, url: str, beta: bool): self.depots[name] = HttpDepot(name, url) self.save() @@ -355,4 +352,4 @@ def remove_depot(self, name: str): self.save() def query_depots(self, url: bool): - return [name + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()] + return [name + ' -- ' + depot.config.get("beta", False) + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()] diff --git a/pros/conductor/depots/http_depot.py b/pros/conductor/depots/http_depot.py index dc7e3a25..fb996f5d 100644 --- a/pros/conductor/depots/http_depot.py +++ b/pros/conductor/depots/http_depot.py @@ -12,10 +12,10 @@ class HttpDepot(Depot): - def __init__(self, name: str, location: str): + def __init__(self, name: str, location: str, beta: bool = False): # Note: If update_frequency = timedelta(minutes=1) isn't included as a parameter, # the beta depot won't be saved in conductor.json correctly - super().__init__(name, location, config_schema={}, update_frequency = timedelta(minutes=1)) + super().__init__(name, location, config={"beta": beta}, config_schema={}, update_frequency = timedelta(minutes=1)) def fetch_template(self, template: BaseTemplate, destination: str, **kwargs): import requests From 9ba9246419a49880f5f3e9104b491d7a391a55f8 Mon Sep 17 00:00:00 2001 From: Benjamin Davis Date: Wed, 31 Jan 2024 14:18:04 -0500 Subject: [PATCH 2/5] add help description --- pros/cli/conductor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index fea3d633..cb0cc430 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -330,7 +330,7 @@ def info_project(project: c.Project, ls_upgrades): @conductor.command('add-depot') @click.argument('name') @click.argument('url') -@click.option('--early-access/--disable-early-access', '--early/--disable-early', '-ea/-dea', 'early_access', '--beta/--disable-beta', is_flag=True, default=False) +@click.option('--early-access/--disable-early-access', '--early/--disable-early', '-ea/-dea', 'early_access', '--beta/--disable-beta', is_flag=True, default=False, help="Add a depot as beta. Templates on this depot will be stored in early_access_local_templates, requiring --early-access to apply them.") @default_options def add_depot(name: str, url: str, early_access: bool): """ From 4bfb20f56e384e2e14268fb03261e49d76c1bc15 Mon Sep 17 00:00:00 2001 From: Benjamin Davis Date: Wed, 31 Jan 2024 14:39:06 -0500 Subject: [PATCH 3/5] fixed some bugs --- pros/cli/conductor.py | 2 +- pros/conductor/conductor.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index cb0cc430..a21282b3 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -339,7 +339,7 @@ def add_depot(name: str, url: str, early_access: bool): Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more """ _conductor = c.Conductor() - _conductor.add_depot(name, url, early_access=early_access) + _conductor.add_depot(name, url, beta=early_access) ui.echo(f"Added depot {name} from {url}") diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index 8353d9ec..f11ffa51 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -344,7 +344,7 @@ def new_project(self, path: str, no_default_libs: bool = False, **kwargs) -> Pro return proj def add_depot(self, name: str, url: str, beta: bool): - self.depots[name] = HttpDepot(name, url) + self.depots[name] = HttpDepot(name, url, beta=beta) self.save() def remove_depot(self, name: str): @@ -352,4 +352,4 @@ def remove_depot(self, name: str): self.save() def query_depots(self, url: bool): - return [name + ' -- ' + depot.config.get("beta", False) + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()] + return [(' BETA -- ' if depot.config.get("beta", False) else 'STABLE -- ') + name + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()] From 9493d9d7ed165ef844ea9fa0ec253da46a1c0c1a Mon Sep 17 00:00:00 2001 From: Benjamin Davis Date: Thu, 22 Feb 2024 19:47:04 -0500 Subject: [PATCH 4/5] change beta to early_access --- pros/cli/conductor.py | 2 +- pros/conductor/conductor.py | 14 +++++++------- pros/conductor/depots/http_depot.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index 6a8f0aad..f3837ca8 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -341,7 +341,7 @@ def add_depot(name: str, url: str, early_access: bool): Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more """ _conductor = c.Conductor() - _conductor.add_depot(name, url, beta=early_access) + _conductor.add_depot(name, url, early_access=early_access) ui.echo(f"Added depot {name} from {url}") diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index e988778d..9e970480 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -94,13 +94,13 @@ def __init__(self, file=None): if MAINLINE_NAME not in self.depots or \ not isinstance(self.depots[MAINLINE_NAME], HttpDepot) or \ self.depots[MAINLINE_NAME].location != MAINLINE_URL: - self.depots[MAINLINE_NAME] = HttpDepot(MAINLINE_NAME, MAINLINE_URL, beta=False) + self.depots[MAINLINE_NAME] = HttpDepot(MAINLINE_NAME, MAINLINE_URL, early_access=False) needs_saving = True # add early access depot as another remote depot if EARLY_ACCESS_NAME not in self.depots or \ not isinstance(self.depots[EARLY_ACCESS_NAME], HttpDepot) or \ self.depots[EARLY_ACCESS_NAME].location != EARLY_ACCESS_URL: - self.depots[EARLY_ACCESS_NAME] = HttpDepot(EARLY_ACCESS_NAME, EARLY_ACCESS_URL, beta=True) + self.depots[EARLY_ACCESS_NAME] = HttpDepot(EARLY_ACCESS_NAME, EARLY_ACCESS_URL, early_access=True) needs_saving = True if self.default_target is None: self.default_target = 'v5' @@ -154,7 +154,7 @@ def fetch_template(self, depot: Depot, template: BaseTemplate, **kwargs) -> Loca local_template = LocalTemplate(orig=template, location=destination) local_template.metadata['origin'] = depot.name click.echo(f'Adding {local_template.identifier} to registry...', nl=False) - if depot.config.get("beta",False): # check for early access + if depot.config.get("early_access",False): # check for early access self.early_access_local_templates.add(local_template) else: self.local_templates.add(local_template) @@ -207,7 +207,7 @@ def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online: if allow_online: for depot in self.depots.values(): # EarlyAccess depot will only be accessed when the --early-access flag is true - if not depot.config.get("beta", False) or (depot.config.get("beta", False) and use_early_access): + if not depot.config.get("early_access", False) or (depot.config.get("early_access", False) and use_early_access): remote_templates = depot.get_remote_templates(force_check=force_refresh, **kwargs) online_results = list(filter(lambda t: t.satisfies(query, kernel_version=kernel_version), remote_templates)) @@ -403,8 +403,8 @@ def new_project(self, path: str, no_default_libs: bool = False, **kwargs) -> Pro logger(__name__).exception(e) return proj - def add_depot(self, name: str, url: str, beta: bool): - self.depots[name] = HttpDepot(name, url, beta=beta) + def add_depot(self, name: str, url: str, early_access: bool): + self.depots[name] = HttpDepot(name, url, early_access=early_access) self.save() def remove_depot(self, name: str): @@ -412,4 +412,4 @@ def remove_depot(self, name: str): self.save() def query_depots(self, url: bool): - return [(' BETA -- ' if depot.config.get("beta", False) else 'STABLE -- ') + name + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()] + return [(' BETA -- ' if depot.config.get("early_access", False) else 'STABLE -- ') + name + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()] diff --git a/pros/conductor/depots/http_depot.py b/pros/conductor/depots/http_depot.py index fb996f5d..a7ad427b 100644 --- a/pros/conductor/depots/http_depot.py +++ b/pros/conductor/depots/http_depot.py @@ -15,7 +15,7 @@ class HttpDepot(Depot): def __init__(self, name: str, location: str, beta: bool = False): # Note: If update_frequency = timedelta(minutes=1) isn't included as a parameter, # the beta depot won't be saved in conductor.json correctly - super().__init__(name, location, config={"beta": beta}, config_schema={}, update_frequency = timedelta(minutes=1)) + super().__init__(name, location, config={"early_access": beta}, config_schema={}, update_frequency = timedelta(minutes=1)) def fetch_template(self, template: BaseTemplate, destination: str, **kwargs): import requests From 75f672af7ea151079c8f84c751f00dd606bfc6f7 Mon Sep 17 00:00:00 2001 From: Benjamin Davis Date: Thu, 22 Feb 2024 19:48:12 -0500 Subject: [PATCH 5/5] fix mistake --- pros/conductor/depots/http_depot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pros/conductor/depots/http_depot.py b/pros/conductor/depots/http_depot.py index a7ad427b..6ba2e3c6 100644 --- a/pros/conductor/depots/http_depot.py +++ b/pros/conductor/depots/http_depot.py @@ -12,7 +12,7 @@ class HttpDepot(Depot): - def __init__(self, name: str, location: str, beta: bool = False): + def __init__(self, name: str, location: str, early_access: bool = False): # Note: If update_frequency = timedelta(minutes=1) isn't included as a parameter, # the beta depot won't be saved in conductor.json correctly super().__init__(name, location, config={"early_access": beta}, config_schema={}, update_frequency = timedelta(minutes=1))