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 5 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
28 changes: 14 additions & 14 deletions pros/cli/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ 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')
@click.option('--modern', is_flag=True, default=False, show_default=True,
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
help='Allow applying PROS v4 templates')
@project_option()
@template_query(required=True)
@default_options
Expand All @@ -116,8 +116,8 @@ 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')
@click.option('--modern', is_flag=True, default=False, show_default=True,
help='Allow applying PROS v4 templates')
@project_option()
@template_query(required=True)
@default_options
Expand All @@ -143,8 +143,8 @@ 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')
@click.option('--modern', is_flag=True, default=False, show_default=True,
help='Allow upgrading to PROS v4 templates')
@project_option()
@template_query(required=False)
@default_options
Expand Down Expand Up @@ -205,8 +205,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('--modern', is_flag=True, default=False, show_default=True,
help='Create a project with a PROS v4 template')
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
@click.pass_context
@default_options
def new_project(ctx: click.Context, path: str, target: str, version: str,
Expand Down Expand Up @@ -255,13 +255,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('--modern', is_flag=True, default=False, show_default=True,
help='View PROS v4 templates in the listing')
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
@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, modern: bool):
"""
Query local and remote templates based on a spec

Expand All @@ -271,10 +271,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, modern=modern)
if modern:
templates += c.Conductor().resolve_templates(query, allow_offline=allow_offline, allow_online=allow_online,
force_refresh=force_refresh, beta=False)
force_refresh=force_refresh, modern=False)

render_templates = {}
for template in templates:
Expand Down
111 changes: 56 additions & 55 deletions pros/conductor/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import Enum
from pathlib import Path
from typing import *
import re

import click
from semantic_version import Spec, Version
Expand All @@ -17,11 +18,11 @@

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'
PROS4_NAME = 'kernel-4-mainline'
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
PROS4_URL = 'https://purduesigbots.github.io/pros-mainline/beta/kernel-beta-mainline.json'

"""
# TBD? Currently, beta value is stored in config file
# TBD? Currently, PROS 4 value is stored in config file
class ReleaseChannel(Enum):
Stable = 'stable'
Beta = 'beta'
Expand All @@ -35,24 +36,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.pros4_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.pros4_libraries: Dict[str, List[str]] = None
self.use_pros4 = False
self.warned_pros3_deprecated = 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 PROS 4 depot as another remote depot
if PROS4_NAME not in self.depots or \
not isinstance(self.depots[PROS4_NAME], HttpDepot) or \
self.depots[PROS4_NAME].location != PROS4_URL:
self.depots[PROS4_NAME] = HttpDepot(PROS4_NAME, PROS4_URL)
needs_saving = True
if self.default_target is None:
self.default_target = 'v5'
Expand All @@ -63,8 +65,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.pros4_libraries is None or len(self.pros4_libraries['v5']) != 2:
self.pros4_libraries = {
'v5': ['liblvgl', 'okapilib'],
'cortex': []
}
Expand All @@ -75,11 +77,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.pros4_libraries:
self.pros4_libraries['v5'] = []
needs_saving = True
if 'cortex' not in self.beta_libraries:
self.beta_libraries['cortex'] = []
if 'cortex' not in self.pros4_libraries:
self.pros4_libraries['cortex'] = []
needs_saving = True
if needs_saving:
self.save()
Expand All @@ -106,8 +108,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 == PROS4_NAME: # check for PROS 4
self.pros4_local_templates.add(local_template)
else:
self.local_templates.add(local_template)
self.save()
Expand All @@ -117,11 +119,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'] == PROS4_NAME:
if template not in self.pros4_local_templates:
logger(__name__).info(f"{template.identifier} was not in the Conductor's local PROS 4 templates cache.")
else:
self.beta_local_templates.remove(template)
self.pros4_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 +141,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_pros4 = kwargs.get('modern', False)
if isinstance(identifier, str):
query = BaseTemplate.create_query(name=identifier, **kwargs)
else:
query = identifier
if allow_offline:
if self.is_beta:
offline_results = filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.beta_local_templates)
if self.use_pros4:
offline_results = filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.pros4_local_templates)
else:
offline_results = filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.local_templates)
if unique:
Expand All @@ -155,8 +157,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):
# PROS 4 depot will only be accessed when the --modern flag is true
if depot.name != PROS4_NAME or (depot.name == PROS4_NAME and self.use_pros4):
online_results = filter(lambda t: t.satisfies(query, kernel_version=kernel_version),
depot.get_remote_templates(force_check=force_refresh, **kwargs))
if unique:
Expand Down Expand Up @@ -230,18 +232,25 @@ 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(
InvalidTemplateException(f'Not upgrading'))
if template.version[0] == '3' and curr_proj.kernel[0] == '4':
confirm = ui.confirm(f'Warning! Downgrading project to PROS 3 will cause breaking changes. '
confirm = ui.confirm(f'PROS 3 is now deprecated. Downgrading project to PROS 3 will also cause breaking changes. '
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
f'Do you still want to downgrade?')
if not confirm:
raise dont_send(
InvalidTemplateException(f'Not downgrading'))
elif template.version[0] == '3' and not self.warned_pros3_deprecated:
confirm = ui.confirm(f'PROS 3 is now deprecated. PROS 4 is now the latest version. '
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
f'Do you still want to use PROS 3?\n'
f'To use PROS 4, please use the --modern flag. We will remember your choice.')
self.warned_pros3_deprecated = 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 @@ -279,13 +288,15 @@ 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_pros4 = kwargs.get('modern', False)
if not self.use_pros4 and self.warned_pros3_deprecated:
ui.echo(f"PROS 3 is deprecated. PROS 4 is now the latest version. "
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
f"To use PROS 4 use the --modern flag.")

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}\''))
if re.match(r'^[\w\-. /]+$', str(Path(path))) is None:
raise dont_send(ValueError('Invalid characters found in path'))
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
proj = Project(path=path, create=True)
if 'target' in kwargs:
proj.target = kwargs['target']
Expand All @@ -300,23 +311,13 @@ 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.pros4_libraries if self.use_pros4 else self.default_libraries
12944qwerty marked this conversation as resolved.
Show resolved Hide resolved
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