Skip to content

Commit

Permalink
Merge pull request #338 from purduesigbots/release/3.5.1
Browse files Browse the repository at this point in the history
🔖 Release 3.5.1
  • Loading branch information
ayushuk authored Mar 22, 2024
2 parents 93a0288 + 27c6483 commit 1c5aa00
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 47 deletions.
2 changes: 1 addition & 1 deletion pip_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.0
3.5.1
10 changes: 10 additions & 0 deletions pros/cli/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ctypes
import sys
from typing import *

import click
Expand All @@ -24,6 +26,10 @@ def make(project: c.Project, build_args):
analytics.send("make")
exit_code = project.compile(build_args)
if exit_code != 0:
if sys.platform == 'win32':
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)

logger(__name__).error(f'Failed to make project: Exit Code {exit_code}', extra={'sentry': False})
raise click.ClickException('Failed to build')
return exit_code
Expand Down Expand Up @@ -71,6 +77,10 @@ def build_compile_commands(project: c.Project, suppress_output: bool, compile_co
exit_code = project.make_scan_build(build_args, cdb_file=compile_commands, suppress_output=suppress_output,
sandbox=sandbox)
if exit_code != 0:
if sys.platform == 'win32':
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)

logger(__name__).error(f'Failed to make project: Exit Code {exit_code}', extra={'sentry': False})
raise click.ClickException('Failed to build')
return exit_code
17 changes: 11 additions & 6 deletions pros/cli/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def callback(ctx: click.Context, param: click.Parameter, value: bool):
add_tag('no-sentry',value)
if value:
pros.common.sentry.disable_prompt()
decorator = click.option('--no-sentry', expose_value=False, is_flag=True, default=False, is_eager=True,
decorator = click.option('--no-sentry', expose_value=False, is_flag=True, default=True, is_eager=True,
help="Disable sentry reporting prompt.", callback=callback, cls=PROSOption, hidden=True)(f)
decorator.__name__ = f.__name__
return decorator
Expand Down Expand Up @@ -191,10 +191,13 @@ def callback(ctx: click.Context, param: click.Parameter, value: str):
if project_path is None:
if allow_none:
return None
else:
elif required:
raise click.UsageError(f'{os.path.abspath(value or ".")} is not inside a PROS project. '
f'Execute this command from within a PROS project or specify it '
f'with --project project/path')
else:
return None

return c.Project(project_path)

def wrapper(f: Union[click.Command, Callable]):
Expand Down Expand Up @@ -253,11 +256,13 @@ def resolve_v5_port(port: Optional[str], type: str, quiet: bool = False) -> Tupl
return None, False
if len(ports) > 1:
if not quiet:
port = click.prompt('Multiple {} ports were found. Please choose one: [{}]'
.format('v5', '|'.join([p.device for p in ports])),
default=ports[0].device,
brain_id = click.prompt('Multiple {} Brains were found. Please choose one to upload the program: [{}]'
.format('v5', ' | '.join([p.product.split(' ')[-1] for p in ports])),
default=ports[0].product.split(' ')[-1],
show_default=False,
type=click.Choice([p.device for p in ports]))
type=click.Choice([p.description.split(' ')[-1] for p in ports]))
port = [p.device for p in ports if p.description.split(' ')[-1] == brain_id][0]

assert port in [p.device for p in ports]
else:
return None, False
Expand Down
45 changes: 34 additions & 11 deletions pros/cli/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def fetch(query: c.BaseTemplate):
else:
if template_file:
logger(__name__).debug(f'Template file exists but is not a valid template: {template_file}')
else:
logger(__name__).error(f'Template not found: {query.name}')
return -1
template = c.Conductor().resolve_template(query, allow_offline=False)
logger(__name__).debug(f'Template from resolved query: {template}')
if template is None:
Expand Down Expand Up @@ -91,7 +94,7 @@ 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('--early-access/--disable-early-access', '--early/--disable-early', '-ea/-dea', 'early_access', '--beta/--disable-beta', default=None,
@click.option('--early-access/--no-early-access', '--early/--no-early', '-ea/-nea', 'early_access', '--beta/--no-beta', default=None,
help='Create a project using the PROS 4 kernel')
@project_option()
@template_query(required=True)
Expand Down Expand Up @@ -142,7 +145,7 @@ 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('--early-access/--disable-early-access', '--early/--disable-early', '-ea/-dea', 'early_access', '--beta/--disable-beta', default=None,
@click.option('--early-access/--no-early-access', '--early/--no-early', '-ea/-nea', 'early_access', '--beta/--no-beta', default=None,
help='Create a project using the PROS 4 kernel')
@project_option()
@template_query(required=False)
Expand Down Expand Up @@ -204,7 +207,7 @@ 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('--early-access/--disable-early-access', '--early/--disable-early', '-ea/-dea', 'early_access', '--beta/--disable-beta', default=None,
@click.option('--early-access/--no-early-access', '--early/--no-early', '-ea/-nea', 'early_access', '--beta/--no-beta', default=None,
help='Create a project using the PROS 4 kernel')
@click.pass_context
@default_options
Expand Down Expand Up @@ -248,7 +251,7 @@ def new_project(ctx: click.Context, path: str, target: str, version: str,


@conductor.command('query-templates',
aliases=['search-templates', 'ls-templates', 'lstemplates', 'querytemplates', 'searchtemplates'],
aliases=['search-templates', 'ls-templates', 'lstemplates', 'querytemplates', 'searchtemplates', 'q'],
context_settings={'ignore_unknown_options': True})
@click.option('--allow-offline/--no-offline', 'allow_offline', default=True, show_default=True,
help='(Dis)allow offline templates in the listing')
Expand All @@ -258,12 +261,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('--early-access/--disable-early-access', '--early/--disable-early', '-ea/-dea', 'early_access', '--beta/--disable-beta', default=None,
@click.option('--early-access/--no-early-access', '--early/--no-early', '-ea/-nea', 'early_access', '--beta/--no-beta', default=None,
help='View a list of early access templates')
@template_query(required=False)
@project_option(required=False)
@click.pass_context
@default_options
def query_templates(ctx, query: c.BaseTemplate, allow_offline: bool, allow_online: bool, force_refresh: bool,
def query_templates(ctx, project: Optional[c.Project], query: c.BaseTemplate, allow_offline: bool, allow_online: bool, force_refresh: bool,
limit: int, early_access: bool):
"""
Query local and remote templates based on a spec
Expand All @@ -273,12 +277,10 @@ def query_templates(ctx, query: c.BaseTemplate, allow_offline: bool, allow_onlin
analytics.send("query-templates")
if limit < 0:
limit = 15
if early_access is None and project is not None:
early_access = project.use_early_access
templates = c.Conductor().resolve_templates(query, allow_offline=allow_offline, allow_online=allow_online,
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, early_access=False)

render_templates = {}
for template in templates:
key = (template.identifier, template.origin)
Expand Down Expand Up @@ -368,4 +370,25 @@ def query_depots(url: bool):
_conductor = c.Conductor()
ui.echo(f"Available Depots{' (Add --url for the url)' if not url else ''}:\n")
ui.echo('\n'.join(_conductor.query_depots(url))+"\n")


@conductor.command('reset')
@click.option('--force', is_flag=True, default=False, help='Force reset')
@default_options
def reset(force: bool):
"""
Reset conductor.pros
Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""

if not force:
if not ui.confirm("This will remove all depots and templates. You will be unable to create a new PROS project if you do not have internet connection. Are you sure you want to continue?"):
ui.echo("Aborting")
return

# Delete conductor.pros
file = os.path.join(click.get_app_dir('PROS'), 'conductor.pros')
if os.path.exists(file):
os.remove(file)

ui.echo("Conductor was reset")
21 changes: 20 additions & 1 deletion pros/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import pros.cli.misc_commands
import pros.cli.interactive
import pros.cli.user_script
import pros.conductor as c

if sys.platform == 'win32':
kernel32 = ctypes.windll.kernel32
Expand Down Expand Up @@ -99,7 +100,23 @@ def use_analytics(ctx: click.Context, param, value):
ctx.exit(0)
ctx.ensure_object(dict)
analytics.set_use(touse)
ui.echo('Analytics set to : {}'.format(analytics.useAnalytics))
ui.echo(f'Analytics usage set to: {analytics.useAnalytics}')
ctx.exit(0)

def use_early_access(ctx: click.Context, param, value):
if value is None:
return
conductor = c.Conductor()
value = str(value).lower()
if value.startswith("t") or value in ["1", "yes", "y"]:
conductor.use_early_access = True
elif value.startswith("f") or value in ["0", "no", "n"]:
conductor.use_early_access = False
else:
ui.echo('Invalid argument provided for \'--use-early-access\'. Try \'--use-early-access=False\' or \'--use-early-access=True\'')
ctx.exit(0)
conductor.save()
ui.echo(f'Early access set to: {conductor.use_early_access}')
ctx.exit(0)


Expand All @@ -112,6 +129,8 @@ def use_analytics(ctx: click.Context, param, value):
callback=version)
@click.option('--use-analytics', help='Set analytics usage (True/False).', type=str, expose_value=False,
is_eager=True, default=None, callback=use_analytics)
@click.option('--use-early-access', type=str, expose_value=False, is_eager=True, default=None,
help='Create projects with PROS 4 kernel by default', callback=use_early_access)
def cli(ctx):
pros.common.sentry.register()
ctx.call_on_close(after_command)
Expand Down
2 changes: 1 addition & 1 deletion pros/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __str__(self):
result.append(PortReport('VEX EDR V5 System Ports', ports, 'v5/system'))

ports = find_v5_ports('User')
result.append(PortReport('VEX EDR V5 User ports', ports, 'v5/user'))
result.append(PortReport('VEX EDR V5 User Ports', ports, 'v5/user'))
if target == 'cortex' or target is None:
ports = find_cortex_ports()
result.append(PortReport('VEX EDR Cortex Microcontroller Ports', ports, 'cortex'))
Expand Down
4 changes: 2 additions & 2 deletions pros/cli/v5_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def capture(file_name: str, port: str, force: bool = False):

print(f'Saved screen capture to {file_name}')

@v5.command(aliases=['sv', 'set'], short_help='Set a kernel variable on a connected V5 device')
@v5.command('set-variable', aliases=['sv', 'set', 'set_variable'], short_help='Set a kernel variable on a connected V5 device')
@click.argument('variable', type=click.Choice(['teamnumber', 'robotname']), required=True)
@click.argument('value', required=True, type=click.STRING, nargs=1)
@click.argument('port', type=str, default=None, required=False)
Expand All @@ -308,7 +308,7 @@ def set_variable(variable, value, port):
actual_value = device.kv_write(variable, value).decode()
print(f'Value of \'{variable}\' set to : {actual_value}')

@v5.command(aliases=['rv', 'get'], short_help='Read a kernel variable from a connected V5 device')
@v5.command('read-variable', aliases=['rv', 'get', 'read_variable'], short_help='Read a kernel variable from a connected V5 device')
@click.argument('variable', type=click.Choice(['teamnumber', 'robotname']), required=True)
@click.argument('port', type=str, default=None, required=False)
@default_options
Expand Down
Loading

0 comments on commit 1c5aa00

Please sign in to comment.