Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸Allow for adding a depot as beta #323

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pros/cli/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,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, 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):
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}")

Expand Down
29 changes: 13 additions & 16 deletions pros/conductor/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)
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'
Expand Down Expand Up @@ -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.name == EARLY_ACCESS_NAME: # 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)
Expand All @@ -165,16 +165,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'))) \
Expand Down Expand Up @@ -210,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 depot.name != EARLY_ACCESS_NAME or (depot.name == EARLY_ACCESS_NAME 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))
Expand Down Expand Up @@ -406,13 +403,13 @@ 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):
self.depots[name] = HttpDepot(name, url)
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):
del self.depots[name]
self.save()

def query_depots(self, url: bool):
return [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()]
4 changes: 2 additions & 2 deletions pros/conductor/depots/http_depot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@


class HttpDepot(Depot):
def __init__(self, name: str, location: str):
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_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
Expand Down
Loading