Skip to content

Commit

Permalink
Merge branch 'pylint-ci' into fix-pylint-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankpatibandla committed Mar 1, 2024
2 parents 7b69626 + 2765c90 commit 06a495a
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
# W0106: Expression is assigned to nothing
# R1721: Unnecessary comprehension
# W0601: Global variable undefined at the module level
# W0612: Unused variable
# W1406: Redundant u-string prefix

# Performance optimization
# W1203: Use % formatting in logging functions and pass the parameters as arguments
Expand Down Expand Up @@ -103,4 +105,4 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120
W0108, R0912, R0911, W0511, E1136, R0902, W0611, C0412, C0103, C0301, R1732, R0915, W1514, R1718, W1510,
E0602, W1309, C0325, E1101, R1714, R0916, W0719, R1734, E1133, W1201, W0107, W3101, W0640, C0201, W1113,
W0246, W0622, W0221, E1111, R1720, R1723, E0102, W0201, E0203, E0401, W0602, W0212, W0707, R0904, W0101,
C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401
C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401, W0612, W1406
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
44 changes: 34 additions & 10 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,3 +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 06a495a

Please sign in to comment.