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

🚨 Fix Pylint errors #337

Draft
wants to merge 60 commits into
base: pylint-ci
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
7b69626
Create list of Pylint issues
mayankpatibandla Mar 1, 2024
06a495a
Merge branch 'pylint-ci' into fix-pylint-errors
mayankpatibandla Mar 1, 2024
a89428f
Disable whitespace and max builtin
mayankpatibandla Mar 1, 2024
652af5d
Fix R1731
mayankpatibandla Mar 4, 2024
2121128
Fix W1406
mayankpatibandla Mar 4, 2024
a29fa24
Fix W0612
mayankpatibandla Mar 4, 2024
d79f120
Fix W0601
mayankpatibandla Mar 4, 2024
d8c9825
Fix R1721
mayankpatibandla Mar 4, 2024
f0ece38
Fix W0106
mayankpatibandla Mar 4, 2024
7620f07
Fix R1701
mayankpatibandla Mar 4, 2024
2b92be3
Fix W0707
mayankpatibandla Mar 4, 2024
ba854f3
Fix W0602
mayankpatibandla Mar 4, 2024
97bcccf
Fix E0203 and W0201
mayankpatibandla Mar 4, 2024
f939b8a
Fix E0102
mayankpatibandla Mar 4, 2024
db9b198
Fix R1723
mayankpatibandla Mar 4, 2024
bbe03fe
Fix R1720
mayankpatibandla Mar 4, 2024
2ced5b4
Fix E1111
mayankpatibandla Mar 4, 2024
3b56ae1
Fix W0221
mayankpatibandla Mar 4, 2024
53666cd
Fix W0622
mayankpatibandla Mar 5, 2024
effdeb3
Fix W0246
mayankpatibandla Mar 5, 2024
0b58dc5
Fix W1113
mayankpatibandla Mar 5, 2024
11b23cd
Fix C0201
mayankpatibandla Mar 5, 2024
cce0199
Fix W0640
mayankpatibandla Mar 5, 2024
6952329
Fix W3101
mayankpatibandla Mar 5, 2024
29f9a7f
Fix W0107
mayankpatibandla Mar 5, 2024
4265e8d
Fix E1133
mayankpatibandla Mar 5, 2024
0b32d6c
Fix W0719
mayankpatibandla Mar 5, 2024
eca98fd
Fix R0916
mayankpatibandla Mar 5, 2024
56e808b
Fix R1714
mayankpatibandla Mar 5, 2024
31ead64
Fix C0325
mayankpatibandla Mar 5, 2024
38251ef
Fix W1309
mayankpatibandla Mar 5, 2024
d338e19
Add W4902
mayankpatibandla Mar 5, 2024
07eca48
Fix E0602
mayankpatibandla Mar 5, 2024
ac262f0
Fix W1510
mayankpatibandla Mar 5, 2024
cc52de8
Fix R1718
mayankpatibandla Mar 5, 2024
6661f0a
Fix W0611
mayankpatibandla Mar 5, 2024
3812947
Fix E1136
mayankpatibandla Mar 5, 2024
fa0dbd8
Fix W0108
mayankpatibandla Mar 5, 2024
21d5a8d
Fix R0402
mayankpatibandla Mar 5, 2024
a647ef9
Fix R0205
mayankpatibandla Mar 5, 2024
0d39605
Fix C0117
mayankpatibandla Mar 5, 2024
f1618c3
Fix C0121
mayankpatibandla Mar 5, 2024
8e47441
Fix R1705
mayankpatibandla Mar 5, 2024
1c4c1da
Fix C0303
mayankpatibandla Mar 5, 2024
cd8bb4a
Fix W4902
mayankpatibandla Mar 5, 2024
b2fe007
Merge branch 'pylint-ci' into fix-pylint-errors
mayankpatibandla Mar 5, 2024
8e9c3cd
Fix R1732
mayankpatibandla Mar 7, 2024
54eed9f
Fix R1734
mayankpatibandla Mar 19, 2024
e174cb4
Fix R1735
mayankpatibandla Mar 19, 2024
f04bca2
Test R0401
mayankpatibandla Mar 20, 2024
bf70bdb
Disable R0401
mayankpatibandla Mar 20, 2024
2e9f7b3
Fix E0110
mayankpatibandla Mar 24, 2024
a3be556
Fix W0223
mayankpatibandla Mar 24, 2024
8838799
Fix R1710
mayankpatibandla Mar 24, 2024
5df6f16
Fix R1729
mayankpatibandla Mar 24, 2024
5d925da
Fix terminal
mayankpatibandla Mar 28, 2024
609d479
Fix C0103 -- variables
mayankpatibandla Mar 28, 2024
a23bbbf
Fix C0103 -- modules
mayankpatibandla Mar 28, 2024
f501518
Fix case sensitive file rename
mayankpatibandla Mar 28, 2024
f27b927
Fix interpret-cc in workflow
mayankpatibandla Mar 28, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ jobs:
run: |
python3 version.py
pyinstaller pros.spec
pyinstaller --onefile pros/cli/compile_commands/intercept-cc.py --name=intercept-cc
pyinstaller --onefile pros/cli/compile_commands/intercept-cc.py --name=intercept-c++
pyinstaller --onefile pros/cli/compile_commands/intercept_cc.py --name=intercept-cc
pyinstaller --onefile pros/cli/compile_commands/intercept_cc.py --name=intercept-c++
if: matrix.os != 'macos-latest'

- name: Run Pyinstaller MacOS
Expand All @@ -77,8 +77,8 @@ jobs:
pip3 install -e ./charset_normalizer
python3 version.py
pyinstaller pros-macos.spec
pyinstaller --onefile pros/cli/compile_commands/intercept-cc.py --name=intercept-cc --target-arch=universal2
pyinstaller --onefile pros/cli/compile_commands/intercept-cc.py --name=intercept-c++ --target-arch=universal2
pyinstaller --onefile pros/cli/compile_commands/intercept_cc.py --name=intercept-cc --target-arch=universal2
pyinstaller --onefile pros/cli/compile_commands/intercept_cc.py --name=intercept-c++ --target-arch=universal2
if: matrix.os == 'macos-latest'

- name: Package Everything Up
Expand Down
64 changes: 58 additions & 6 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
[MASTER]

# Should enable these
# C0114: Missing module docstring
# C0115: Missing class docstring
# C0116: Missing function or method docstring
# C0415: Import outside toplevel (import-outside-toplevel)
# E1120: No value for argument in function call
# E1123: Unexpected argument in function call
# C0209: Consider using an f-string
# W0621: Redefining name from outer scope
# W0614: Unused import from wildcard import
# W0401: Wildcard import
# R1725: Super with arguments
# W0237: Renamed arguments
# W0613: Unused argument
# W0511: TODO
# W1514: Using open without explicitly specifying an encoding
# E1101: Nonexistent member
# E0401: Unable to import
# W0212: Access to a protected member
# W0101: Unreachable code

# Performance optimization
# W1203: Use % formatting in logging functions and pass the parameters as arguments
# W1202: Use % formatting in logging functions and pass the parameters as arguments
# W1201: Specify string format arguments as logging function parameters

# Fixed by auto formatter
# C0411: Wrongly ordered import
# C0412: Ungrouped imports
# C0301: Line too long

# Might be difficult to refactor in some cases
# W0718: Broad exception caught
# W0702: No exception type(s) specified





# Should disable these for now, would require too much refactoring
# R0903: Too few public methods
# R0913: Too many arguments
# R0914: Too many local variables
# R0912: Too many branches
# R0911: Too many return statements
# R0902: Too many instance attributes
# R0915: Too many statements
# R0904: Too many public methods
# C0302: Too many lines in module
# W0603: Using the global statement
# R0401: Cyclic import -- Seems to be platform specific

max-line-length = 120
disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, C0121,
W0614, W0401, W1202, C0117, W0718, R0205, R0402, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613,
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, W0221, R1723, E0102, W0201, E0203, E0401, W0602, W0212, W0707, R0904,
W0101, C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401, W0612, W1406, C0303, R1731
disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, E1120, E1123, C0209, W0621,
W0614, W0401, W1202, W0718, R0914, R1725, C0411, W0237, W0702, W0613,
R0912, R0911, W0511, R0902, C0412, C0301, R0915, W1514,
E1101, W1201,
E0401, W0212, R0904, W0101,
C0302, W0603, R0401
25 changes: 13 additions & 12 deletions pros/cli/click_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def format_commands(self, ctx, formatter):
if hasattr(cmd, 'hidden') and cmd.hidden:
continue

help = cmd.short_help or ''
rows.append((subcommand, help))
help_text = cmd.short_help or ''
rows.append((subcommand, help_text))

if rows:
with formatter.section('Commands'):
Expand Down Expand Up @@ -65,9 +65,10 @@ class PROSCommand(PROSFormatted, click.Command):
pass


# Seems to be unused?
class PROSMultiCommand(PROSFormatted, click.MultiCommand):
def get_command(self, ctx, cmd_name):
super().get_command(ctx, cmd_name)
def get_command(self, ctx: click.Context, cmd_name: str) -> Optional[click.Command]:
pass


class PROSOption(click.Option):
Expand All @@ -78,21 +79,21 @@ def __init__(self, *args, hidden: bool = False, group: str = None, **kwargs):

def get_help_record(self, ctx):
if hasattr(self, 'hidden') and self.hidden:
return
return None
return super().get_help_record(ctx)

class PROSDeprecated(click.Option):
def __init__(self, *args, replacement: str = None, **kwargs):
kwargs['help'] = "This option has been deprecated."
if not replacement==None:
if replacement is not None:
kwargs['help'] += " Its replacement is '--{}'".format(replacement)
super(PROSDeprecated, self).__init__(*args, **kwargs)
self.group = "Deprecated"
self.optiontype = "flag" if str(self.type)=="BOOL" else "switch"
self.to_use = replacement
self.arg = args[0][len(args[0])-1]
self.msg = "The '{}' {} has been deprecated. Please use '--{}' instead."
if replacement==None:
if replacement is None:
self.msg = self.msg.split(".")[0]+"."

def type_cast_value(self, ctx, value):
Expand All @@ -103,7 +104,7 @@ def type_cast_value(self, ctx, value):
class PROSGroup(PROSFormatted, click.Group):
def __init__(self, *args, **kwargs):
super(PROSGroup, self).__init__(*args, **kwargs)
self.cmd_dict = dict()
self.cmd_dict = {}

def command(self, *args, aliases=None, **kwargs):
aliases = aliases or []
Expand All @@ -118,7 +119,7 @@ def decorator(f):

return decorator

def group(self, aliases=None, *args, **kwargs):
def group(self, *args, aliases=None, **kwargs):
aliases = aliases or []

def decorator(f):
Expand All @@ -140,7 +141,7 @@ def get_command(self, ctx, cmd_name):

# fall back to guessing
matches = {x for x in self.list_commands(ctx) if x.startswith(cmd_name)}
matches.union({x for x in self.cmd_dict.keys() if x.startswith(cmd_name)})
matches.union({x for x in self.cmd_dict if x.startswith(cmd_name)})
if len(matches) == 1:
return super(PROSGroup, self).get_command(ctx, matches.pop())
return None
Expand All @@ -159,8 +160,8 @@ def invoke(self, *args, **kwargs):
super(PROSCommandCollection, self).invoke(*args, **kwargs)
except ClickException as e:
click.echo("PROS-CLI Version: {}".format(get_version()))
isProject = p.find_project("")
if (isProject): #check if there is a project
is_project = p.find_project("")
if is_project: #check if there is a project
curr_proj = p()
click.echo("PROS-Kernel Version: {}".format(curr_proj.kernel))
raise e
18 changes: 8 additions & 10 deletions pros/cli/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def callback(ctx: click.Context, param: click.core.Parameter, value: Any):
def logfile_option(f: Union[click.Command, Callable]):
def callback(ctx: click.Context, param: click.core.Parameter, value: Any):
if value is None or value[0] is None:
return None
return
ctx.ensure_object(dict)
level = None
if isinstance(value[1], str):
Expand Down Expand Up @@ -138,8 +138,7 @@ def callback(ctx: click.Context, param: click.Parameter, value: bool):
add_tag('no-analytics',value)
if value:
echo("Not sending analytics for this command.\n")
analytics.useAnalytics = False
pass
analytics.use_analytics = False
decorator = click.option('--no-analytics', expose_value=False, is_flag=True, default=False, is_eager=True,
help="Don't send analytics for this command.", callback=callback, cls=PROSOption, hidden=True)(f)
decorator.__name__ = f.__name__
Expand Down Expand Up @@ -191,12 +190,11 @@ def callback(ctx: click.Context, param: click.Parameter, value: str):
if project_path is None:
if allow_none:
return None
elif required:
if 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 None

return c.Project(project_path)

Expand Down Expand Up @@ -231,12 +229,12 @@ def pros_root(f):
return decorator


def resolve_v5_port(port: Optional[str], type: str, quiet: bool = False) -> Tuple[Optional[str], bool]:
def resolve_v5_port(port: Optional[str], p_type: str, quiet: bool = False) -> Tuple[Optional[str], bool]:
"""
Detect serial ports that can be used to interact with a V5.

Returns a tuple of (port?, is_joystick). port will be None if no ports are
found, and is_joystick is False unless type == 'user' and the port is
found, and is_joystick is False unless p_type == 'user' and the port is
determined to be a controller. This is useful in e.g.
pros.cli.terminal:terminal where the communication protocol is different for
wireless interaction.
Expand All @@ -246,7 +244,7 @@ def resolve_v5_port(port: Optional[str], type: str, quiet: bool = False) -> Tupl
# not a joystick.
is_joystick = False
if not port:
ports = find_v5_ports(type)
ports = find_v5_ports(p_type)
logger(__name__).debug('Ports: {}'.format(';'.join([str(p.__dict__) for p in ports])))
if len(ports) == 0:
if not quiet:
Expand All @@ -268,7 +266,7 @@ def resolve_v5_port(port: Optional[str], type: str, quiet: bool = False) -> Tupl
return None, False
else:
port = ports[0].device
is_joystick = type == 'user' and 'Controller' in ports[0].description
is_joystick = p_type == 'user' and 'Controller' in ports[0].description
logger(__name__).info('Automatically selected {}'.format(port))
return port, is_joystick

Expand Down
8 changes: 4 additions & 4 deletions pros/cli/conductor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os.path
from itertools import groupby

import pros.common.ui as ui
from pros.common import ui
import pros.conductor as c
from pros.cli.common import *
from pros.conductor.templates import ExternalTemplate
Expand All @@ -22,7 +22,6 @@ def conductor():

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
pass


@conductor.command(aliases=['download'], short_help='Fetch/Download a remote template',
Expand Down Expand Up @@ -78,6 +77,7 @@ def fetch(query: c.BaseTemplate):
# whether the arguments are for the template or for the depot, so they share them
logger(__name__).debug(f'Additional depot and template args: {query.metadata}')
c.Conductor().fetch_template(depot, template, **query.metadata)
return 0


@conductor.command(context_settings={'ignore_unknown_options': True})
Expand Down Expand Up @@ -320,12 +320,12 @@ def info_project(project: c.Project, ls_upgrades):
report = ProjectReport(project)
_conductor = c.Conductor()
if ls_upgrades:
import semantic_version as semver
for template in report.project['templates']:
import semantic_version as semver
templates = _conductor.resolve_templates(c.BaseTemplate.create_query(name=template["name"],
version=f'>{template["version"]}',
target=project.target))
template["upgrades"] = sorted({t.version for t in templates}, key=lambda v: semver.Version(v), reverse=True)
template["upgrades"] = sorted({t.version for t in templates}, key=semver.Version, reverse=True)

ui.finalize('project-report', report)

Expand Down
8 changes: 4 additions & 4 deletions pros/cli/conductor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import *

import click
import pros.common.ui as ui
from pros.common import ui
import pros.conductor as c
from pros.common.utils import logger
from pros.conductor.templates import ExternalTemplate
Expand Down Expand Up @@ -77,7 +77,7 @@ def get_matching_files(globs: List[str]) -> Set[str]:
_path = os.path.normpath(path) + os.path.sep
for g in [g for g in globs if glob.has_magic(g)]:
files = glob.glob(f'{path}/{g}', recursive=True)
files = filter(lambda f: os.path.isfile(f), files)
files = filter(os.path.isfile, files)
files = [os.path.normpath(os.path.normpath(f).split(_path)[-1]) for f in files]
matching_files.extend(files)

Expand Down Expand Up @@ -161,11 +161,11 @@ def purge_template(query: c.BaseTemplate, force):
beta_templates = cond.resolve_templates(query, allow_online=False, beta=True)
if len(templates) == 0:
click.echo('No matching templates were found matching the spec.')
return 0
return
t_list = [t.identifier for t in templates] + [t.identifier for t in beta_templates]
click.echo(f'The following template(s) will be removed {t_list}')
if len(templates) > 1 and not force:
click.confirm(f'Are you sure you want to remove multiple templates?', abort=True)
click.confirm('Are you sure you want to remove multiple templates?', abort=True)
for template in templates:
if isinstance(template, c.LocalTemplate):
cond.purge_template(template)
Expand Down
5 changes: 2 additions & 3 deletions pros/cli/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import click
import pros.conductor as c
from .common import PROSGroup, default_options, project_option, pros_root
from pros.ga.analytics import analytics

@pros_root
def interactive_cli():
Expand All @@ -21,7 +20,7 @@ def interactive():
@default_options
def new_project(directory):
from pros.common.ui.interactive.renderers import MachineOutputRenderer
from pros.conductor.interactive.NewProjectModal import NewProjectModal
from pros.conductor.interactive.new_project_modal import NewProjectModal
app = NewProjectModal(directory=directory)
MachineOutputRenderer(app).run()

Expand All @@ -31,7 +30,7 @@ def new_project(directory):
@default_options
def update_project(project: Optional[c.Project]):
from pros.common.ui.interactive.renderers import MachineOutputRenderer
from pros.conductor.interactive.UpdateProjectModal import UpdateProjectModal
from pros.conductor.interactive.update_project_modal import UpdateProjectModal
app = UpdateProjectModal(project)
MachineOutputRenderer(app).run()

Expand Down
Loading
Loading