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

✨ Move PROS 4 to early access #296

Merged
merged 22 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
22 changes: 8 additions & 14 deletions pros/cli/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ def fetch(query: c.BaseTemplate):
help="Force apply the template, disregarding if the template is already installed.")
@click.option('--remove-empty-dirs/--no-remove-empty-dirs', 'remove_empty_directories', is_flag=True, default=True,
help='Remove empty directories when removing files')
@click.option('--beta', is_flag=True, default=False, show_default=True,
help='Allow applying beta templates')
@project_option()
@template_query(required=True)
@default_options
Expand All @@ -117,8 +115,6 @@ def apply(project: c.Project, query: c.BaseTemplate, **kwargs):
help="Force apply the template, disregarding if the template is already installed.")
@click.option('--remove-empty-dirs/--no-remove-empty-dirs', 'remove_empty_directories', is_flag=True, default=True,
help='Remove empty directories when removing files')
@click.option('--beta', is_flag=True, default=False, show_default=True,
help='Allow applying beta templates')
@project_option()
@template_query(required=True)
@default_options
Expand All @@ -144,8 +140,6 @@ def install(ctx: click.Context, **kwargs):
help="Force apply the template, disregarding if the template is already installed.")
@click.option('--remove-empty-dirs/--no-remove-empty-dirs', 'remove_empty_directories', is_flag=True, default=True,
help='Remove empty directories when removing files')
@click.option('--beta', is_flag=True, default=False, show_default=True,
help='Allow upgrading to beta templates')
@project_option()
@template_query(required=False)
@default_options
Expand Down Expand Up @@ -206,8 +200,8 @@ def uninstall_template(project: c.Project, query: c.BaseTemplate, remove_user: b
help='Compile the project after creation')
@click.option('--build-cache', is_flag=True, default=None, show_default=False,
help='Build compile commands cache after creation. Overrides --compile-after if both are specified.')
@click.option('--beta', is_flag=True, default=False, show_default=True,
help='Create a project with a beta template')
@click.option('--early-access', '--early', '-ea', 'early_access', '--beta', is_flag=True, default=False, show_default=True,
help='Create a project using the PROS 4 kernel')
@click.pass_context
@default_options
def new_project(ctx: click.Context, path: str, target: str, version: str,
Expand Down Expand Up @@ -256,13 +250,13 @@ def new_project(ctx: click.Context, path: str, target: str, version: str,
help='Force update all remote depots, ignoring automatic update checks')
@click.option('--limit', type=int, default=15,
help='The maximum number of displayed results for each library')
@click.option('--beta', is_flag=True, default=False, show_default=True,
help='View beta templates in the listing')
@click.option('--early-access', '--early', '-ea', '--beta', 'early_access', is_flag=True, default=False, show_default=True,
help='View a list of early access templates')
@template_query(required=False)
@click.pass_context
@default_options
def query_templates(ctx, query: c.BaseTemplate, allow_offline: bool, allow_online: bool, force_refresh: bool,
limit: int, beta: bool):
limit: int, early_access: bool):
"""
Query local and remote templates based on a spec

Expand All @@ -272,10 +266,10 @@ def query_templates(ctx, query: c.BaseTemplate, allow_offline: bool, allow_onlin
if limit < 0:
limit = 15
templates = c.Conductor().resolve_templates(query, allow_offline=allow_offline, allow_online=allow_online,
force_refresh=force_refresh, beta=beta)
if beta:
force_refresh=force_refresh, early_access=early_access)
if early_access:
templates += c.Conductor().resolve_templates(query, allow_offline=allow_offline, allow_online=allow_online,
force_refresh=force_refresh, beta=False)
force_refresh=force_refresh, early_access=False)

render_templates = {}
for template in templates:
Expand Down
107 changes: 56 additions & 51 deletions pros/conductor/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
from .templates import BaseTemplate, ExternalTemplate, LocalTemplate, Template

MAINLINE_NAME = 'pros-mainline'
MAINLINE_URL = 'https://purduesigbots.github.io/pros-mainline/pros-mainline.json'
BETA_NAME = 'kernel-beta-mainline'
BETA_URL = 'https://raw.githubusercontent.com/purduesigbots/pros-mainline/master/beta/kernel-beta-mainline.json'
MAINLINE_URL = 'https://pros.cs.purdue.edu/v5/_static/releases/pros-mainline.json'
EARLY_ACCESS_NAME = 'kernel-early-access-mainline'
EARLY_ACCESS_URL = 'https://pros.cs.purdue.edu/v5/_static/beta/beta-pros-mainline.json'

"""
# TBD? Currently, beta value is stored in config file
# TBD? Currently, EarlyAccess value is stored in config file
class ReleaseChannel(Enum):
Stable = 'stable'
Beta = 'beta'
Expand All @@ -35,24 +35,25 @@ def __init__(self, file=None):
if not file:
file = os.path.join(click.get_app_dir('PROS'), 'conductor.pros')
self.local_templates: Set[LocalTemplate] = set()
self.beta_local_templates: Set[LocalTemplate] = set()
self.early_access_local_templates: Set[LocalTemplate] = set()
self.depots: Dict[str, Depot] = {}
self.default_target: str = 'v5'
self.default_libraries: Dict[str, List[str]] = None
self.beta_libraries: Dict[str, List[str]] = None
self.is_beta = False
self.early_access_libraries: Dict[str, List[str]] = None
self.use_early_access = False
self.warn_early_access = False
super(Conductor, self).__init__(file)
needs_saving = False
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)
needs_saving = True
# add beta depot as another remote depot
if BETA_NAME not in self.depots or \
not isinstance(self.depots[BETA_NAME], HttpDepot) or \
self.depots[BETA_NAME].location != BETA_URL:
self.depots[BETA_NAME] = HttpDepot(BETA_NAME, BETA_URL)
# 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)
needs_saving = True
if self.default_target is None:
self.default_target = 'v5'
Expand All @@ -63,8 +64,8 @@ def __init__(self, file=None):
'cortex': []
}
needs_saving = True
if self.beta_libraries is None or len(self.beta_libraries['v5']) != 2:
self.beta_libraries = {
if self.early_access_libraries is None or len(self.early_access_libraries['v5']) != 2:
self.early_access_libraries = {
'v5': ['liblvgl', 'okapilib'],
'cortex': []
}
Expand All @@ -75,11 +76,11 @@ def __init__(self, file=None):
if 'cortex' not in self.default_libraries:
self.default_libraries['cortex'] = []
needs_saving = True
if 'v5' not in self.beta_libraries:
self.beta_libraries['v5'] = []
if 'v5' not in self.early_access_libraries:
self.early_access_libraries['v5'] = []
needs_saving = True
if 'cortex' not in self.beta_libraries:
self.beta_libraries['cortex'] = []
if 'cortex' not in self.early_access_libraries:
self.early_access_libraries['cortex'] = []
needs_saving = True
if needs_saving:
self.save()
Expand All @@ -106,8 +107,8 @@ 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 == BETA_NAME: # check for beta
self.beta_local_templates.add(local_template)
if depot.name == EARLY_ACCESS_NAME: # check for early access
self.early_access_local_templates.add(local_template)
else:
self.local_templates.add(local_template)
self.save()
Expand All @@ -117,11 +118,11 @@ def fetch_template(self, depot: Depot, template: BaseTemplate, **kwargs) -> Loca
return local_template

def purge_template(self, template: LocalTemplate):
if template.metadata['origin'] == BETA_NAME:
if template not in self.beta_local_templates:
logger(__name__).info(f"{template.identifier} was not in the Conductor's local beta templates cache.")
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.beta_local_templates.remove(template)
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.")
Expand All @@ -139,14 +140,14 @@ def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online:
unique: bool = True, **kwargs) -> List[BaseTemplate]:
results = list() if not unique else set()
kernel_version = kwargs.get('kernel_version', None)
self.is_beta = kwargs.get('beta', False)
self.use_early_access = kwargs.get('early_access', False) or self.use_early_access
if isinstance(identifier, str):
query = BaseTemplate.create_query(name=identifier, **kwargs)
else:
query = identifier
if allow_offline:
if self.is_beta:
offline_results = list(filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.beta_local_templates))
if self.use_early_access:
offline_results = list(filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.early_access_local_templates))
else:
offline_results = list(filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.local_templates))

Expand All @@ -160,8 +161,8 @@ def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online:
results.extend(offline_results)
if allow_online:
for depot in self.depots.values():
# beta depot will only be accessed when the --beta flag is true
if depot.name != BETA_NAME or (depot.name == BETA_NAME and self.is_beta):
# 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):
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 @@ -242,8 +243,6 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate],
if curr_proj.kernel:
if template.version[0] == '4' and curr_proj.kernel[0] == '3':
confirm = ui.confirm(f'Warning! Upgrading project to PROS 4 will cause breaking changes. '
f'For PROS 4 LLEMU/LVGL to function, the library liblvgl is required. '
f'Run \'pros conductor apply liblvgl --beta\' in the project directory. '
f'Do you still want to upgrade?')
if not confirm:
raise dont_send(
Expand All @@ -254,6 +253,15 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate],
if not confirm:
raise dont_send(
InvalidTemplateException(f'Not downgrading'))
elif not self.use_early_access and template.version[0] == '3' and not self.warn_early_access:
confirm = ui.confirm(f'PROS 4 is now in early access. '
f'Please use the --early-access flag if you would like to use it.\n'
f'Do you still want to use PROS 3?')
self.warn_early_access = True
self.save()
if not confirm:
raise dont_send(
InvalidTemplateException(f'Not using PROS 3'))
if not isinstance(template, LocalTemplate):
with ui.Notification():
template = self.fetch_template(self.get_depot(template.metadata['origin']), template, **kwargs)
Expand Down Expand Up @@ -291,13 +299,20 @@ def remove_template(project: Project, identifier: Union[str, BaseTemplate], remo
remove_empty_directories=remove_empty_directories)

def new_project(self, path: str, no_default_libs: bool = False, **kwargs) -> Project:
self.is_beta = kwargs.get('beta', False)
self.use_early_access = kwargs.get('early_access', False) or self.use_early_access
if not self.use_early_access and self.warn_early_access:
ui.echo(f"PROS 4 is now in early access. "
f"If you would like to use it, use the --early-access flag.")
elif self.use_early_access:
ui.echo(f'Early access is enabled. Using PROS 4.')

if Path(path).exists() and Path(path).samefile(os.path.expanduser('~')):
raise dont_send(ValueError('Will not create a project in user home directory'))
for char in str(Path(path)):
if char in ['?', '<', '>', '*', '|', '^', '#', '%', '&', '$', '+', '!', '`', '\'', '=',
'@', '\'', '{', '}', '[', ']', '(', ')', '~'] or ord(char) > 127:
raise dont_send(ValueError(f'Invalid character found in directory name: \'{char}\''))

proj = Project(path=path, create=True)
if 'target' in kwargs:
proj.target = kwargs['target']
Expand All @@ -312,25 +327,15 @@ def new_project(self, path: str, no_default_libs: bool = False, **kwargs) -> Pro
proj.save()

if not no_default_libs:
if self.is_beta:
#libraries = self.beta_libraries if self.is_beta else self.default_libraries
for library in self.beta_libraries[proj.target]:
try:
# remove kernel version so that latest template satisfying query is correctly selected
if 'version' in kwargs:
kwargs.pop('version')
self.apply_template(proj, library, **kwargs)
except Exception as e:
logger(__name__).exception(e)
else:
for library in self.default_libraries[proj.target]:
try:
# remove kernel version so that latest template satisfying query is correctly selected
if 'version' in kwargs:
kwargs.pop('version')
self.apply_template(proj, library, **kwargs)
except Exception as e:
logger(__name__).exception(e)
libraries = self.early_access_libraries if self.use_early_access else self.default_libraries
for library in libraries[proj.target]:
try:
# remove kernel version so that latest template satisfying query is correctly selected
if 'version' in kwargs:
kwargs.pop('version')
self.apply_template(proj, library, **kwargs)
except Exception as e:
logger(__name__).exception(e)
return proj

def add_depot(self, name: str, url: str):
Expand Down