From 7b696268340b9a38a9b5e04d731eea0c540f58d5 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Thu, 29 Feb 2024 19:33:41 -0500 Subject: [PATCH 01/58] Create list of Pylint issues --- .pylintrc | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 4514f984..23379512 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,9 +1,106 @@ [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) +# R1705: Unnecessary "else" after "return" +# E1120: No value for argument in function call +# E1123: Unexpected argument in function call +# C0209: Consider using an f-string +# R1710: Either all return statements in a function should return an expression, or none of them should +# W0621: Redefining name from outer scope +# C0121: Comparison to singletons is unnecessary +# W0614: Unused import from wildcard import +# W0401: Wildcard import +# C0117: Unnecessary negation +# R0205: Useless object inheritance +# R0402: Consider using from import +# R1725: Super with arguments +# W0237: Renamed arguments +# W0223: Abstract method is not overridden +# W0613: Unused argument +# W0108: Lambda may not be necessary +# W0511: TODO +# E1136: Value is unsubscriptable +# W0611: Unused import +# C0103: Variable name doesn't conform to naming style +# R1732: Consider using with +# W1514: Using open without explicitly specifying an encoding +# R1718: Consider using set comprehension +# W1510: Subprocess run without explicitly defining check +# E0602: Undefined variable +# W1309: Using an f-string that does not have any interpolated variables +# C0325: Unnecessary parenthesis +# E1101: Nonexistent member +# R1714: Consider using in +# R0916: Too many boolean expressions in if statement +# W0719: Broad exception raised +# E1133: Not an iterable +# W0107: Unnecessary pass statement +# W3101: Missing timeout +# W0640: Cell variable from loop +# C0201: Consider iterating over a dict instead of calling keys +# W1113: Keyword argument before variable argument +# W0246: Useless parent delegation +# W0622: Redefining built-in +# W0221: Arguments number differs from overridden method +# E1111: Assigning to function call which doesn't return +# R1720: Unnecessary "else" after "raise" +# R1723: Unnecessary "else" after "break" +# E0102: Function already defined +# W0201: Attribute defined outside __init__ +# E0203: Access to member before its definition +# E0401: Unable to import +# W0602: Undefined global variable +# W0212: Access to a protected member +# W0707: Missing raising from +# W0101: Unreachable code +# E0110: Instantiated abstract class +# R1701: Consider merging isinstance +# W0106: Expression is assigned to nothing +# R1721: Unnecessary comprehension +# W0601: Global variable undefined at the module level + +# Performance optimization +# W1203: Use % formatting in logging functions and pass the parameters as arguments +# R1729: Use a generator instead of comprehension +# W1202: Use % formatting in logging functions and pass the parameters as arguments +# R1735: Use literal syntax instead of function calls to create dict +# R1734: Use literal syntax instead of function calls to create list +# 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 + 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 + W0246, W0622, W0221, E1111, R1720, R1723, E0102, W0201, E0203, E0401, W0602, W0212, W0707, R0904, W0101, + C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401 From a89428f083dc5153f8033b2cc53e286080cb22f0 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Thu, 29 Feb 2024 23:26:20 -0500 Subject: [PATCH 02/58] Disable whitespace and max builtin --- .pylintrc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 0846fa12..02e7c108 100644 --- a/.pylintrc +++ b/.pylintrc @@ -64,6 +64,7 @@ # W0601: Global variable undefined at the module level # W0612: Unused variable # W1406: Redundant u-string prefix +# R1731: Use max builtin function # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -77,6 +78,7 @@ # C0411: Wrongly ordered import # C0412: Ungrouped imports # C0301: Line too long +# C0303: Trailing whitespace # Might be difficult to refactor in some cases # W0718: Broad exception caught @@ -105,4 +107,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, W0612, W1406 + C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401, W0612, W1406, C0303, R1731 From 652af5d100f357686b1ad9e0458a92cc83b5a51b Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:31:49 -0500 Subject: [PATCH 03/58] Fix R1731 --- .pylintrc | 3 +-- pros/common/ui/__init__.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index 02e7c108..e978c8ed 100644 --- a/.pylintrc +++ b/.pylintrc @@ -64,7 +64,6 @@ # W0601: Global variable undefined at the module level # W0612: Unused variable # W1406: Redundant u-string prefix -# R1731: Use max builtin function # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -107,4 +106,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, W0612, W1406, C0303, R1731 + C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401, W0612, W1406, C0303 diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index 24fcc71d..4380c9fe 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -141,8 +141,7 @@ def __init__(self, notify_value: Optional[int] = None): global _last_notify_value if not notify_value: notify_value = _last_notify_value + 1 - if notify_value > _last_notify_value: - _last_notify_value = notify_value + _last_notify_value = max(_last_notify_value, notify_value) self.notify_value = notify_value self.old_notify_values = [] From 212112890f43a8069271dcd7175d78bad9b161f5 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:35:13 -0500 Subject: [PATCH 04/58] Fix W1406 --- .pylintrc | 3 +-- pros/conductor/conductor.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index e978c8ed..6e14bf74 100644 --- a/.pylintrc +++ b/.pylintrc @@ -63,7 +63,6 @@ # 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 @@ -106,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, W0612, W1406, C0303 + C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401, W0612, C0303 diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index 4d82cd30..4dd1a11c 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -59,7 +59,7 @@ def is_pathname_valid(pathname: str) -> bool: # Check for emojis # https://stackoverflow.com/a/62898106/11177720 ranges = [ - (ord(u'\U0001F300'), ord(u"\U0001FAF6")), # 127744, 129782 + (ord('\U0001F300'), ord("\U0001FAF6")), # 127744, 129782 (126980, 127569), (169, 174), (8205, 12953) From a29fa24d38d5703224d4842c49be9493ff022e56 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:37:37 -0500 Subject: [PATCH 05/58] Fix W0612 --- .pylintrc | 3 +-- pros/conductor/conductor.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 6e14bf74..c51b1bd2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -62,7 +62,6 @@ # W0106: Expression is assigned to nothing # R1721: Unnecessary comprehension # W0601: Global variable undefined at the module level -# W0612: Unused variable # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -105,4 +104,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, W0612, C0303 + C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401, C0303 diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index 4dd1a11c..e35d9046 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -69,7 +69,7 @@ def is_pathname_valid(pathname: str) -> bool: for range_min, range_max in ranges: if range_min <= char_code <= range_max: return False - except TypeError as exc: + except TypeError: return False else: return True From d79f1201df7f4eec0b38d129bd1251e68cc05540 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:41:33 -0500 Subject: [PATCH 06/58] Fix W0601 --- .pylintrc | 3 +-- pros/common/sentry.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index c51b1bd2..2f936e78 100644 --- a/.pylintrc +++ b/.pylintrc @@ -61,7 +61,6 @@ # R1701: Consider merging isinstance # W0106: Expression is assigned to nothing # R1721: Unnecessary comprehension -# W0601: Global variable undefined at the module level # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -104,4 +103,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, C0303 + C0302, E0110, W0603, R1701, W0106, R1721, R0401, C0303 diff --git a/pros/common/sentry.py b/pros/common/sentry.py index 6c0c8690..4ecacc4f 100644 --- a/pros/common/sentry.py +++ b/pros/common/sentry.py @@ -113,7 +113,7 @@ def add_tag(key: str, value: str): def register(cfg: Optional['CliConfig'] = None): - global cli_config, client + global cli_config if cfg is None: from pros.config.cli_config import cli_config as get_cli_config cli_config = get_cli_config() From d8c98254df22498ea6880224a419a208d831b3f4 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:44:17 -0500 Subject: [PATCH 07/58] Fix R1721 --- .pylintrc | 3 +-- pros/conductor/interactive/UpdateProjectModal.py | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.pylintrc b/.pylintrc index 2f936e78..77bbfadb 100644 --- a/.pylintrc +++ b/.pylintrc @@ -60,7 +60,6 @@ # E0110: Instantiated abstract class # R1701: Consider merging isinstance # W0106: Expression is assigned to nothing -# R1721: Unnecessary comprehension # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -103,4 +102,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, R0401, C0303 + C0302, E0110, W0603, R1701, W0106, R0401, C0303 diff --git a/pros/conductor/interactive/UpdateProjectModal.py b/pros/conductor/interactive/UpdateProjectModal.py index 9cb5124e..348400d6 100644 --- a/pros/conductor/interactive/UpdateProjectModal.py +++ b/pros/conductor/interactive/UpdateProjectModal.py @@ -92,17 +92,18 @@ def project_changed(self, new_project: ExistingProjectParameter): self.current_kernel = TemplateParameter( None, options=sorted( - {t for t in self.conductor.resolve_templates(self.project.templates['kernel'].as_query())}, + set(self.conductor.resolve_templates(self.project.templates['kernel'].as_query())), key=lambda v: Version(v.version), reverse=True ) ) self.current_templates = [ TemplateParameter( None, - options=sorted({ - t - for t in self.conductor.resolve_templates(t.as_query()) - }, key=lambda v: Version(v.version), reverse=True) + options=sorted( + set(self.conductor.resolve_templates(t.as_query())), + key=lambda v: Version(v.version), + reverse=True + ) ) for t in self.project.templates.values() if t.name != 'kernel' From f0ece3871ade5beba2a3c8db393d795c1d08436e Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:47:11 -0500 Subject: [PATCH 08/58] Fix W0106 --- .pylintrc | 3 +-- pros/serial/devices/vex/v5_device.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 77bbfadb..62f0d1fc 100644 --- a/.pylintrc +++ b/.pylintrc @@ -59,7 +59,6 @@ # W0101: Unreachable code # E0110: Instantiated abstract class # R1701: Consider merging isinstance -# W0106: Expression is assigned to nothing # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -102,4 +101,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, R0401, C0303 + C0302, E0110, W0603, R1701, R0401, C0303 diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index 24483eb0..d1c52f7a 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -891,7 +891,7 @@ def user_fifo_write(self, payload: Union[Iterable, bytes, bytearray, str]): if i + max_packet_size > pl_len: packet_size = pl_len - i logger(__name__).debug(f'Writing {packet_size} bytes to user FIFO') - self._txrx_ext_packet(0x27, b'\x01\x00' + payload[i:packet_size], 0, check_length=False)[1:] + # self._txrx_ext_packet(0x27, b'\x01\x00' + payload[i:packet_size], 0, check_length=False)[1:] logger(__name__).debug('Completed ext 0x27 command (write)') @retries From 7620f07854c7712106135477aa07878f4e22ff85 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:49:05 -0500 Subject: [PATCH 09/58] Fix R1701 --- .pylintrc | 3 +-- pros/common/ui/__init__.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 62f0d1fc..7da09968 100644 --- a/.pylintrc +++ b/.pylintrc @@ -58,7 +58,6 @@ # W0707: Missing raising from # W0101: Unreachable code # E0110: Instantiated abstract class -# R1701: Consider merging isinstance # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -101,4 +100,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, R0401, C0303 + C0302, E0110, W0603, R0401, C0303 diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index 4380c9fe..698e6e9c 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -89,7 +89,7 @@ def finalize(method: str, data: Union[str, Dict, object, List[Union[str, Dict, o human_readable = '' elif isinstance(data[0], str): human_readable = '\n'.join(data) - elif isinstance(data[0], dict) or isinstance(data[0], object): + elif isinstance(data[0], (dict, object)): if hasattr(data[0], '__str__'): human_readable = '\n'.join([str(d) for d in data]) else: From 2b92be32de7c6c85d5cf3569a6cbf4243e81a31c Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:10:53 -0500 Subject: [PATCH 10/58] Fix W0707 --- .pylintrc | 3 +-- pros/serial/ports/direct_port.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.pylintrc b/.pylintrc index 7da09968..156ca2b2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,7 +55,6 @@ # E0401: Unable to import # W0602: Undefined global variable # W0212: Access to a protected member -# W0707: Missing raising from # W0101: Unreachable code # E0110: Instantiated abstract class @@ -99,5 +98,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, R1723, E0102, W0201, E0203, E0401, W0602, W0212, W0707, R0904, W0101, + W0246, W0622, W0221, E1111, R1720, R1723, E0102, W0201, E0203, E0401, W0602, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/serial/ports/direct_port.py b/pros/serial/ports/direct_port.py index fa225f54..4b555b67 100644 --- a/pros/serial/ports/direct_port.py +++ b/pros/serial/ports/direct_port.py @@ -21,9 +21,9 @@ def create_serial_port(port_name: str, timeout: Optional[float] = 1.0) -> serial 'Access is denied', 'Errno 16', 'Errno 13' ]): tb = sys.exc_info()[2] - raise dont_send(ConnectionRefusedException(port_name, e).with_traceback(tb)) + raise dont_send(ConnectionRefusedException(port_name, e).with_traceback(tb)) from e else: - raise dont_send(PortNotFoundException(port_name, e)) + raise dont_send(PortNotFoundException(port_name, e)) from e @@ -51,7 +51,7 @@ def read(self, n_bytes: int = 0) -> bytes: return msg except serial.SerialException as e: logger(__name__).debug(e) - raise PortConnectionException(e) + raise PortConnectionException(e) from e def write(self, data: Union[str, bytes]): if isinstance(data, str): From ba854f3651f81103e4ac602fbcad48a1a03d8e3c Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:13:53 -0500 Subject: [PATCH 11/58] Fix W0602 --- .pylintrc | 3 +-- pros/common/sentry.py | 1 - pros/common/ui/__init__.py | 2 -- .../ui/interactive/renderers/MachineOutputRenderer.py | 8 -------- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/.pylintrc b/.pylintrc index 156ca2b2..949d814b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -53,7 +53,6 @@ # W0201: Attribute defined outside __init__ # E0203: Access to member before its definition # E0401: Unable to import -# W0602: Undefined global variable # W0212: Access to a protected member # W0101: Unreachable code # E0110: Instantiated abstract class @@ -98,5 +97,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, R1723, E0102, W0201, E0203, E0401, W0602, W0212, R0904, W0101, + W0246, W0622, W0221, E1111, R1720, R1723, E0102, W0201, E0203, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/common/sentry.py b/pros/common/sentry.py index 4ecacc4f..f161231f 100644 --- a/pros/common/sentry.py +++ b/pros/common/sentry.py @@ -21,7 +21,6 @@ def prompt_to_send(event: Dict[str, Any], hint: Optional[Dict[str, Any]]) -> Opt """ Asks the user for permission to send data to Sentry """ - global cli_config with ui.Notification(): if cli_config is None or (cli_config.offer_sentry is not None and not cli_config.offer_sentry): return diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index 698e6e9c..7f917f48 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -17,7 +17,6 @@ def _machineoutput(obj: Dict[str, Any]): def _machine_notify(method: str, obj: Dict[str, Any], notify_value: Optional[int]): if notify_value is None: - global _current_notify_value notify_value = _current_notify_value obj['type'] = f'notify/{method}' obj['notify_value'] = notify_value @@ -120,7 +119,6 @@ def finalize(method: str, data: Union[str, Dict, object, List[Union[str, Dict, o class _MachineOutputProgressBar(_click_ProgressBar): def __init__(self, *args, **kwargs): - global _current_notify_value kwargs['file'] = open(os.devnull, 'w', encoding='UTF-8') self.notify_value = kwargs.pop('notify_value', _current_notify_value) super(_MachineOutputProgressBar, self).__init__(*args, **kwargs) diff --git a/pros/common/ui/interactive/renderers/MachineOutputRenderer.py b/pros/common/ui/interactive/renderers/MachineOutputRenderer.py index 4bb5eddb..402716e2 100644 --- a/pros/common/ui/interactive/renderers/MachineOutputRenderer.py +++ b/pros/common/ui/interactive/renderers/MachineOutputRenderer.py @@ -13,23 +13,17 @@ def _push_renderer(renderer: 'MachineOutputRenderer'): - global current - stack: List['MachineOutputRenderer'] = current stack.append(renderer) def _remove_renderer(renderer: 'MachineOutputRenderer'): - global current - stack: List['MachineOutputRenderer'] = current if renderer in stack: stack.remove(renderer) def _current_renderer() -> Optional['MachineOutputRenderer']: - global current - stack: List['MachineOutputRenderer'] = current return stack[-1] if len(stack) > 0 else None @@ -39,8 +33,6 @@ def _current_renderer() -> Optional['MachineOutputRenderer']: class MachineOutputRenderer(Renderer[P], Generic[P]): def __init__(self, app: Application[P]): - global current - super().__init__(app) self.alive = False self.thread = None From 97bcccf58c9df53574587b5b1b227d5219646ba6 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:23:31 -0500 Subject: [PATCH 12/58] Fix E0203 and W0201 --- .pylintrc | 4 +--- pros/config/cli_config.py | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index 949d814b..02a30ae4 100644 --- a/.pylintrc +++ b/.pylintrc @@ -50,8 +50,6 @@ # R1720: Unnecessary "else" after "raise" # R1723: Unnecessary "else" after "break" # E0102: Function already defined -# W0201: Attribute defined outside __init__ -# E0203: Access to member before its definition # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -97,5 +95,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, R1723, E0102, W0201, E0203, E0401, W0212, R0904, W0101, + W0246, W0622, W0221, E1111, R1720, R1723, E0102, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/config/cli_config.py b/pros/config/cli_config.py index 8c962047..d18d2ad8 100644 --- a/pros/config/cli_config.py +++ b/pros/config/cli_config.py @@ -21,6 +21,7 @@ def __init__(self, file=None): self.override_use_build_compile_commands: Optional[bool] = None self.offer_sentry: Optional[bool] = None self.ga: Optional[dict] = None + self.cached_upgrade: Optional[Tuple[datetime, 'UpgradeManifestV1']] = None super(CliConfig, self).__init__(file) def needs_online_fetch(self, last_fetch: datetime) -> bool: @@ -36,7 +37,7 @@ def use_build_compile_commands(self): def get_upgrade_manifest(self, force: bool = False) -> Optional['UpgradeManifestV1']: from pros.upgrade.manifests.upgrade_manifest_v1 import UpgradeManifestV1 # noqa: F811 - if not force and not self.needs_online_fetch(self.cached_upgrade[0]): + if not force and self.cached_upgrade is not None and not self.needs_online_fetch(self.cached_upgrade[0]): return self.cached_upgrade[1] pros.common.logger(__name__).info('Fetching upgrade manifest...') import requests From f939b8a81ac77fbb365c482d26c38df2f4ab308a Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:32:46 -0500 Subject: [PATCH 13/58] Fix E0102 --- .pylintrc | 3 +-- pros/common/ui/interactive/components/container.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 02a30ae4..45b63853 100644 --- a/.pylintrc +++ b/.pylintrc @@ -49,7 +49,6 @@ # E1111: Assigning to function call which doesn't return # R1720: Unnecessary "else" after "raise" # R1723: Unnecessary "else" after "break" -# E0102: Function already defined # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -95,5 +94,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, R1723, E0102, E0401, W0212, R0904, W0101, + W0246, W0622, W0221, E1111, R1720, R1723, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/common/ui/interactive/components/container.py b/pros/common/ui/interactive/components/container.py index 8b8615f4..736c4f90 100644 --- a/pros/common/ui/interactive/components/container.py +++ b/pros/common/ui/interactive/components/container.py @@ -1,4 +1,4 @@ -from typing import * +from typing import AnyStr, Optional, Union from pros.common.ui.interactive.parameters import BooleanParameter from .component import Component From db9b198e1c099c3e612b57ecb286b4b996822ceb Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:34:06 -0500 Subject: [PATCH 14/58] Fix R1723 --- .pylintrc | 3 +-- pros/serial/terminal/terminal.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.pylintrc b/.pylintrc index 45b63853..2f1a123a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -48,7 +48,6 @@ # W0221: Arguments number differs from overridden method # E1111: Assigning to function call which doesn't return # R1720: Unnecessary "else" after "raise" -# R1723: Unnecessary "else" after "break" # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -94,5 +93,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, R1723, E0401, W0212, R0904, W0101, + W0246, W0622, W0221, E1111, R1720, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/serial/terminal/terminal.py b/pros/serial/terminal/terminal.py index a0c78264..d65de534 100644 --- a/pros/serial/terminal/terminal.py +++ b/pros/serial/terminal/terminal.py @@ -260,9 +260,8 @@ def transmitter(self): if c == '\x03' or not self.no_sigint: self.stop() break - else: - self.device.write(c.encode(encoding='utf-8')) - self.console.write(c) + self.device.write(c.encode(encoding='utf-8')) + self.console.write(c) except Exception as e: if not self.alive.is_set(): logger(__name__).exception(e) From bbe03fe594035ff3343ab9f7ba7d5dcb19bba187 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:39:20 -0500 Subject: [PATCH 15/58] Fix R1720 --- .pylintrc | 3 +-- pros/cli/terminal.py | 2 +- pros/conductor/project/ProjectTransaction.py | 6 ++---- pros/config/config.py | 8 +++----- pros/serial/devices/vex/v5_device.py | 4 ++-- pros/serial/ports/direct_port.py | 3 +-- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.pylintrc b/.pylintrc index 2f1a123a..27251e53 100644 --- a/.pylintrc +++ b/.pylintrc @@ -47,7 +47,6 @@ # W0622: Redefining built-in # W0221: Arguments number differs from overridden method # E1111: Assigning to function call which doesn't return -# R1720: Unnecessary "else" after "raise" # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -93,5 +92,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, E0401, W0212, R0904, W0101, + W0246, W0622, W0221, E1111, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/terminal.py b/pros/cli/terminal.py index a44b89d5..f8e50bb4 100644 --- a/pros/cli/terminal.py +++ b/pros/cli/terminal.py @@ -73,7 +73,7 @@ def terminal(port: str, backend: str, **kwargs): if backend == 'share': raise NotImplementedError('Share backend is not yet implemented') # ser = SerialSharePort(port) - elif is_v5_user_joystick: + if is_v5_user_joystick: logger(__name__).debug("it's a v5 joystick") ser = V5WirelessPort(port) else: diff --git a/pros/conductor/project/ProjectTransaction.py b/pros/conductor/project/ProjectTransaction.py index edae1330..ac5b2ad0 100644 --- a/pros/conductor/project/ProjectTransaction.py +++ b/pros/conductor/project/ProjectTransaction.py @@ -34,8 +34,7 @@ def execute(self, conductor: c.Conductor, project: c.Project): except InvalidTemplateException as e: if e.reason != TemplateAction.AlreadyInstalled or not self.suppress_already_installed: raise e - else: - ui.logger(__name__).warning(str(e)) + ui.logger(__name__).warning(str(e)) def describe(self, conductor: c.Conductor, project: c.Project): action = project.get_template_actions(conductor.resolve_template(self.template)) @@ -77,8 +76,7 @@ def execute(self, conductor: c.Conductor, project: c.Project): except ValueError as e: if not self.suppress_not_removable: raise e - else: - ui.logger(__name__).warning(str(e)) + ui.logger(__name__).warning(str(e)) def describe(self, conductor: c.Conductor, project: c.Project) -> str: return f'{self.template.identifier} will be removed' diff --git a/pros/config/config.py b/pros/config/config.py index 984b668a..cbb5b736 100644 --- a/pros/config/config.py +++ b/pros/config/config.py @@ -51,9 +51,8 @@ def __init__(self, file, error_on_decode=False): logger(__name__).error(f'Error parsing {file}') logger(__name__).exception(e) raise e - else: - logger(__name__).debug(e) - pass + logger(__name__).debug(e) + pass # obvious elif os.path.isdir(file): raise ValueError('{} must be a file, not a directory'.format(file)) @@ -65,8 +64,7 @@ def __init__(self, file, error_on_decode=False): if error_on_decode: logger(__name__).exception(e) raise e - else: - logger(__name__).debug('Failed to save {} ({})'.format(file, e)) + logger(__name__).debug('Failed to save {} ({})'.format(file, e)) from pros.common.sentry import add_context add_context(self) diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index d1c52f7a..e8f0fce8 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -989,14 +989,14 @@ def _rx_ext_packet(cls, msg: Message, command: int, rx_length: int, check_ack: b } if msg[0] in nacks.keys(): raise VEXCommError("Device NACK'd with reason: {}".format(nacks[msg[0]]), msg) - elif msg[0] != cls.ACK_BYTE: + if msg[0] != cls.ACK_BYTE: raise VEXCommError("Device didn't ACK", msg) msg = msg[1:] if len(msg) > 0: logger(cls).debug('Set msg window to {}'.format(bytes_to_str(msg))) if len(msg) < rx_length and check_length: raise VEXCommError(f'Received length is less than {rx_length} (got {len(msg)}).', msg) - elif len(msg) > rx_length and check_length: + if len(msg) > rx_length and check_length: ui.echo( f'WARNING: Recieved length is more than {rx_length} (got {len(msg)}). Consider upgrading the PROS (CLI Version: {get_version()}).') return msg diff --git a/pros/serial/ports/direct_port.py b/pros/serial/ports/direct_port.py index 4b555b67..5a046cb2 100644 --- a/pros/serial/ports/direct_port.py +++ b/pros/serial/ports/direct_port.py @@ -22,8 +22,7 @@ def create_serial_port(port_name: str, timeout: Optional[float] = 1.0) -> serial ]): tb = sys.exc_info()[2] raise dont_send(ConnectionRefusedException(port_name, e).with_traceback(tb)) from e - else: - raise dont_send(PortNotFoundException(port_name, e)) from e + raise dont_send(PortNotFoundException(port_name, e)) from e From 2ced5b484428b666694120c53e531abc39c4f21d Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:43:19 -0500 Subject: [PATCH 16/58] Fix E1111 --- .pylintrc | 3 +-- pros/serial/devices/vex/cortex_device.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index 27251e53..8813a8e0 100644 --- a/.pylintrc +++ b/.pylintrc @@ -46,7 +46,6 @@ # W0246: Useless parent delegation # W0622: Redefining built-in # W0221: Arguments number differs from overridden method -# E1111: Assigning to function call which doesn't return # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -92,5 +91,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, E0401, W0212, R0904, W0101, + W0246, W0622, W0221, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/serial/devices/vex/cortex_device.py b/pros/serial/devices/vex/cortex_device.py index 02dbfe0f..5fb2dc07 100644 --- a/pros/serial/devices/vex/cortex_device.py +++ b/pros/serial/devices/vex/cortex_device.py @@ -103,10 +103,9 @@ def write_program(self, file: typing.BinaryIO, **kwargs): self.send_to_download_channel() bootloader = self.expose_bootloader() - rv = bootloader.write_program(file, **kwargs) + bootloader.write_program(file, **kwargs) ui.finalize('upload', f'Finished uploading {action_string}') - return rv @retries def query_system(self) -> SystemStatus: From 3b56ae13f448939ce16c212b3517021e5a906fe9 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:47:33 -0500 Subject: [PATCH 17/58] Fix W0221 --- .pylintrc | 3 +-- pros/common/ui/interactive/ConfirmModal.py | 4 ++-- pros/serial/devices/vex/cortex_device.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.pylintrc b/.pylintrc index 8813a8e0..3fb3808f 100644 --- a/.pylintrc +++ b/.pylintrc @@ -45,7 +45,6 @@ # W1113: Keyword argument before variable argument # W0246: Useless parent delegation # W0622: Redefining built-in -# W0221: Arguments number differs from overridden method # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -91,5 +90,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, E0401, W0212, R0904, W0101, + W0246, W0622, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/common/ui/interactive/ConfirmModal.py b/pros/common/ui/interactive/ConfirmModal.py index d4c59235..6c46f036 100644 --- a/pros/common/ui/interactive/ConfirmModal.py +++ b/pros/common/ui/interactive/ConfirmModal.py @@ -14,11 +14,11 @@ def __init__(self, text: str, abort: bool = False, title: AnyStr = 'Please confi super().__init__(title, will_abort=abort, confirm_button='Yes', cancel_button='No', description=text) self.log = log - def confirm(self): + def confirm(self, *args, **kwargs): self.set_return(True) self.exit() - def cancel(self): + def cancel(self, *args, **kwargs): self.set_return(False) super(ConfirmModal, self).cancel() diff --git a/pros/serial/devices/vex/cortex_device.py b/pros/serial/devices/vex/cortex_device.py index 5fb2dc07..e15190c0 100644 --- a/pros/serial/devices/vex/cortex_device.py +++ b/pros/serial/devices/vex/cortex_device.py @@ -89,7 +89,7 @@ def upload_project(self, project: Project, **kwargs): with output_path.open(mode='rb') as pf: return self.write_program(pf, **kwargs) - def write_program(self, file: typing.BinaryIO, **kwargs): + def write_program(self, file: typing.BinaryIO, quirk: int = 0, **kwargs): action_string = '' if hasattr(file, 'name'): action_string += f' {Path(file.name).name}' From 53666cd1f05f80519d424109bb28a88f12918090 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 19:08:13 -0500 Subject: [PATCH 18/58] Fix W0622 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 4 ++-- pros/cli/common.py | 8 ++++---- pros/cli/upload.py | 4 ++-- pros/common/ui/__init__.py | 4 ++-- pros/common/ui/interactive/parameters/misc_parameters.py | 8 ++++---- pros/serial/ports/serial_share_bridge.py | 4 ++-- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.pylintrc b/.pylintrc index 3fb3808f..fb70008f 100644 --- a/.pylintrc +++ b/.pylintrc @@ -44,7 +44,6 @@ # C0201: Consider iterating over a dict instead of calling keys # W1113: Keyword argument before variable argument # W0246: Useless parent delegation -# W0622: Redefining built-in # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -90,5 +89,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, E0401, W0212, R0904, W0101, + W0246, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 27dbf73f..5c84093a 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -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'): diff --git a/pros/cli/common.py b/pros/cli/common.py index 8d2ca312..e2f48b2d 100644 --- a/pros/cli/common.py +++ b/pros/cli/common.py @@ -231,12 +231,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. @@ -246,7 +246,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: @@ -268,7 +268,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 diff --git a/pros/cli/upload.py b/pros/cli/upload.py index 05cc1476..43597fd5 100644 --- a/pros/cli/upload.py +++ b/pros/cli/upload.py @@ -1,4 +1,4 @@ -from sys import exit +import sys from unicodedata import name import pros.common.ui as ui @@ -155,7 +155,7 @@ def upload(path: Optional[str], project: Optional[c.Project], port: str, **kwarg device.write_program(pf, **kwargs) except Exception as e: logger(__name__).exception(e, exc_info=True) - exit(1) + sys.exit(1) @upload_cli.command('lsusb', aliases=['ls-usb', 'ls-devices', 'lsdev', 'list-usb', 'list-devices']) @click.option('--target', type=click.Choice(['v5', 'cortex']), default=None, required=False) diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index 7f917f48..5524ab3f 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -51,7 +51,7 @@ def confirm(text: str, default: bool = False, abort: bool = False, prompt_suffix def prompt(text, default=None, hide_input=False, - confirmation_prompt=False, type=None, + confirmation_prompt=False, value_type=None, value_proc=None, prompt_suffix=': ', show_default=True, err=False): if ismachineoutput(): @@ -59,7 +59,7 @@ def prompt(text, default=None, hide_input=False, pass else: return click.prompt(text, default=default, hide_input=hide_input, confirmation_prompt=confirmation_prompt, - type=type, value_proc=value_proc, prompt_suffix=prompt_suffix, show_default=show_default, + type=value_type, value_proc=value_proc, prompt_suffix=prompt_suffix, show_default=show_default, err=err) diff --git a/pros/common/ui/interactive/parameters/misc_parameters.py b/pros/common/ui/interactive/parameters/misc_parameters.py index f19edba9..36bbe9f8 100644 --- a/pros/common/ui/interactive/parameters/misc_parameters.py +++ b/pros/common/ui/interactive/parameters/misc_parameters.py @@ -25,15 +25,15 @@ def update(self, new_value): class RangeParameter(ValidatableParameter[int]): - def __init__(self, initial_value: int, range: Tuple[int, int]): + def __init__(self, initial_value: int, value_range: Tuple[int, int]): super().__init__(initial_value) - self.range = range + self.value_range = value_range def validate(self, value: T): - if self.range[0] <= value <= self.range[1]: + if self.value_range[0] <= value <= self.value_range[1]: return True else: - return f'{value} is not within [{self.range[0]}, {self.range[1]}]' + return f'{value} is not within [{self.value_range[0]}, {self.value_range[1]}]' def update(self, new_value): super(RangeParameter, self).update(int(new_value)) diff --git a/pros/serial/ports/serial_share_bridge.py b/pros/serial/ports/serial_share_bridge.py index b632a5dc..fcc817e8 100644 --- a/pros/serial/ports/serial_share_bridge.py +++ b/pros/serial/ports/serial_share_bridge.py @@ -11,8 +11,8 @@ from .. import bytes_to_str -def get_port_num(serial_port_name: str, hash: str) -> int: - return sum("Powered by PROS: {}-{}".format(serial_port_name, hash).encode(encoding='ascii')) +def get_port_num(serial_port_name: str, hash_value: str) -> int: + return sum("Powered by PROS: {}-{}".format(serial_port_name, hash_value).encode(encoding='ascii')) def get_from_device_port_num(serial_port_name: str) -> int: From effdeb3367828b7b737e16a5b2b2161430ed6429 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:50:00 -0500 Subject: [PATCH 19/58] Fix W0246 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index fb70008f..7f42a9b1 100644 --- a/.pylintrc +++ b/.pylintrc @@ -43,7 +43,6 @@ # W0640: Cell variable from loop # C0201: Consider iterating over a dict instead of calling keys # W1113: Keyword argument before variable argument -# W0246: Useless parent delegation # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -89,5 +88,5 @@ disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120 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, E0401, W0212, R0904, W0101, + E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 5c84093a..b166d573 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -65,9 +65,9 @@ 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) + pass class PROSOption(click.Option): From 0b58dc5d9124efe5b7688e7de5f02357bb331c06 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:52:00 -0500 Subject: [PATCH 20/58] Fix W1113 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 7f42a9b1..6ead6b43 100644 --- a/.pylintrc +++ b/.pylintrc @@ -42,7 +42,6 @@ # W3101: Missing timeout # W0640: Cell variable from loop # C0201: Consider iterating over a dict instead of calling keys -# W1113: Keyword argument before variable argument # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -87,6 +86,6 @@ 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, + E0602, W1309, C0325, E1101, R1714, R0916, W0719, R1734, E1133, W1201, W0107, W3101, W0640, C0201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index b166d573..4e4f9519 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -118,7 +118,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): From 11b23cd02fe6da476c82f34c51362694f2311b37 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:58:26 -0500 Subject: [PATCH 21/58] Fix C0201 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 2 +- pros/serial/devices/vex/v5_device.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index 6ead6b43..ad28049d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -41,7 +41,6 @@ # W0107: Unnecessary pass statement # W3101: Missing timeout # W0640: Cell variable from loop -# C0201: Consider iterating over a dict instead of calling keys # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -86,6 +85,6 @@ 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, + E0602, W1309, C0325, E1101, R1714, R0916, W0719, R1734, E1133, W1201, W0107, W3101, W0640, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 4e4f9519..148a75b3 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -140,7 +140,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 diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index e8f0fce8..e8707d33 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -987,7 +987,7 @@ def _rx_ext_packet(cls, msg: Message, command: int, rx_length: int, check_ack: b 0xDA: "Max user files, no more room for another user program", 0xDB: "User file exists" } - if msg[0] in nacks.keys(): + if msg[0] in nacks: raise VEXCommError("Device NACK'd with reason: {}".format(nacks[msg[0]]), msg) if msg[0] != cls.ACK_BYTE: raise VEXCommError("Device didn't ACK", msg) From cce01993700c91a72f9228f89c31b248618a0c38 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:01:10 -0500 Subject: [PATCH 22/58] Fix W0640 --- .pylintrc | 3 +-- pros/cli/conductor.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index ad28049d..f38b4d16 100644 --- a/.pylintrc +++ b/.pylintrc @@ -40,7 +40,6 @@ # E1133: Not an iterable # W0107: Unnecessary pass statement # W3101: Missing timeout -# W0640: Cell variable from loop # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -85,6 +84,6 @@ 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, + E0602, W1309, C0325, E1101, R1714, R0916, W0719, R1734, E1133, W1201, W0107, W3101, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index 0db800d3..bdb393b9 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -320,8 +320,8 @@ 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)) From 695232937a5ebc7b68ecf26e963c5619bf554d3d Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:20:52 -0500 Subject: [PATCH 23/58] Fix W3101 --- .pylintrc | 3 +-- pros/common/utils.py | 2 +- pros/conductor/depots/http_depot.py | 2 +- pros/config/cli_config.py | 2 +- pros/upgrade/upgrade_manager.py | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.pylintrc b/.pylintrc index f38b4d16..01ec2e94 100644 --- a/.pylintrc +++ b/.pylintrc @@ -39,7 +39,6 @@ # W0719: Broad exception raised # E1133: Not an iterable # W0107: Unnecessary pass statement -# W3101: Missing timeout # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -84,6 +83,6 @@ 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, + E0602, W1309, C0325, E1101, R1714, R0916, W0719, R1734, E1133, W1201, W0107, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/common/utils.py b/pros/common/utils.py index d74d9a2d..e926afb5 100644 --- a/pros/common/utils.py +++ b/pros/common/utils.py @@ -114,7 +114,7 @@ def download_file(url: str, ext: Optional[str] = None, desc: Optional[str] = Non # from rfc6266_parser import parse_requests_response import re - response = requests.get(url, stream=True) + response = requests.get(url, stream=True, timeout=10) if response.status_code == 200: filename: str = url.rsplit('/', 1)[-1] if 'Content-Disposition' in response.headers.keys(): diff --git a/pros/conductor/depots/http_depot.py b/pros/conductor/depots/http_depot.py index dc7e3a25..9f5accec 100644 --- a/pros/conductor/depots/http_depot.py +++ b/pros/conductor/depots/http_depot.py @@ -35,7 +35,7 @@ def fetch_template(self, template: BaseTemplate, destination: str, **kwargs): def update_remote_templates(self, **_): import requests - response = requests.get(self.location) + response = requests.get(self.location, timeout=10) if response.status_code == 200: self.remote_templates = jsonpickle.decode(response.text) else: diff --git a/pros/config/cli_config.py b/pros/config/cli_config.py index d18d2ad8..d508a999 100644 --- a/pros/config/cli_config.py +++ b/pros/config/cli_config.py @@ -42,7 +42,7 @@ def get_upgrade_manifest(self, force: bool = False) -> Optional['UpgradeManifest pros.common.logger(__name__).info('Fetching upgrade manifest...') import requests import jsonpickle - r = requests.get('https://purduesigbots.github.io/pros-mainline/cli-updates.json') + r = requests.get('https://purduesigbots.github.io/pros-mainline/cli-updates.json', timeout=10) pros.common.logger(__name__).debug(r) if r.status_code == 200: try: diff --git a/pros/upgrade/upgrade_manager.py b/pros/upgrade/upgrade_manager.py index 3ddcf8eb..a4a216f8 100644 --- a/pros/upgrade/upgrade_manager.py +++ b/pros/upgrade/upgrade_manager.py @@ -49,7 +49,7 @@ def get_manifest(self, force: bool = False) -> UpgradeManifestV1: manifest_urls = [f"{channel_url}/{manifest.__name__}.json" for manifest in manifests] for manifest_url in manifest_urls: - resp = requests.get(manifest_url) + resp = requests.get(manifest_url, timeout=10) if resp.status_code == 200: try: self._manifest = jsonpickle.decode(resp.text, keys=True) From 29f9a7fec92c794676656d06afcee660ac9b0b98 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:23:11 -0500 Subject: [PATCH 24/58] Fix W0107 --- .pylintrc | 3 +-- pros/cli/common.py | 1 - pros/cli/conductor.py | 1 - pros/common/ui/interactive/components/label.py | 1 - pros/config/config.py | 1 - 5 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.pylintrc b/.pylintrc index 01ec2e94..2df12329 100644 --- a/.pylintrc +++ b/.pylintrc @@ -38,7 +38,6 @@ # R0916: Too many boolean expressions in if statement # W0719: Broad exception raised # E1133: Not an iterable -# W0107: Unnecessary pass statement # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -83,6 +82,6 @@ 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, + E0602, W1309, C0325, E1101, R1714, R0916, W0719, R1734, E1133, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/common.py b/pros/cli/common.py index e2f48b2d..1724e10e 100644 --- a/pros/cli/common.py +++ b/pros/cli/common.py @@ -139,7 +139,6 @@ def callback(ctx: click.Context, param: click.Parameter, value: bool): if value: echo("Not sending analytics for this command.\n") analytics.useAnalytics = False - pass 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__ diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index bdb393b9..8e46c24c 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -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', diff --git a/pros/common/ui/interactive/components/label.py b/pros/common/ui/interactive/components/label.py index 8b060300..6b2e13ce 100644 --- a/pros/common/ui/interactive/components/label.py +++ b/pros/common/ui/interactive/components/label.py @@ -18,7 +18,6 @@ class VerbatimLabel(Label): """ Should be displayed with a monospace font """ - pass class Spinner(Label): diff --git a/pros/config/config.py b/pros/config/config.py index cbb5b736..440767c5 100644 --- a/pros/config/config.py +++ b/pros/config/config.py @@ -52,7 +52,6 @@ def __init__(self, file, error_on_decode=False): logger(__name__).exception(e) raise e logger(__name__).debug(e) - pass # obvious elif os.path.isdir(file): raise ValueError('{} must be a file, not a directory'.format(file)) From 4265e8d62cf30ad546d69834b304fda52ad747a0 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:47:53 -0500 Subject: [PATCH 25/58] Fix E1133 --- .pylintrc | 3 +-- pros/common/utils.py | 1 + pros/upgrade/manifests/upgrade_manifest_v2.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 2df12329..43a7b49b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -37,7 +37,6 @@ # R1714: Consider using in # R0916: Too many boolean expressions in if statement # W0719: Broad exception raised -# E1133: Not an iterable # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -82,6 +81,6 @@ 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, + E0602, W1309, C0325, E1101, R1714, R0916, W0719, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/common/utils.py b/pros/common/utils.py index e926afb5..b1077119 100644 --- a/pros/common/utils.py +++ b/pros/common/utils.py @@ -33,6 +33,7 @@ def get_version(): else: import pros.cli.main module = pros.cli.main.__name__ + # pylint: disable=not-an-iterable for dist in pkg_resources.working_set: scripts = dist.get_entry_map().get('console_scripts') or {} for _, entry_point in iter(scripts.items()): diff --git a/pros/upgrade/manifests/upgrade_manifest_v2.py b/pros/upgrade/manifests/upgrade_manifest_v2.py index b024aa3d..dfebbf0f 100644 --- a/pros/upgrade/manifests/upgrade_manifest_v2.py +++ b/pros/upgrade/manifests/upgrade_manifest_v2.py @@ -51,6 +51,7 @@ def platform(self) -> 'PlatformsV2': else: try: from pip._vendor import pkg_resources + # pylint: disable=not-an-iterable results = [p for p in pkg_resources.working_set if p.project_name.startswith('pros-cli')] if any(results): self._platform = PlatformsV2.Pip From 0b32d6cc1874ca5ce882fc5c6681587c0f271c0b Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:50:33 -0500 Subject: [PATCH 26/58] Fix W0719 --- .pylintrc | 3 +-- pros/conductor/conductor.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 43a7b49b..15636924 100644 --- a/.pylintrc +++ b/.pylintrc @@ -36,7 +36,6 @@ # E1101: Nonexistent member # R1714: Consider using in # R0916: Too many boolean expressions in if statement -# W0719: Broad exception raised # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -81,6 +80,6 @@ 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, W1201, + E0602, W1309, C0325, E1101, R1714, R0916, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index e35d9046..343fce31 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -255,7 +255,7 @@ def resolve_template(self, identifier: Union[str, BaseTemplate], **kwargs) -> Op # there's a local template satisfying the query if len(local_templates) > 1: # This should never happen! Conductor state must be invalid - raise Exception(f'Multiple local templates satisfy {query.identifier}!') + raise RuntimeError(f'Multiple local templates satisfy {query.identifier}!') return local_templates[0] # prefer pros-mainline template second From eca98fd78abbdd71cc8f5662698c42b55f5c36cc Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:53:07 -0500 Subject: [PATCH 27/58] Fix R0916 --- .pylintrc | 3 +-- pros/conductor/conductor.py | 10 ++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.pylintrc b/.pylintrc index 15636924..2292505b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -35,7 +35,6 @@ # C0325: Unnecessary parenthesis # E1101: Nonexistent member # R1714: Consider using in -# R0916: Too many boolean expressions in if statement # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -80,6 +79,6 @@ 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, R1734, W1201, + E0602, W1309, C0325, E1101, R1714, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index 343fce31..7322a197 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -325,10 +325,12 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate], raise dont_send( InvalidTemplateException(f'{template.identifier} is not applicable to {project}', reason=valid_action) ) - if force \ - or (valid_action == TemplateAction.Upgradable and upgrade_ok) \ - or (valid_action == TemplateAction.Installable and install_ok) \ - or (valid_action == TemplateAction.Downgradable and downgrade_ok): + should_apply = force \ + or (valid_action == TemplateAction.Upgradable and upgrade_ok) \ + or (valid_action == TemplateAction.Installable and install_ok) \ + or (valid_action == TemplateAction.Downgradable and downgrade_ok) + + if should_apply: project.apply_template(template, force_system=kwargs.pop('force_system', False), force_user=kwargs.pop('force_user', False), remove_empty_directories=kwargs.pop('remove_empty_directories', False)) From 56e808b0cfa9d7b607116ae3ffea2b9694826bf1 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:55:40 -0500 Subject: [PATCH 28/58] Fix R1714 --- .pylintrc | 3 +-- pros/conductor/project/__init__.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 2292505b..e02c5da6 100644 --- a/.pylintrc +++ b/.pylintrc @@ -34,7 +34,6 @@ # W1309: Using an f-string that does not have any interpolated variables # C0325: Unnecessary parenthesis # E1101: Nonexistent member -# R1714: Consider using in # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code @@ -79,6 +78,6 @@ 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, R1734, W1201, + E0602, W1309, C0325, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index a0acbc61..53cfea12 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -114,7 +114,7 @@ def apply_template(self, template: LocalTemplate, force_system: bool = False, fo transaction = Transaction(self.location, set(self.all_files)) installed_user_files = set() for lib_name, lib in self.templates.items(): - if lib_name == template.name or lib.name == template.name: + if template.name in (lib_name, lib.name): logger(__name__).debug(f'{lib} is already installed') logger(__name__).debug(lib.system_files) logger(__name__).debug(lib.user_files) From 31ead6472dbee2bbebfe99ab6c76b9dd9538f5e0 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:05:59 -0500 Subject: [PATCH 29/58] Fix C0325 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 2 +- pros/serial/devices/vex/cortex_device.py | 14 +++++++------- pros/serial/devices/vex/crc.py | 2 +- pros/serial/devices/vex/v5_device.py | 6 +++--- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.pylintrc b/.pylintrc index e02c5da6..fae718ea 100644 --- a/.pylintrc +++ b/.pylintrc @@ -32,7 +32,6 @@ # W1510: Subprocess run without explicitly defining check # E0602: Undefined variable # W1309: Using an f-string that does not have any interpolated variables -# C0325: Unnecessary parenthesis # E1101: Nonexistent member # E0401: Unable to import # W0212: Access to a protected member @@ -78,6 +77,6 @@ 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, R1734, W1201, + E0602, W1309, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 148a75b3..3d64146c 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -160,7 +160,7 @@ def invoke(self, *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 + if isProject: #check if there is a project curr_proj = p() click.echo("PROS-Kernel Version: {}".format(curr_proj.kernel)) raise e diff --git a/pros/serial/devices/vex/cortex_device.py b/pros/serial/devices/vex/cortex_device.py index e15190c0..978e1c0d 100644 --- a/pros/serial/devices/vex/cortex_device.py +++ b/pros/serial/devices/vex/cortex_device.py @@ -39,13 +39,13 @@ def __str__(self): f'{self.joystick_battery:1.2f} V' class SystemStatusFlags(IntFlag): - DL_MODE = (1 << 0) - TETH_VN2 = (1 << 2) - FCS_CONNECT = (1 << 3) - TETH_USB = (1 << 4) - DIRECT_USB = (1 << 5) - FCS_AUTON = (1 << 6) - FCS_DISABLE = (1 << 7) + DL_MODE = 1 << 0 + TETH_VN2 = 1 << 2 + FCS_CONNECT = 1 << 3 + TETH_USB = 1 << 4 + DIRECT_USB = 1 << 5 + FCS_AUTON = 1 << 6 + FCS_DISABLE = 1 << 7 TETH_BITS = DL_MODE | TETH_VN2 | TETH_USB diff --git a/pros/serial/devices/vex/crc.py b/pros/serial/devices/vex/crc.py index 2e4270d7..abc7fa6e 100644 --- a/pros/serial/devices/vex/crc.py +++ b/pros/serial/devices/vex/crc.py @@ -13,7 +13,7 @@ def __init__(self, size: int, polynomial: int): if crc_accumulator & (1 << (self._size - 1)): crc_accumulator = (crc_accumulator << 1) ^ self._polynomial else: - crc_accumulator = (crc_accumulator << 1) + crc_accumulator = crc_accumulator << 1 self._table.append(crc_accumulator) def compute(self, data: Iterable[int], accumulator: int = 0): diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index e8707d33..c267e959 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -804,7 +804,7 @@ def set_program_file_metadata(self, file_name: str, **kwargs): if isinstance(options['vid'], str): options['vid'] = self.vid_map[options['vid'].lower()] if isinstance(options['timestamp'], datetime): - assert (isinstance(options['timestamp'], datetime)) + assert isinstance(options['timestamp'], datetime) options['timestamp'] = (options['timestamp'] - datetime(2000, 1, 1)).get_seconds() if isinstance(options['type'], str): options['type'] = options['type'].encode(encoding='ascii') @@ -965,10 +965,10 @@ def _rx_ext_packet(cls, msg: Message, command: int, rx_length: int, check_ack: b :param tx_payload: what was sent, used if an exception needs to be thrown :return: The payload of the extended message """ - assert (msg['command'] == 0x56) + assert msg['command'] == 0x56 if not cls.VEX_CRC16.compute(msg.rx) == 0: raise VEXCommError("CRC of message didn't match 0: {}".format(cls.VEX_CRC16.compute(msg.rx)), msg) - assert (msg['payload'][0] == command) + assert msg['payload'][0] == command msg = msg['payload'][1:-2] if check_ack: nacks = { From 38251ef9f61b4f5dca17e57a2358e2373d9ff979 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:09:39 -0500 Subject: [PATCH 30/58] Fix W1309 --- .pylintrc | 3 +- pros/cli/conductor_utils.py | 2 +- pros/cli/misc_commands.py | 2 +- pros/conductor/conductor.py | 32 ++++++++++---------- pros/conductor/project/ProjectTransaction.py | 2 +- pros/conductor/project/__init__.py | 2 +- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.pylintrc b/.pylintrc index fae718ea..9a5125be 100644 --- a/.pylintrc +++ b/.pylintrc @@ -31,7 +31,6 @@ # R1718: Consider using set comprehension # W1510: Subprocess run without explicitly defining check # E0602: Undefined variable -# W1309: Using an f-string that does not have any interpolated variables # E1101: Nonexistent member # E0401: Unable to import # W0212: Access to a protected member @@ -77,6 +76,6 @@ 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, E1101, R1734, W1201, + E0602, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303 diff --git a/pros/cli/conductor_utils.py b/pros/cli/conductor_utils.py index cb22cffc..24128073 100644 --- a/pros/cli/conductor_utils.py +++ b/pros/cli/conductor_utils.py @@ -165,7 +165,7 @@ def purge_template(query: c.BaseTemplate, force): 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) diff --git a/pros/cli/misc_commands.py b/pros/cli/misc_commands.py index d212a2fc..93002c80 100644 --- a/pros/cli/misc_commands.py +++ b/pros/cli/misc_commands.py @@ -37,6 +37,6 @@ def upgrade(force_check, no_install): ui.finalize('upgradeInfo', manifest) if not no_install: if not manager.can_perform_upgrade: - ui.logger(__name__).error(f'This manifest cannot perform the upgrade.') + ui.logger(__name__).error('This manifest cannot perform the upgrade.') return -3 ui.finalize('upgradeComplete', manager.perform_upgrade()) diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index 7322a197..2315c9c1 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -289,21 +289,21 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate], curr_proj = Project() 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'Do you still want to upgrade?') + confirm = ui.confirm('Warning! Upgrading project to PROS 4 will cause breaking changes. ' + 'Do you still want to upgrade?') if not confirm: raise dont_send( - InvalidTemplateException(f'Not upgrading')) + InvalidTemplateException('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. ' - f'Do you still want to downgrade?') + confirm = ui.confirm('Warning! Downgrading project to PROS 3 will cause breaking changes. ' + 'Do you still want to downgrade?') if not confirm: raise dont_send( - InvalidTemplateException(f'Not downgrading')) + InvalidTemplateException('Not downgrading')) elif not project.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 want to use PROS 4 instead?') + confirm = ui.confirm('PROS 4 is now in early access. ' + 'Please use the --early-access flag if you would like to use it.\n' + 'Do you want to use PROS 4 instead?') self.warn_early_access = True if confirm: # use pros 4 project.use_early_access = True @@ -362,20 +362,20 @@ def new_project(self, path: str, no_default_libs: bool = False, **kwargs) -> Pro kwargs["early_access"] = use_early_access if kwargs["version_source"]: # If true, then the user has not specified a version if not 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.") + ui.echo("PROS 4 is now in early access. " + "If you would like to use it, use the --early-access flag.") elif not use_early_access 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 want to use PROS 4 instead?') + confirm = ui.confirm('PROS 4 is now in early access. ' + 'Please use the --early-access flag if you would like to use it.\n' + 'Do you want to use PROS 4 instead?') self.warn_early_access = True if confirm: use_early_access = True kwargs['early_access'] = True elif use_early_access: - ui.echo(f'Early access is enabled. Using PROS 4.') + ui.echo('Early access is enabled. Using PROS 4.') elif use_early_access: - ui.echo(f'Early access is enabled.') + ui.echo('Early access is enabled.') if not is_pathname_valid(str(Path(path).absolute())): raise dont_send(ValueError('Project path contains invalid characters.')) diff --git a/pros/conductor/project/ProjectTransaction.py b/pros/conductor/project/ProjectTransaction.py index ac5b2ad0..0e5e0974 100644 --- a/pros/conductor/project/ProjectTransaction.py +++ b/pros/conductor/project/ProjectTransaction.py @@ -133,7 +133,7 @@ def execute(self): raise ValueError('Action did not complete successfully') ui.echo('All actions performed successfully') except Exception as e: - ui.logger(__name__).warning(f'Failed to perform transaction, restoring project to previous state') + ui.logger(__name__).warning('Failed to perform transaction, restoring project to previous state') with zipfile.ZipFile(tfn) as zf: with ui.progressbar(zf.namelist(), label=f'Restoring {self.project.name} from {tfn}') as pb: diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index 53cfea12..90ce3ef0 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -167,7 +167,7 @@ def remove_template(self, template: Template, remove_user: bool = False, remove_ if not self.template_is_installed(template): raise ValueError(f'{template.identifier} is not installed on this project.') if template.name == 'kernel': - raise ValueError(f'Cannot remove the kernel template. Maybe create a new project?') + raise ValueError('Cannot remove the kernel template. Maybe create a new project?') real_template = LocalTemplate(orig=template, location=self.location) transaction = Transaction(self.location, set(self.all_files)) From d338e19f4799bb3e4a72dd23be57775d8b675853 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:20:40 -0500 Subject: [PATCH 31/58] Add W4902 --- .pylintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 9a5125be..a2af278e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -36,6 +36,7 @@ # W0212: Access to a protected member # W0101: Unreachable code # E0110: Instantiated abstract class +# W4902: Using deprecated method # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -78,4 +79,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, E1101, R1734, W1201, E0401, W0212, R0904, W0101, - C0302, E0110, W0603, R0401, C0303 + C0302, E0110, W0603, R0401, C0303, W4902 From 07eca48e9f0390b78c6858203ba754ecbe8178c2 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:24:09 -0500 Subject: [PATCH 32/58] Fix E0602 --- .pylintrc | 3 +-- pros/conductor/conductor.py | 1 + pros/conductor/project/__init__.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index a2af278e..515ff7dc 100644 --- a/.pylintrc +++ b/.pylintrc @@ -30,7 +30,6 @@ # W1514: Using open without explicitly specifying an encoding # R1718: Consider using set comprehension # W1510: Subprocess run without explicitly defining check -# E0602: Undefined variable # E1101: Nonexistent member # E0401: Unable to import # W0212: Access to a protected member @@ -77,6 +76,6 @@ 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, E1101, R1734, W1201, + E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303, W4902 diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index 2315c9c1..4a1ff067 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -11,6 +11,7 @@ from semantic_version import Spec, Version from pros.common import * +import pros.common.ui as ui from pros.conductor.project import TemplateAction from pros.conductor.project.template_resolution import InvalidTemplateException from pros.config import Config diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index 90ce3ef0..7cc6a67f 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -7,6 +7,7 @@ from typing import * from pros.common import * +import pros.common.ui as ui from pros.common.ui import EchoPipe from pros.conductor.project.template_resolution import TemplateAction from pros.config.config import Config, ConfigNotFoundException From ac262f0506e920f5ffd0014e0b846e20a0d7d7ae Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:28:22 -0500 Subject: [PATCH 33/58] Fix W1510 --- .pylintrc | 3 +-- pros/conductor/project/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index 515ff7dc..b0659527 100644 --- a/.pylintrc +++ b/.pylintrc @@ -29,7 +29,6 @@ # R1732: Consider using with # W1514: Using open without explicitly specifying an encoding # R1718: Consider using set comprehension -# W1510: Subprocess run without explicitly defining check # E1101: Nonexistent member # E0401: Unable to import # W0212: Access to a protected member @@ -75,7 +74,7 @@ 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, + W0108, R0912, R0911, W0511, E1136, R0902, W0611, C0412, C0103, C0301, R1732, R0915, W1514, R1718, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303, W4902 diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index 7cc6a67f..fbfd0d7f 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -330,7 +330,7 @@ def libscanbuild_capture(args: argparse.Namespace) -> Tuple[int, Iterable[Compil if os.environ.get('PROS_TOOLCHAIN'): env['PATH'] = os.path.join(os.environ.get('PROS_TOOLCHAIN'), 'bin') + os.pathsep + env['PATH'] cc_sysroot = subprocess.run([make_cmd, 'cc-sysroot'], env=env, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, cwd=self.directory) + stderr=subprocess.PIPE, cwd=self.directory, check=False) lines = str(cc_sysroot.stderr.decode()).splitlines() + str(cc_sysroot.stdout.decode()).splitlines() lines = [l.strip() for l in lines] cc_sysroot_includes = [] @@ -345,7 +345,7 @@ def libscanbuild_capture(args: argparse.Namespace) -> Tuple[int, Iterable[Compil if copy: cc_sysroot_includes.append(f'-isystem{line}') cxx_sysroot = subprocess.run([make_cmd, 'cxx-sysroot'], env=env, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, cwd=self.directory) + stderr=subprocess.PIPE, cwd=self.directory, check=False) lines = str(cxx_sysroot.stderr.decode()).splitlines() + str(cxx_sysroot.stdout.decode()).splitlines() lines = [l.strip() for l in lines] cxx_sysroot_includes = [] From cc52de8c3579633a7285434a03575f10d88bf7ca Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:31:53 -0500 Subject: [PATCH 34/58] Fix R1718 --- .pylintrc | 3 +-- pros/conductor/project/__init__.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index b0659527..6a02e11c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -28,7 +28,6 @@ # C0103: Variable name doesn't conform to naming style # R1732: Consider using with # W1514: Using open without explicitly specifying an encoding -# R1718: Consider using set comprehension # E1101: Nonexistent member # E0401: Unable to import # W0212: Access to a protected member @@ -74,7 +73,7 @@ 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, + W0108, R0912, R0911, W0511, E1136, R0902, W0611, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303, W4902 diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index fbfd0d7f..2ea4812c 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -360,7 +360,7 @@ def libscanbuild_capture(args: argparse.Namespace) -> Tuple[int, Iterable[Compil if copy: cxx_sysroot_includes.append(f'-isystem{line}') new_entries, entries = itertools.tee(entries, 2) - new_sources = set([e.source for e in entries]) + new_sources = {e.source for e in entries} if not cdb_file: cdb_file = os.path.join(self.directory, 'compile_commands.json') if isinstance(cdb_file, str) and os.path.isfile(cdb_file): From 6661f0a34df2518fdfaa626c578bbb6781308c8a Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:59:25 -0500 Subject: [PATCH 35/58] Fix W0611 --- .pylintrc | 3 +-- pros/cli/interactive.py | 1 - pros/cli/main.py | 3 +-- pros/cli/terminal.py | 1 - pros/cli/upload.py | 1 - pros/conductor/conductor.py | 2 -- pros/ga/analytics.py | 3 --- pros/serial/devices/vex/v5_device.py | 1 - 8 files changed, 2 insertions(+), 13 deletions(-) diff --git a/.pylintrc b/.pylintrc index 6a02e11c..05261bfb 100644 --- a/.pylintrc +++ b/.pylintrc @@ -24,7 +24,6 @@ # W0108: Lambda may not be necessary # W0511: TODO # E1136: Value is unsubscriptable -# W0611: Unused import # C0103: Variable name doesn't conform to naming style # R1732: Consider using with # W1514: Using open without explicitly specifying an encoding @@ -73,7 +72,7 @@ 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, + W0108, R0912, R0911, W0511, E1136, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303, W4902 diff --git a/pros/cli/interactive.py b/pros/cli/interactive.py index 634f1b2f..1fb3c09f 100644 --- a/pros/cli/interactive.py +++ b/pros/cli/interactive.py @@ -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(): diff --git a/pros/cli/main.py b/pros/cli/main.py index 8e4d6725..f7b8bd3d 100644 --- a/pros/cli/main.py +++ b/pros/cli/main.py @@ -17,7 +17,6 @@ from pros.common.utils import get_version, logger from pros.ga.analytics import analytics -import jsonpickle import pros.cli.build import pros.cli.conductor import pros.cli.conductor_utils @@ -102,7 +101,7 @@ def use_analytics(ctx: click.Context, param, value): analytics.set_use(touse) 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 diff --git a/pros/cli/terminal.py b/pros/cli/terminal.py index f8e50bb4..55a705fc 100644 --- a/pros/cli/terminal.py +++ b/pros/cli/terminal.py @@ -44,7 +44,6 @@ def terminal(port: str, backend: str, **kwargs): Note: share backend is not yet implemented. """ analytics.send("terminal") - from pros.serial.devices.vex.v5_user_device import V5UserDevice from pros.serial.terminal import Terminal is_v5_user_joystick = False if port == 'default': diff --git a/pros/cli/upload.py b/pros/cli/upload.py index 43597fd5..ece08692 100644 --- a/pros/cli/upload.py +++ b/pros/cli/upload.py @@ -1,5 +1,4 @@ import sys -from unicodedata import name import pros.common.ui as ui import pros.conductor as c diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index 4a1ff067..cf009660 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -1,11 +1,9 @@ import errno import os.path import shutil -from enum import Enum from pathlib import Path import sys from typing import * -import re import click from semantic_version import Spec, Version diff --git a/pros/ga/analytics.py b/pros/ga/analytics.py index 247e6b31..209bf5c6 100644 --- a/pros/ga/analytics.py +++ b/pros/ga/analytics.py @@ -1,7 +1,4 @@ -import json -from os import path import uuid -import requests from requests_futures.sessions import FuturesSession import random from concurrent.futures import as_completed diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index c267e959..f0190e1b 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -843,7 +843,6 @@ def get_device_status(self): @retries def get_system_status(self) -> SystemStatus: - from semantic_version import Version logger(__name__).debug('Sending ext 0x22 command') version = self.query_system_version() if (version.product == V5Device.SystemVersion.Product.BRAIN and version.system_version in Spec('<1.0.13')) or \ From 3812947cce44ff46ea6f73b57532056c71d184af Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 00:09:26 -0500 Subject: [PATCH 36/58] Fix E1136 --- .pylintrc | 3 +-- pros/serial/ports/serial_share_bridge.py | 1 + pros/serial/ports/serial_share_port.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 05261bfb..82c43c76 100644 --- a/.pylintrc +++ b/.pylintrc @@ -23,7 +23,6 @@ # W0613: Unused argument # W0108: Lambda may not be necessary # W0511: TODO -# E1136: Value is unsubscriptable # C0103: Variable name doesn't conform to naming style # R1732: Consider using with # W1514: Using open without explicitly specifying an encoding @@ -72,7 +71,7 @@ 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, C0412, C0103, C0301, R1732, R0915, W1514, + W0108, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303, W4902 diff --git a/pros/serial/ports/serial_share_bridge.py b/pros/serial/ports/serial_share_bridge.py index fcc817e8..54259f4f 100644 --- a/pros/serial/ports/serial_share_bridge.py +++ b/pros/serial/ports/serial_share_bridge.py @@ -156,6 +156,7 @@ def _to_device_loop(self, initialization_barrier: multiprocessing.Barrier): initialization_barrier.wait() watchdog.start() while not self.dying.is_set(): + # pylint: disable=unsubscriptable-object msg = to_ser_sock.recv_multipart() if not msg or self.dying.is_set(): continue diff --git a/pros/serial/ports/serial_share_port.py b/pros/serial/ports/serial_share_port.py index f329ac7e..2ee58587 100644 --- a/pros/serial/ports/serial_share_port.py +++ b/pros/serial/ports/serial_share_port.py @@ -42,6 +42,7 @@ def read(self, n_bytes: int = -1): n_bytes = 1 data = bytearray() for _ in range(n_bytes): + # pylint: disable=unsubscriptable-object data.extend(self.from_device_sock.recv_multipart()[1]) return bytes(data) From fa0dbd81b7b3764e94cbde930b253f0d9e2500c1 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 00:27:21 -0500 Subject: [PATCH 37/58] Fix W0108 --- .pylintrc | 3 +-- pros/cli/conductor.py | 2 +- pros/cli/conductor_utils.py | 2 +- pros/common/ui/interactive/parameters/validatable_parameter.py | 2 +- pros/common/ui/interactive/renderers/MachineOutputRenderer.py | 2 +- pros/conductor/interactive/parameters.py | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.pylintrc b/.pylintrc index 82c43c76..44b81183 100644 --- a/.pylintrc +++ b/.pylintrc @@ -21,7 +21,6 @@ # W0237: Renamed arguments # W0223: Abstract method is not overridden # W0613: Unused argument -# W0108: Lambda may not be necessary # W0511: TODO # C0103: Variable name doesn't conform to naming style # R1732: Consider using with @@ -71,7 +70,7 @@ 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, R0902, C0412, C0103, C0301, R1732, R0915, W1514, + R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401, C0303, W4902 diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index 8e46c24c..cc3752e5 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -324,7 +324,7 @@ def info_project(project: c.Project, ls_upgrades): 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) diff --git a/pros/cli/conductor_utils.py b/pros/cli/conductor_utils.py index 24128073..ff5ef8f5 100644 --- a/pros/cli/conductor_utils.py +++ b/pros/cli/conductor_utils.py @@ -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) diff --git a/pros/common/ui/interactive/parameters/validatable_parameter.py b/pros/common/ui/interactive/parameters/validatable_parameter.py index ceafd59f..f175d94c 100644 --- a/pros/common/ui/interactive/parameters/validatable_parameter.py +++ b/pros/common/ui/interactive/parameters/validatable_parameter.py @@ -20,7 +20,7 @@ def __init__(self, initial_value: T, allow_invalid_input: bool = True, """ super().__init__(initial_value) self.allow_invalid_input = allow_invalid_input - self.validate_lambda = validate or (lambda v: bool(v)) + self.validate_lambda = validate or bool def validate(self, value: T) -> Union[bool, str]: return self.validate_lambda(value) diff --git a/pros/common/ui/interactive/renderers/MachineOutputRenderer.py b/pros/common/ui/interactive/renderers/MachineOutputRenderer.py index 402716e2..425f7aed 100644 --- a/pros/common/ui/interactive/renderers/MachineOutputRenderer.py +++ b/pros/common/ui/interactive/renderers/MachineOutputRenderer.py @@ -42,7 +42,7 @@ def __init__(self, app: Application[P]): def on_redraw(): self.render(self.app) - app.on_exit(lambda: self.stop()) + app.on_exit(self.stop) @staticmethod def get_line(): diff --git a/pros/conductor/interactive/parameters.py b/pros/conductor/interactive/parameters.py index 7b0da738..d3c4e02f 100644 --- a/pros/conductor/interactive/parameters.py +++ b/pros/conductor/interactive/parameters.py @@ -64,7 +64,7 @@ def _update_versions(self): if self.name.value in self.options: self.version = p.OptionParameter( self.version.value if self.version else None, - list(sorted(self.options[self.name.value].keys(), reverse=True, key=lambda v: Version(v))) + list(sorted(self.options[self.name.value].keys(), reverse=True, key=Version)) ) if self.version.value not in self.version.options: From 21d5a8dbdd070ccc7dccd84372dd6f859efd3c60 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:01:36 -0500 Subject: [PATCH 38/58] Fix R0402 --- .pylintrc | 3 +-- pros/cli/conductor.py | 2 +- pros/cli/conductor_utils.py | 2 +- pros/cli/main.py | 2 +- pros/cli/misc_commands.py | 2 +- pros/cli/terminal.py | 2 +- pros/cli/upload.py | 4 ++-- pros/cli/v5_utils.py | 4 ++-- pros/common/sentry.py | 2 +- pros/conductor/conductor.py | 2 +- pros/conductor/depots/depot.py | 2 +- pros/conductor/depots/http_depot.py | 2 +- pros/conductor/project/ProjectTransaction.py | 2 +- pros/conductor/project/__init__.py | 2 +- pros/conductor/transaction.py | 2 +- pros/serial/devices/vex/stm32_device.py | 2 +- pros/serial/interactive/UploadProjectModal.py | 2 +- pros/upgrade/upgrade_manager.py | 2 +- 18 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.pylintrc b/.pylintrc index 44b81183..610aa344 100644 --- a/.pylintrc +++ b/.pylintrc @@ -16,7 +16,6 @@ # W0401: Wildcard import # C0117: Unnecessary negation # R0205: Useless object inheritance -# R0402: Consider using from import # R1725: Super with arguments # W0237: Renamed arguments # W0223: Abstract method is not overridden @@ -69,7 +68,7 @@ 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, + W0614, W0401, W1202, C0117, W0718, R0205, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index cc3752e5..dd717135 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -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 diff --git a/pros/cli/conductor_utils.py b/pros/cli/conductor_utils.py index ff5ef8f5..a933acaa 100644 --- a/pros/cli/conductor_utils.py +++ b/pros/cli/conductor_utils.py @@ -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 diff --git a/pros/cli/main.py b/pros/cli/main.py index f7b8bd3d..1c04b53f 100644 --- a/pros/cli/main.py +++ b/pros/cli/main.py @@ -10,7 +10,7 @@ import ctypes import sys -import pros.common.ui as ui +from pros.common import ui import pros.common.ui.log from pros.cli.click_classes import * from pros.cli.common import default_options, root_commands diff --git a/pros/cli/misc_commands.py b/pros/cli/misc_commands.py index 93002c80..9aade94e 100644 --- a/pros/cli/misc_commands.py +++ b/pros/cli/misc_commands.py @@ -1,4 +1,4 @@ -import pros.common.ui as ui +from pros.common import ui from pros.cli.common import * from pros.ga.analytics import analytics diff --git a/pros/cli/terminal.py b/pros/cli/terminal.py index 55a705fc..e6c07143 100644 --- a/pros/cli/terminal.py +++ b/pros/cli/terminal.py @@ -6,7 +6,7 @@ import sys import pros.conductor as c -import pros.serial.devices as devices +from pros.serial import devices from pros.serial.ports import DirectPort from pros.common.utils import logger from .common import default_options, resolve_v5_port, resolve_cortex_port, pros_root diff --git a/pros/cli/upload.py b/pros/cli/upload.py index ece08692..593ba8cd 100644 --- a/pros/cli/upload.py +++ b/pros/cli/upload.py @@ -1,6 +1,6 @@ import sys -import pros.common.ui as ui +from pros.common import ui import pros.conductor as c from .common import * @@ -53,7 +53,7 @@ def upload(path: Optional[str], project: Optional[c.Project], port: str, **kwarg automatically detected based on the target (or as supplied by the PROS project) """ analytics.send("upload") - import pros.serial.devices.vex as vex + from pros.serial.devices import vex from pros.serial.ports import DirectPort kwargs['ide_version'] = project.kernel if not project==None else "None" kwargs['ide'] = 'PROS' diff --git a/pros/cli/v5_utils.py b/pros/cli/v5_utils.py index a6fe0eec..a8404a95 100644 --- a/pros/cli/v5_utils.py +++ b/pros/cli/v5_utils.py @@ -297,7 +297,7 @@ def capture(file_name: str, port: str, force: bool = False): @click.argument('port', type=str, default=None, required=False) @default_options def set_variable(variable, value, port): - import pros.serial.devices.vex as vex + from pros.serial.devices import vex from pros.serial.ports import DirectPort # Get the connected v5 device @@ -313,7 +313,7 @@ def set_variable(variable, value, port): @click.argument('port', type=str, default=None, required=False) @default_options def read_variable(variable, port): - import pros.serial.devices.vex as vex + from pros.serial.devices import vex from pros.serial.ports import DirectPort # Get the connected v5 device diff --git a/pros/common/sentry.py b/pros/common/sentry.py index f161231f..c0201c6c 100644 --- a/pros/common/sentry.py +++ b/pros/common/sentry.py @@ -2,7 +2,7 @@ import click -import pros.common.ui as ui +from pros.common import ui if TYPE_CHECKING: from sentry_sdk import Client, Hub, Scope # noqa: F401, flake8 issue with "if TYPE_CHECKING" diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index cf009660..192e8433 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -9,7 +9,7 @@ from semantic_version import Spec, Version from pros.common import * -import pros.common.ui as ui +from pros.common import ui from pros.conductor.project import TemplateAction from pros.conductor.project.template_resolution import InvalidTemplateException from pros.config import Config diff --git a/pros/conductor/depots/depot.py b/pros/conductor/depots/depot.py index 364d312f..cafd8e16 100644 --- a/pros/conductor/depots/depot.py +++ b/pros/conductor/depots/depot.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta from typing import * -import pros.common.ui as ui +from pros.common import ui from pros.common import logger from pros.config.cli_config import cli_config from ..templates import BaseTemplate, Template diff --git a/pros/conductor/depots/http_depot.py b/pros/conductor/depots/http_depot.py index 9f5accec..3ba4358b 100644 --- a/pros/conductor/depots/http_depot.py +++ b/pros/conductor/depots/http_depot.py @@ -4,7 +4,7 @@ import jsonpickle -import pros.common.ui as ui +from pros.common import ui from pros.common import logger from pros.common.utils import download_file from .depot import Depot diff --git a/pros/conductor/project/ProjectTransaction.py b/pros/conductor/project/ProjectTransaction.py index 0e5e0974..bc417b37 100644 --- a/pros/conductor/project/ProjectTransaction.py +++ b/pros/conductor/project/ProjectTransaction.py @@ -4,7 +4,7 @@ import zipfile from typing import * -import pros.common.ui as ui +from pros.common import ui import pros.conductor as c from pros.conductor.project.template_resolution import InvalidTemplateException, TemplateAction diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index 2ea4812c..bbebb4a2 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -7,7 +7,7 @@ from typing import * from pros.common import * -import pros.common.ui as ui +from pros.common import ui from pros.common.ui import EchoPipe from pros.conductor.project.template_resolution import TemplateAction from pros.config.config import Config, ConfigNotFoundException diff --git a/pros/conductor/transaction.py b/pros/conductor/transaction.py index 0fcb05d7..8fad09a7 100644 --- a/pros/conductor/transaction.py +++ b/pros/conductor/transaction.py @@ -2,7 +2,7 @@ import shutil from typing import * -import pros.common.ui as ui +from pros.common import ui from pros.common import logger diff --git a/pros/serial/devices/vex/stm32_device.py b/pros/serial/devices/vex/stm32_device.py index eecfdc47..23e6f05b 100644 --- a/pros/serial/devices/vex/stm32_device.py +++ b/pros/serial/devices/vex/stm32_device.py @@ -6,7 +6,7 @@ from functools import reduce from typing import * -import pros.common.ui as ui +from pros.common import ui from pros.common import logger, retries from pros.serial import bytes_to_str from pros.serial.devices.vex import VEXCommError diff --git a/pros/serial/interactive/UploadProjectModal.py b/pros/serial/interactive/UploadProjectModal.py index f14dde7e..164c71ef 100644 --- a/pros/serial/interactive/UploadProjectModal.py +++ b/pros/serial/interactive/UploadProjectModal.py @@ -3,7 +3,7 @@ from threading import Thread from typing import * -import pros.common.ui as ui +from pros.common import ui from pros.common.ui.interactive import application, components, parameters from pros.common.utils import with_click_context from pros.conductor import Project diff --git a/pros/upgrade/upgrade_manager.py b/pros/upgrade/upgrade_manager.py index a4a216f8..93360a19 100644 --- a/pros/upgrade/upgrade_manager.py +++ b/pros/upgrade/upgrade_manager.py @@ -4,7 +4,7 @@ from typing import * from pros.common import logger -import pros.common.ui as ui +from pros.common import ui from pros.config import Config from pros.config.cli_config import cli_config from .manifests import * From a647ef90972a6cda3e847112467f490ff1e263d3 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:06:21 -0500 Subject: [PATCH 39/58] Fix R0205 --- .pylintrc | 3 +-- pros/cli/terminal.py | 2 +- pros/cli/upload.py | 2 +- pros/common/ui/__init__.py | 2 +- pros/common/ui/interactive/components/component.py | 2 +- pros/conductor/depots/depot.py | 2 +- pros/conductor/project/ProjectReport.py | 2 +- pros/conductor/project/ProjectTransaction.py | 4 ++-- pros/conductor/templates/base_template.py | 2 +- pros/conductor/transaction.py | 2 +- pros/config/config.py | 2 +- pros/jinx/server.py | 2 +- pros/serial/devices/generic_device.py | 2 +- pros/serial/devices/system_device.py | 2 +- pros/serial/devices/vex/cortex_device.py | 2 +- pros/serial/devices/vex/v5_device.py | 6 +++--- pros/serial/ports/base_port.py | 2 +- pros/serial/ports/serial_share_bridge.py | 2 +- pros/serial/terminal/terminal.py | 6 +++--- pros/upgrade/instructions/base_instructions.py | 4 ++-- pros/upgrade/manifests/upgrade_manifest_v1.py | 2 +- 21 files changed, 27 insertions(+), 28 deletions(-) diff --git a/.pylintrc b/.pylintrc index 610aa344..ff3ad2c7 100644 --- a/.pylintrc +++ b/.pylintrc @@ -15,7 +15,6 @@ # W0614: Unused import from wildcard import # W0401: Wildcard import # C0117: Unnecessary negation -# R0205: Useless object inheritance # R1725: Super with arguments # W0237: Renamed arguments # W0223: Abstract method is not overridden @@ -68,7 +67,7 @@ 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, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, + W0614, W0401, W1202, C0117, W0718, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, diff --git a/pros/cli/terminal.py b/pros/cli/terminal.py index e6c07143..eb4c4e8c 100644 --- a/pros/cli/terminal.py +++ b/pros/cli/terminal.py @@ -84,7 +84,7 @@ def terminal(port: str, backend: str, **kwargs): device = devices.vex.V5UserDevice(ser) term = Terminal(device, request_banner=kwargs.pop('request_banner', True)) - class TerminalOutput(object): + class TerminalOutput: def __init__(self, file): self.terminal = sys.stdout self.log = open(file, 'a') diff --git a/pros/cli/upload.py b/pros/cli/upload.py index 593ba8cd..144dc38a 100644 --- a/pros/cli/upload.py +++ b/pros/cli/upload.py @@ -166,7 +166,7 @@ def ls_usb(target): analytics.send("ls-usb") from pros.serial.devices.vex import find_v5_ports, find_cortex_ports - class PortReport(object): + class PortReport: def __init__(self, header: str, ports: List[Any], machine_header: Optional[str] = None): self.header = header self.ports = [{'device': p.device, 'desc': p.description} for p in ports] diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index 5524ab3f..de7ae02d 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -134,7 +134,7 @@ def render_progress(self): _machine_notify('progress', obj, self.notify_value) -class Notification(object): +class Notification: def __init__(self, notify_value: Optional[int] = None): global _last_notify_value if not notify_value: diff --git a/pros/common/ui/interactive/components/component.py b/pros/common/ui/interactive/components/component.py index 158fc0bc..254a6761 100644 --- a/pros/common/ui/interactive/components/component.py +++ b/pros/common/ui/interactive/components/component.py @@ -4,7 +4,7 @@ from pros.common.ui.interactive.parameters.validatable_parameter import ValidatableParameter -class Component(object): +class Component: """ A Component is the basic building block of something to render to users. diff --git a/pros/conductor/depots/depot.py b/pros/conductor/depots/depot.py index cafd8e16..8487b10d 100644 --- a/pros/conductor/depots/depot.py +++ b/pros/conductor/depots/depot.py @@ -7,7 +7,7 @@ from ..templates import BaseTemplate, Template -class Depot(object): +class Depot: def __init__(self, name: str, location: str, config: Dict[str, Any] = None, update_frequency: timedelta = timedelta(minutes=1), config_schema: Dict[str, Dict[str, Any]] = None): diff --git a/pros/conductor/project/ProjectReport.py b/pros/conductor/project/ProjectReport.py index 75d2ff3a..f33d4792 100644 --- a/pros/conductor/project/ProjectReport.py +++ b/pros/conductor/project/ProjectReport.py @@ -1,7 +1,7 @@ import os.path -class ProjectReport(object): +class ProjectReport: def __init__(self, project: 'Project'): self.project = { "target": project.target, diff --git a/pros/conductor/project/ProjectTransaction.py b/pros/conductor/project/ProjectTransaction.py index bc417b37..78a3432d 100644 --- a/pros/conductor/project/ProjectTransaction.py +++ b/pros/conductor/project/ProjectTransaction.py @@ -9,7 +9,7 @@ from pros.conductor.project.template_resolution import InvalidTemplateException, TemplateAction -class Action(object): +class Action: def execute(self, conductor: c.Conductor, project: c.Project) -> None: raise NotImplementedError() @@ -100,7 +100,7 @@ def can_execute(self, conductor: c.Conductor, project: c.Project): return True -class ProjectTransaction(object): +class ProjectTransaction: def __init__(self, project: c.Project, conductor: Optional[c.Conductor] = None): self.project = project self.conductor = conductor or c.Conductor() diff --git a/pros/conductor/templates/base_template.py b/pros/conductor/templates/base_template.py index 95a19064..7c66d623 100644 --- a/pros/conductor/templates/base_template.py +++ b/pros/conductor/templates/base_template.py @@ -5,7 +5,7 @@ from pros.common import ui -class BaseTemplate(object): +class BaseTemplate: def __init__(self, **kwargs): self.name: str = None self.version: str = None diff --git a/pros/conductor/transaction.py b/pros/conductor/transaction.py index 8fad09a7..a79d8c4e 100644 --- a/pros/conductor/transaction.py +++ b/pros/conductor/transaction.py @@ -6,7 +6,7 @@ from pros.common import logger -class Transaction(object): +class Transaction: def __init__(self, location: str, current_state: Set[str]): self._add_files: Set[str] = set() self._rm_files: Set[str] = set() diff --git a/pros/config/config.py b/pros/config/config.py index 440767c5..1b66cad1 100644 --- a/pros/config/config.py +++ b/pros/config/config.py @@ -10,7 +10,7 @@ def __init__(self, message, *args, **kwargs): self.message = message -class Config(object): +class Config: """ A configuration object that's capable of being saved as a JSON object """ diff --git a/pros/jinx/server.py b/pros/jinx/server.py index 31f848cf..ac87968a 100644 --- a/pros/jinx/server.py +++ b/pros/jinx/server.py @@ -1,6 +1,6 @@ from pros.serial.devices import StreamDevice -class JinxServer(object): +class JinxServer: def __init__(self, device: StreamDevice): self.device = device diff --git a/pros/serial/devices/generic_device.py b/pros/serial/devices/generic_device.py index 0e139fc8..ac500e2d 100644 --- a/pros/serial/devices/generic_device.py +++ b/pros/serial/devices/generic_device.py @@ -1,7 +1,7 @@ from ..ports import BasePort -class GenericDevice(object): +class GenericDevice: def __init__(self, port: BasePort): self.port = port diff --git a/pros/serial/devices/system_device.py b/pros/serial/devices/system_device.py index 6511c4cd..aa2351ae 100644 --- a/pros/serial/devices/system_device.py +++ b/pros/serial/devices/system_device.py @@ -3,7 +3,7 @@ from pros.conductor import Project -class SystemDevice(object): +class SystemDevice: def upload_project(self, project: Project, **kwargs): raise NotImplementedError diff --git a/pros/serial/devices/vex/cortex_device.py b/pros/serial/devices/vex/cortex_device.py index 978e1c0d..7e57d767 100644 --- a/pros/serial/devices/vex/cortex_device.py +++ b/pros/serial/devices/vex/cortex_device.py @@ -22,7 +22,7 @@ def find_cortex_ports(): class CortexDevice(VEXDevice, SystemDevice): - class SystemStatus(object): + class SystemStatus: def __init__(self, data: Tuple[bytes, ...]): self.joystick_firmware = data[0:2] self.robot_firmware = data[2:4] diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index f0190e1b..82a4eb4f 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -137,7 +137,7 @@ class FTCompleteOptions(IntEnum): VEX_CRC16 = CRC(16, 0x1021) # CRC-16-CCIT VEX_CRC32 = CRC(32, 0x04C11DB7) # CRC-32 (the one used everywhere but has no name) - class SystemVersion(object): + class SystemVersion: class Product(IntEnum): CONTROLLER = 0x11 BRAIN = 0x10 @@ -161,7 +161,7 @@ def __str__(self): f' Product: {self.product.name}\n' \ f' Product Flags: {self.product_flags.value:x}' - class SystemStatus(object): + class SystemStatus: def __init__(self, data: tuple): from semantic_version import Version self.system_version = Version('{}.{}.{}-{}'.format(*data[0:4])) @@ -178,7 +178,7 @@ def __init__(self, port: BasePort): self._serial_cache = b'' super().__init__(port) - class DownloadChannel(object): + class DownloadChannel: def __init__(self, device: 'V5Device', timeout: float = 5.): self.device = device self.timeout = timeout diff --git a/pros/serial/ports/base_port.py b/pros/serial/ports/base_port.py index 6bfc03fc..8c71d34e 100644 --- a/pros/serial/ports/base_port.py +++ b/pros/serial/ports/base_port.py @@ -1,7 +1,7 @@ from typing import * -class BasePort(object): +class BasePort: def write(self, data: bytes): raise NotImplementedError() diff --git a/pros/serial/ports/serial_share_bridge.py b/pros/serial/ports/serial_share_bridge.py index 54259f4f..27b57b1c 100644 --- a/pros/serial/ports/serial_share_bridge.py +++ b/pros/serial/ports/serial_share_bridge.py @@ -23,7 +23,7 @@ def get_to_device_port_num(serial_port_name: str) -> int: return get_port_num(serial_port_name, 'to') -class SerialShareBridge(object): +class SerialShareBridge: def __init__(self, serial_port_name: str, base_addr: str = '127.0.0.1', to_device_port_num: int = None, from_device_port_num: int = None): self._serial_port_name = serial_port_name diff --git a/pros/serial/terminal/terminal.py b/pros/serial/terminal/terminal.py index d65de534..6c6f6b0e 100644 --- a/pros/serial/terminal/terminal.py +++ b/pros/serial/terminal/terminal.py @@ -15,7 +15,7 @@ # This file is a modification of the miniterm implementation on pyserial -class ConsoleBase(object): +class ConsoleBase: """OS abstraction for console (input/output codec, no echo)""" def __init__(self): @@ -65,7 +65,7 @@ def __exit__(self, *args, **kwargs): import ctypes - class Out(object): + class Out: """file-like wrapper that uses os.write""" def __init__(self, fd): @@ -166,7 +166,7 @@ def cleanup(self): ' available.'.format(sys.platform)) -class Terminal(object): +class Terminal: """This class is loosely based off of the pyserial miniterm""" def __init__(self, port_instance: StreamDevice, transformations=(), diff --git a/pros/upgrade/instructions/base_instructions.py b/pros/upgrade/instructions/base_instructions.py index 81f543fd..8ccdd209 100644 --- a/pros/upgrade/instructions/base_instructions.py +++ b/pros/upgrade/instructions/base_instructions.py @@ -1,4 +1,4 @@ -class UpgradeResult(object): +class UpgradeResult: def __init__(self, successful: bool, **kwargs): self.successful = successful self.__dict__.update(**kwargs) @@ -7,7 +7,7 @@ def __str__(self): return f'The upgrade was {"" if self.successful else "not "}successful.\n{getattr(self, "explanation", "")}' -class UpgradeInstruction(object): +class UpgradeInstruction: """ Base class for all upgrade instructions, not useful to instantiate """ diff --git a/pros/upgrade/manifests/upgrade_manifest_v1.py b/pros/upgrade/manifests/upgrade_manifest_v1.py index 51ba9346..d3f0fa1c 100644 --- a/pros/upgrade/manifests/upgrade_manifest_v1.py +++ b/pros/upgrade/manifests/upgrade_manifest_v1.py @@ -4,7 +4,7 @@ from ..instructions import UpgradeResult -class UpgradeManifestV1(object): +class UpgradeManifestV1: """ An Upgrade Manifest only capable of determine if there is an update - not how to update """ From 0d396051fbf9abd435caa4d6bfd9f092950fe64c Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:11:27 -0500 Subject: [PATCH 40/58] Fix C0117 --- .pylintrc | 3 +-- pros/serial/devices/vex/v5_device.py | 2 +- pros/serial/devices/vex/vex_device.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index ff3ad2c7..312c9d48 100644 --- a/.pylintrc +++ b/.pylintrc @@ -14,7 +14,6 @@ # C0121: Comparison to singletons is unnecessary # W0614: Unused import from wildcard import # W0401: Wildcard import -# C0117: Unnecessary negation # R1725: Super with arguments # W0237: Renamed arguments # W0223: Abstract method is not overridden @@ -67,7 +66,7 @@ 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, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, + W0614, W0401, W1202, W0718, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index 82a4eb4f..92b83bde 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -965,7 +965,7 @@ def _rx_ext_packet(cls, msg: Message, command: int, rx_length: int, check_ack: b :return: The payload of the extended message """ assert msg['command'] == 0x56 - if not cls.VEX_CRC16.compute(msg.rx) == 0: + if cls.VEX_CRC16.compute(msg.rx) != 0: raise VEXCommError("CRC of message didn't match 0: {}".format(cls.VEX_CRC16.compute(msg.rx)), msg) assert msg['payload'][0] == command msg = msg['payload'][1:-2] diff --git a/pros/serial/devices/vex/vex_device.py b/pros/serial/devices/vex/vex_device.py index ff9862d4..80dcace5 100644 --- a/pros/serial/devices/vex/vex_device.py +++ b/pros/serial/devices/vex/vex_device.py @@ -71,7 +71,7 @@ def _rx_packet(self, timeout: Optional[float] = None) -> Dict[str, Union[Union[i logger(__name__).debug("Tossing rx ({}) because {} didn't match".format(bytes_to_str(rx), b)) response_header_stack = bytearray(response_header) rx = bytearray() - if not rx == bytearray(response_header): + if rx != bytearray(response_header): raise IOError(f"Couldn't find the response header in the device response after {timeout} s. " f"Got {rx.hex()} but was expecting {response_header.hex()}") rx.extend(self.port.read(1)) From f1618c36a3569b40a1372a92467f07a8ac033720 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:30:13 -0500 Subject: [PATCH 41/58] Fix C0121 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 4 ++-- pros/cli/main.py | 2 +- pros/cli/upload.py | 6 +++--- pros/cli/v5_utils.py | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.pylintrc b/.pylintrc index 312c9d48..11674b9d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -11,7 +11,6 @@ # C0209: Consider using an f-string # R1710: Either all return statements in a function should return an expression, or none of them should # W0621: Redefining name from outer scope -# C0121: Comparison to singletons is unnecessary # W0614: Unused import from wildcard import # W0401: Wildcard import # R1725: Super with arguments @@ -65,7 +64,7 @@ # R0401: Cyclic import max-line-length = 120 -disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, C0121, +disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, W0614, W0401, W1202, W0718, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 3d64146c..34c74594 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -84,7 +84,7 @@ def get_help_record(self, 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" @@ -92,7 +92,7 @@ def __init__(self, *args, replacement: str = None, **kwargs): 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): diff --git a/pros/cli/main.py b/pros/cli/main.py index 1c04b53f..858f5cc2 100644 --- a/pros/cli/main.py +++ b/pros/cli/main.py @@ -87,7 +87,7 @@ def version(ctx: click.Context, param, value): def use_analytics(ctx: click.Context, param, value): - if value == None: + if value is None: return touse = not analytics.useAnalytics if str(value).lower().startswith("t"): diff --git a/pros/cli/upload.py b/pros/cli/upload.py index 144dc38a..45cb3f96 100644 --- a/pros/cli/upload.py +++ b/pros/cli/upload.py @@ -55,7 +55,7 @@ def upload(path: Optional[str], project: Optional[c.Project], port: str, **kwarg analytics.send("upload") from pros.serial.devices import vex from pros.serial.ports import DirectPort - kwargs['ide_version'] = project.kernel if not project==None else "None" + kwargs['ide_version'] = project.kernel if project is not None else "None" kwargs['ide'] = 'PROS' if path is None or os.path.isdir(path): if project is None: @@ -126,11 +126,11 @@ def upload(path: Optional[str], project: Optional[c.Project], port: str, **kwarg } after_upload_default = 'screen' #Determine which FTCompleteOption to assign to run_after - if kwargs['after']==None: + if kwargs['after'] is None: kwargs['after']=after_upload_default if kwargs['run_after']: kwargs['after']='run' - elif kwargs['run_screen']==False and not kwargs['run_after']: + elif not kwargs['run_screen'] and not kwargs['run_after']: kwargs['after']='none' kwargs['run_after'] = action_to_kwarg[kwargs['after']] kwargs.pop('run_screen') diff --git a/pros/cli/v5_utils.py b/pros/cli/v5_utils.py index a8404a95..8d85b3a5 100644 --- a/pros/cli/v5_utils.py +++ b/pros/cli/v5_utils.py @@ -302,7 +302,7 @@ def set_variable(variable, value, port): # Get the connected v5 device port = resolve_v5_port(port, 'system')[0] - if port == None: + if port is None: return device = vex.V5Device(DirectPort(port)) actual_value = device.kv_write(variable, value).decode() @@ -318,7 +318,7 @@ def read_variable(variable, port): # Get the connected v5 device port = resolve_v5_port(port, 'system')[0] - if port == None: + if port is None: return device = vex.V5Device(DirectPort(port)) value = device.kv_read(variable).decode() From 8e474416cc3fa50346c6fa4669415d17bb944c2f Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:45:01 -0500 Subject: [PATCH 42/58] Fix R1705 --- .pylintrc | 3 +-- pros/cli/common.py | 5 ++-- pros/cli/upload.py | 5 ++-- pros/common/sentry.py | 3 +-- pros/common/ui/__init__.py | 3 +-- .../interactive/parameters/misc_parameters.py | 3 +-- .../parameters/validatable_parameter.py | 3 +-- pros/common/ui/log.py | 3 +-- pros/common/utils.py | 24 +++++++++---------- pros/conductor/conductor.py | 3 +-- pros/conductor/project/ProjectTransaction.py | 8 +++---- pros/conductor/project/__init__.py | 7 +++--- pros/conductor/templates/base_template.py | 6 ++--- pros/config/cli_config.py | 7 +++--- pros/serial/__init__.py | 4 ++-- pros/serial/devices/vex/v5_device.py | 21 +++++++--------- pros/serial/ports/direct_port.py | 15 ++++++------ pros/serial/terminal/terminal.py | 2 +- pros/upgrade/manifests/upgrade_manifest_v1.py | 3 +-- 19 files changed, 52 insertions(+), 76 deletions(-) diff --git a/.pylintrc b/.pylintrc index 11674b9d..76c29fa6 100644 --- a/.pylintrc +++ b/.pylintrc @@ -5,7 +5,6 @@ # C0115: Missing class docstring # C0116: Missing function or method docstring # C0415: Import outside toplevel (import-outside-toplevel) -# R1705: Unnecessary "else" after "return" # E1120: No value for argument in function call # E1123: Unexpected argument in function call # C0209: Consider using an f-string @@ -64,7 +63,7 @@ # R0401: Cyclic import max-line-length = 120 -disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, +disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, W0614, W0401, W1202, W0718, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, diff --git a/pros/cli/common.py b/pros/cli/common.py index 1724e10e..5f6f8be5 100644 --- a/pros/cli/common.py +++ b/pros/cli/common.py @@ -190,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) diff --git a/pros/cli/upload.py b/pros/cli/upload.py index 45cb3f96..44a5ad9e 100644 --- a/pros/cli/upload.py +++ b/pros/cli/upload.py @@ -181,9 +181,8 @@ def __getstate__(self): def __str__(self): if len(self.ports) == 0: return f'There are no connected {self.header}' - else: - port_str = "\n".join([f"{p['device']} - {p['desc']}" for p in self.ports]) - return f'{self.header}:\n{port_str}' + port_str = "\n".join([f"{p['device']} - {p['desc']}" for p in self.ports]) + return f'{self.header}:\n{port_str}' result = [] if target == 'v5' or target is None: diff --git a/pros/common/sentry.py b/pros/common/sentry.py index c0201c6c..ac32d6b2 100644 --- a/pros/common/sentry.py +++ b/pros/common/sentry.py @@ -56,8 +56,7 @@ def prompt_to_send(event: Dict[str, Any], hint: Optional[Dict[str, Any]]) -> Opt ui.echo(f'Want to get updates? Visit https://pros.cs.purdue.edu/report.html?event={event["event_id"]}') return event - else: - ui.echo('Not sending bug report.') + ui.echo('Not sending bug report.') def add_context(obj: object, override_handlers: bool = True, key: str = None) -> None: diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index de7ae02d..e1db879b 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -69,8 +69,7 @@ def progressbar(iterable: Iterable = None, length: int = None, label: str = None info_sep: str = ' ', width: int = 36): if ismachineoutput(): return _MachineOutputProgressBar(**locals()) - else: - return click.progressbar(**locals()) + return click.progressbar(**locals()) def finalize(method: str, data: Union[str, Dict, object, List[Union[str, Dict, object, Tuple]]], diff --git a/pros/common/ui/interactive/parameters/misc_parameters.py b/pros/common/ui/interactive/parameters/misc_parameters.py index 36bbe9f8..83b2dc92 100644 --- a/pros/common/ui/interactive/parameters/misc_parameters.py +++ b/pros/common/ui/interactive/parameters/misc_parameters.py @@ -32,8 +32,7 @@ def __init__(self, initial_value: int, value_range: Tuple[int, int]): def validate(self, value: T): if self.value_range[0] <= value <= self.value_range[1]: return True - else: - return f'{value} is not within [{self.value_range[0]}, {self.value_range[1]}]' + return f'{value} is not within [{self.value_range[0]}, {self.value_range[1]}]' def update(self, new_value): super(RangeParameter, self).update(int(new_value)) diff --git a/pros/common/ui/interactive/parameters/validatable_parameter.py b/pros/common/ui/interactive/parameters/validatable_parameter.py index f175d94c..2bcf1e22 100644 --- a/pros/common/ui/interactive/parameters/validatable_parameter.py +++ b/pros/common/ui/interactive/parameters/validatable_parameter.py @@ -29,8 +29,7 @@ def is_valid(self, value: T = None) -> bool: rv = self.validate(value if value is not None else self.value) if isinstance(rv, bool): return rv - else: - return False + return False def is_valid_reason(self, value: T = None) -> Optional[str]: rv = self.validate(value if value is not None else self.value) diff --git a/pros/common/ui/log.py b/pros/common/ui/log.py index 8202ef95..57c94dc6 100644 --- a/pros/common/ui/log.py +++ b/pros/common/ui/log.py @@ -48,5 +48,4 @@ class PROSLogFormatter(logging.Formatter): def formatException(self, ei): if not isdebug(): return '\n'.join(super().formatException(ei).split('\n')[-3:]) - else: - return super().formatException(ei) + return super().formatException(ei) diff --git a/pros/common/utils.py b/pros/common/utils.py index b1077119..8c28da6a 100644 --- a/pros/common/utils.py +++ b/pros/common/utils.py @@ -52,8 +52,7 @@ def retries_wrapper(*args, n_retries: int = retry, **kwargs): except Exception as e: if n_retries > 0: return retries_wrapper(*args, n_retries=n_retries - 1, **kwargs) - else: - raise e + raise e return retries_wrapper @@ -79,8 +78,7 @@ def ismachineoutput(ctx: click.Context = None) -> bool: ctx.ensure_object(dict) assert isinstance(ctx.obj, dict) return ctx.obj.get('machine_output', False) - else: - return False + return False def get_pros_dir(): @@ -91,15 +89,15 @@ def with_click_context(func): ctx = click.get_current_context(silent=True) if not ctx or not isinstance(ctx, click.Context): return func - else: - def _wrap(*args, **kwargs): - with ctx: - try: - return func(*args, **kwargs) - except BaseException as e: - logger(__name__).exception(e) - - return _wrap + + def _wrap(*args, **kwargs): + with ctx: + try: + return func(*args, **kwargs) + except BaseException as e: + logger(__name__).exception(e) + + return _wrap def download_file(url: str, ext: Optional[str] = None, desc: Optional[str] = None) -> Optional[str]: diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index 192e8433..ce2c6679 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -70,8 +70,7 @@ def is_pathname_valid(pathname: str) -> bool: return False except TypeError: return False - else: - return True + return True class Conductor(Config): """ diff --git a/pros/conductor/project/ProjectTransaction.py b/pros/conductor/project/ProjectTransaction.py index 78a3432d..8a01685b 100644 --- a/pros/conductor/project/ProjectTransaction.py +++ b/pros/conductor/project/ProjectTransaction.py @@ -51,10 +51,9 @@ def describe(self, conductor: c.Conductor, project: c.Project): if action == TemplateAction.AlreadyInstalled: if self.apply_kwargs.get('force_apply'): return f'{self.template.identifier} will be re-applied.' - elif self.suppress_already_installed: + if self.suppress_already_installed: return f'{self.template.identifier} will not be re-applied.' - else: - return f'{self.template.identifier} cannot be applied to project because it is already installed.' + return f'{self.template.identifier} cannot be applied to project because it is already installed.' def can_execute(self, conductor: c.Conductor, project: c.Project) -> bool: action = project.get_template_actions(conductor.resolve_template(self.template)) @@ -164,8 +163,7 @@ def describe(self) -> str: f'- {a.describe(self.conductor, self.project)}' for a in self.actions ) - else: - return 'No actions necessary.' + return 'No actions necessary.' def can_execute(self) -> bool: return all(a.can_execute(self.conductor, self.project) for a in self.actions) diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index bbebb4a2..43bb5365 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -87,8 +87,7 @@ def get_template_actions(self, template: BaseTemplate) -> TemplateAction: if any([template > current for current in self.templates.values()]): return TemplateAction.Upgradable - else: - return TemplateAction.Installable + return TemplateAction.Installable def template_is_installed(self, query: BaseTemplate) -> bool: return self.get_template_actions(query) == TemplateAction.AlreadyInstalled @@ -204,7 +203,7 @@ def __str__(self): def kernel(self): if 'kernel' in self.templates: return self.templates['kernel'].version - elif hasattr(self.__dict__, 'kernel'): + if hasattr(self.__dict__, 'kernel'): return self.__dict__['kernel'] return '' @@ -212,7 +211,7 @@ def kernel(self): def output(self): if 'kernel' in self.templates: return self.templates['kernel'].metadata['output'] - elif hasattr(self.__dict__, 'output'): + if hasattr(self.__dict__, 'output'): return self.__dict__['output'] return 'bin/output.bin' diff --git a/pros/conductor/templates/base_template.py b/pros/conductor/templates/base_template.py index 7c66d623..c7799d13 100644 --- a/pros/conductor/templates/base_template.py +++ b/pros/conductor/templates/base_template.py @@ -53,14 +53,12 @@ def __gt__(self, other): if isinstance(other, BaseTemplate): # TODO: metadata comparison return self.name == other.name and Version(self.version) > Version(other.version) - else: - return False + return False def __eq__(self, other): if isinstance(other, BaseTemplate): return self.identifier == other.identifier - else: - return super().__eq__(other) + return super().__eq__(other) def __hash__(self): return self.identifier.__hash__() diff --git a/pros/config/cli_config.py b/pros/config/cli_config.py index d508a999..72d77c17 100644 --- a/pros/config/cli_config.py +++ b/pros/config/cli_config.py @@ -53,10 +53,9 @@ def get_upgrade_manifest(self, force: bool = False) -> Optional['UpgradeManifest pros.common.logger(__name__).debug(self.cached_upgrade[1]) self.save() return self.cached_upgrade[1] - else: - pros.common.logger(__name__).warning(f'Failed to fetch CLI updates because status code: {r.status_code}') - pros.common.logger(__name__).debug(r) - return None + pros.common.logger(__name__).warning(f'Failed to fetch CLI updates because status code: {r.status_code}') + pros.common.logger(__name__).debug(r) + return None def cli_config() -> CliConfig: diff --git a/pros/serial/__init__.py b/pros/serial/__init__.py index 0177d021..2ad4861b 100644 --- a/pros/serial/__init__.py +++ b/pros/serial/__init__.py @@ -6,8 +6,8 @@ def bytes_to_str(arr): arr = bytes(arr) if hasattr(arr, '__iter__'): return ''.join('{:02X} '.format(x) for x in arr).strip() - else: # actually just a single byte - return '0x{:02X}'.format(arr) + # actually just a single byte + return '0x{:02X}'.format(arr) def decode_bytes_to_str(data: Union[bytes, bytearray], encoding: str = 'utf-8', errors: str = 'strict') -> str: diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index 92b83bde..8bfabbda 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -67,10 +67,9 @@ def filter_v5_ports_mac(p, device): if len(user_ports) == len(system_ports) and len(user_ports) > 0: if p_type.lower() == 'user': return user_ports - elif p_type.lower() == 'system': + if p_type.lower() == 'system': return system_ports + joystick_ports - else: - raise ValueError(f'Invalid port type specified: {p_type}') + raise ValueError(f'Invalid port type specified: {p_type}') # None of the typical filters worked, so if there are only two ports, then the lower one is always* # the USER? port (*always = I haven't found a guarantee) @@ -82,14 +81,13 @@ def natural_key(chunk: str): ports = sorted(ports, key=lambda p: natural_key(p.device)) if p_type.lower() == 'user': return [ports[1]] - elif p_type.lower() == 'system': + if p_type.lower() == 'system': # check if ports contain the word Brain in the description and return that port for port in ports: if "Brain" in port.description: return [port] return [ports[0], *joystick_ports] - else: - raise ValueError(f'Invalid port type specified: {p_type}') + raise ValueError(f'Invalid port type specified: {p_type}') # these can now also be used as user ports if len(joystick_ports) > 0: # and p_type.lower() == 'system': return joystick_ports @@ -205,9 +203,7 @@ def __enter__(self): if V5Device.SystemVersion.ControllerFlags.CONNECTED not in version.product_flags: raise VEXCommError('Could not transfer V5 Controller to download channel', version) logger(__name__).info('V5 should been transferred to higher bandwidth download channel') - return self - else: - return self + return self def __exit__(self, *exc): if self.did_switch: @@ -503,10 +499,9 @@ def upload_library(self, file: typing.BinaryIO, remote_name: str = None, file_le if response['size'] == file_len and response['crc'] == crc32: ui.echo('Library is already onboard V5') return - else: - logger(__name__).warning(f'Library onboard doesn\'t match! ' - f'Length was {response["size"]} but expected {file_len} ' - f'CRC: was {response["crc"]:x} but expected {crc32:x}') + logger(__name__).warning(f'Library onboard doesn\'t match! ' + f'Length was {response["size"]} but expected {file_len} ' + f'CRC: was {response["crc"]:x} but expected {crc32:x}') except VEXCommError as e: logger(__name__).debug(e) else: diff --git a/pros/serial/ports/direct_port.py b/pros/serial/ports/direct_port.py index 5a046cb2..f7189f75 100644 --- a/pros/serial/ports/direct_port.py +++ b/pros/serial/ports/direct_port.py @@ -39,15 +39,14 @@ def read(self, n_bytes: int = 0) -> bytes: msg = bytes(self.buffer) self.buffer = bytearray() return msg + if len(self.buffer) < n_bytes: + self.buffer.extend(self.serial.read(n_bytes - len(self.buffer))) + if len(self.buffer) < n_bytes: + msg = bytes(self.buffer) + self.buffer = bytearray() else: - if len(self.buffer) < n_bytes: - self.buffer.extend(self.serial.read(n_bytes - len(self.buffer))) - if len(self.buffer) < n_bytes: - msg = bytes(self.buffer) - self.buffer = bytearray() - else: - msg, self.buffer = bytes(self.buffer[:n_bytes]), self.buffer[n_bytes:] - return msg + msg, self.buffer = bytes(self.buffer[:n_bytes]), self.buffer[n_bytes:] + return msg except serial.SerialException as e: logger(__name__).debug(e) raise PortConnectionException(e) from e diff --git a/pros/serial/terminal/terminal.py b/pros/serial/terminal/terminal.py index 6c6f6b0e..31a7be53 100644 --- a/pros/serial/terminal/terminal.py +++ b/pros/serial/terminal/terminal.py @@ -104,7 +104,7 @@ def getkey(self): z = msvcrt.getwch() if z == chr(13): return chr(10) - elif z in (chr(0), chr(0x0e)): # functions keys, ignore + if z in (chr(0), chr(0x0e)): # functions keys, ignore msvcrt.getwch() else: return z diff --git a/pros/upgrade/manifests/upgrade_manifest_v1.py b/pros/upgrade/manifests/upgrade_manifest_v1.py index d3f0fa1c..0db43075 100644 --- a/pros/upgrade/manifests/upgrade_manifest_v1.py +++ b/pros/upgrade/manifests/upgrade_manifest_v1.py @@ -28,8 +28,7 @@ def describe_update(self) -> str: if self.needs_upgrade: return f'There is an update available! {self.version} is the latest version.\n' \ f'Go to {self.info_url} to learn more.' - else: - return f'You are up to date. ({self.version})' + return f'You are up to date. ({self.version})' def __str__(self): return self.describe_update() From 1c4c1da0155246f568999f00976b985cc696b311 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:57:18 -0500 Subject: [PATCH 43/58] Fix C0303 Probably fixed in 6661f0a34df2518fdfaa626c578bbb6781308c8a --- .pylintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 76c29fa6..2d19420a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -39,7 +39,6 @@ # C0411: Wrongly ordered import # C0412: Ungrouped imports # C0301: Line too long -# C0303: Trailing whitespace # Might be difficult to refactor in some cases # W0718: Broad exception caught @@ -68,4 +67,4 @@ disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123 R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, - C0302, E0110, W0603, R0401, C0303, W4902 + C0302, E0110, W0603, R0401, W4902 From cd8bb4adb0d80dc2fb27fcaa85d41ce636bbe94b Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 5 Mar 2024 02:13:19 -0500 Subject: [PATCH 44/58] Fix W4902 --- .pylintrc | 3 +-- pros/conductor/project/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index 2d19420a..79c7239b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -25,7 +25,6 @@ # W0212: Access to a protected member # W0101: Unreachable code # E0110: Instantiated abstract class -# W4902: Using deprecated method # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -67,4 +66,4 @@ disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123 R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, - C0302, E0110, W0603, R0401, W4902 + C0302, E0110, W0603, R0401 diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index 43bb5365..fb326e47 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -235,7 +235,7 @@ def make(self, build_args: List[str]): stdout=stdout_pipe, stderr=stderr_pipe) except Exception as e: if not os.environ.get('PROS_TOOLCHAIN'): - ui.logger(__name__).warn("PROS toolchain not found! Please ensure the toolchain is installed correctly and your environment variables are set properly.\n") + ui.logger(__name__).warning("PROS toolchain not found! Please ensure the toolchain is installed correctly and your environment variables are set properly.\n") ui.logger(__name__).error(f"ERROR WHILE CALLING '{make_cmd}' WITH EXCEPTION: {str(e)}\n",extra={'sentry':False}) stdout_pipe.close() stderr_pipe.close() @@ -292,7 +292,7 @@ def libscanbuild_capture(args: argparse.Namespace) -> Tuple[int, Iterable[Compil exit_code = run_build(args.build, env=environment, stdout=pipe, stderr=pipe, cwd=self.directory) except Exception as e: if not os.environ.get('PROS_TOOLCHAIN'): - ui.logger(__name__).warn("PROS toolchain not found! Please ensure the toolchain is installed correctly and your environment variables are set properly.\n") + ui.logger(__name__).warning("PROS toolchain not found! Please ensure the toolchain is installed correctly and your environment variables are set properly.\n") ui.logger(__name__).error(f"ERROR WHILE CALLING '{make_cmd}' WITH EXCEPTION: {str(e)}\n",extra={'sentry':False}) if not suppress_output: pipe.close() From 8e9c3cd351b0888038fbdd023dc2a1f3dbf8d46e Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Wed, 6 Mar 2024 21:32:07 -0500 Subject: [PATCH 45/58] Fix R1732 --- .pylintrc | 3 +-- pros/cli/terminal.py | 2 +- pros/common/ui/__init__.py | 2 +- .../common/ui/interactive/renderers/MachineOutputRenderer.py | 2 +- pros/common/utils.py | 3 ++- pros/conductor/project/__init__.py | 5 +++-- pros/conductor/templates/external_template.py | 2 +- setup.py | 5 ++++- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.pylintrc b/.pylintrc index 79c7239b..4df2f8c6 100644 --- a/.pylintrc +++ b/.pylintrc @@ -18,7 +18,6 @@ # W0613: Unused argument # W0511: TODO # C0103: Variable name doesn't conform to naming style -# R1732: Consider using with # W1514: Using open without explicitly specifying an encoding # E1101: Nonexistent member # E0401: Unable to import @@ -63,7 +62,7 @@ max-line-length = 120 disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, W0614, W0401, W1202, W0718, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, - R0912, R0911, W0511, R0902, C0412, C0103, C0301, R1732, R0915, W1514, + R0912, R0911, W0511, R0902, C0412, C0103, C0301, R0915, W1514, E1101, R1734, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401 diff --git a/pros/cli/terminal.py b/pros/cli/terminal.py index eb4c4e8c..fafb8f26 100644 --- a/pros/cli/terminal.py +++ b/pros/cli/terminal.py @@ -87,7 +87,7 @@ def terminal(port: str, backend: str, **kwargs): class TerminalOutput: def __init__(self, file): self.terminal = sys.stdout - self.log = open(file, 'a') + self.log = open(file, 'a') # pylint: disable=consider-using-with def write(self, data): self.terminal.write(data) self.log.write(data) diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index e1db879b..389b3cfa 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -118,7 +118,7 @@ def finalize(method: str, data: Union[str, Dict, object, List[Union[str, Dict, o class _MachineOutputProgressBar(_click_ProgressBar): def __init__(self, *args, **kwargs): - kwargs['file'] = open(os.devnull, 'w', encoding='UTF-8') + kwargs['file'] = open(os.devnull, 'w', encoding='UTF-8') # pylint: disable=consider-using-with self.notify_value = kwargs.pop('notify_value', _current_notify_value) super(_MachineOutputProgressBar, self).__init__(*args, **kwargs) diff --git a/pros/common/ui/interactive/renderers/MachineOutputRenderer.py b/pros/common/ui/interactive/renderers/MachineOutputRenderer.py index 425f7aed..5ce856b1 100644 --- a/pros/common/ui/interactive/renderers/MachineOutputRenderer.py +++ b/pros/common/ui/interactive/renderers/MachineOutputRenderer.py @@ -81,7 +81,7 @@ def stop(self): if current_thread() != self.thread: ui.logger(__name__).debug(f'Interrupting render thread of {self.app}') - while not self.stop_sem.acquire(timeout=0.1): + while not self.stop_sem.acquire(timeout=0.1): # pylint: disable=consider-using-with self.wake_me() ui.logger(__name__).debug(f'Broadcasting stop {self.app}') diff --git a/pros/common/utils.py b/pros/common/utils.py index 8c28da6a..ba877eb4 100644 --- a/pros/common/utils.py +++ b/pros/common/utils.py @@ -13,7 +13,8 @@ @lru_cache(1) def get_version(): try: - ver = open(os.path.join(os.path.dirname(__file__), '..', '..', 'version')).read().strip() + with open(os.path.join(os.path.dirname(__file__), '..', '..', 'version')) as version_file: + ver = version_file.read().strip() if ver is not None: return ver except: diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index fb326e47..54b90250 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -227,6 +227,7 @@ def make(self, build_args: List[str]): make_cmd = os.path.join(os.environ.get('PROS_TOOLCHAIN'), 'bin', 'make.exe') else: make_cmd = 'make' + # pylint: disable=consider-using-with stdout_pipe = EchoPipe() stderr_pipe = EchoPipe(err=True) process=None @@ -256,7 +257,7 @@ def make_scan_build(self, build_args: Tuple[str], cdb_file: Optional[Union[str, if sandbox: import tempfile - td = tempfile.TemporaryDirectory() + td = tempfile.TemporaryDirectory() # pylint: disable=consider-using-with td_path = td.name.replace("\\", "/") build_args = [*build_args, f'BINDIR={td_path}'] @@ -394,7 +395,7 @@ def entry_map(entry: Compilation): entries = itertools.chain(old_entries, new_entries) json_entries = list(map(entry_map, entries)) if isinstance(cdb_file, str): - cdb_file = open(cdb_file, 'w') + cdb_file = open(cdb_file, 'w') # pylint: disable=consider-using-with import json json.dump(json_entries, cdb_file, sort_keys=True, indent=4) diff --git a/pros/conductor/templates/external_template.py b/pros/conductor/templates/external_template.py index ce08662e..77017169 100644 --- a/pros/conductor/templates/external_template.py +++ b/pros/conductor/templates/external_template.py @@ -12,7 +12,7 @@ def __init__(self, file: str, **kwargs): if os.path.isdir(file): file = os.path.join(file, 'template.pros') elif zipfile.is_zipfile(file): - self.tf = tempfile.NamedTemporaryFile(delete=False) + self.tf = tempfile.NamedTemporaryFile(delete=False) # pylint: disable=consider-using-with with zipfile.ZipFile(file) as zf: with zf.open('template.pros') as zt: self.tf.write(zt.read()) diff --git a/setup.py b/setup.py index f26a9741..2a0b8083 100644 --- a/setup.py +++ b/setup.py @@ -3,9 +3,12 @@ from setuptools import setup, find_packages from install_requires import install_requires as install_reqs +with open('pip_version') as version_file: + version = version_file.read().strip() + setup( name='pros-cli', - version=open('pip_version').read().strip(), + version=version, packages=find_packages(), url='https://github.com/purduesigbots/pros-cli', license='MPL-2.0', From 54eed9f4de7666a3e44e177adb21deb452196682 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:57:13 -0400 Subject: [PATCH 46/58] Fix R1734 --- .pylintrc | 3 +-- pros/conductor/conductor.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pylintrc b/.pylintrc index 4df2f8c6..c1ada39a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -30,7 +30,6 @@ # R1729: Use a generator instead of comprehension # W1202: Use % formatting in logging functions and pass the parameters as arguments # R1735: Use literal syntax instead of function calls to create dict -# R1734: Use literal syntax instead of function calls to create list # W1201: Specify string format arguments as logging function parameters # Fixed by auto formatter @@ -63,6 +62,6 @@ max-line-length = 120 disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, W0614, W0401, W1202, W0718, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R0915, W1514, - E1101, R1734, W1201, + E1101, W1201, E0401, W0212, R0904, W0101, C0302, E0110, W0603, R0401 diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index ce2c6679..f8821012 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -183,7 +183,7 @@ def purge_template(self, template: LocalTemplate): def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online: bool = True, allow_offline: bool = True, force_refresh: bool = False, unique: bool = True, **kwargs) -> List[BaseTemplate]: - results = list() if not unique else set() + results = [] if not unique else set() kernel_version = kwargs.get('kernel_version', None) if kwargs.get('early_access', None) is not None: use_early_access = kwargs.get('early_access', False) @@ -194,7 +194,7 @@ def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online: else: query = identifier if allow_offline: - offline_results = list() + offline_results = [] if use_early_access: offline_results.extend(filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.early_access_local_templates)) From e174cb4dbc3b7071e50501b19120a841e88b1c6b Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:14:57 -0400 Subject: [PATCH 47/58] Fix R1735 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 2 +- pros/cli/upload.py | 2 +- pros/common/sentry.py | 2 +- pros/common/ui/interactive/application.py | 24 +++++++++---------- .../ui/interactive/components/button.py | 8 +++---- .../ui/interactive/components/component.py | 20 ++++++++-------- .../ui/interactive/components/container.py | 6 ++--- .../common/ui/interactive/components/input.py | 4 ++-- .../ui/interactive/components/input_groups.py | 6 ++--- .../common/ui/interactive/components/label.py | 6 ++--- pros/common/ui/interactive/observable.py | 2 +- .../interactive/UpdateProjectModal.py | 10 ++++---- pros/conductor/templates/base_template.py | 2 +- pros/serial/devices/vex/v5_device.py | 4 ++-- 15 files changed, 50 insertions(+), 51 deletions(-) diff --git a/.pylintrc b/.pylintrc index c1ada39a..87dfe7da 100644 --- a/.pylintrc +++ b/.pylintrc @@ -29,7 +29,6 @@ # W1203: Use % formatting in logging functions and pass the parameters as arguments # R1729: Use a generator instead of comprehension # W1202: Use % formatting in logging functions and pass the parameters as arguments -# R1735: Use literal syntax instead of function calls to create dict # W1201: Specify string format arguments as logging function parameters # Fixed by auto formatter @@ -60,7 +59,7 @@ max-line-length = 120 disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, - W0614, W0401, W1202, W0718, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613, + W0614, W0401, W1202, W0718, R0914, R1725, C0411, W0237, W0702, W0223, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R0915, W1514, E1101, W1201, E0401, W0212, R0904, W0101, diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 34c74594..9cdb75b9 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -103,7 +103,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 [] diff --git a/pros/cli/upload.py b/pros/cli/upload.py index 44a5ad9e..12d7b457 100644 --- a/pros/cli/upload.py +++ b/pros/cli/upload.py @@ -68,7 +68,7 @@ def upload(path: Optional[str], project: Optional[c.Project], port: str, **kwarg kwargs['remote_name'] = project.name # apply upload_options as a template - options = dict(**project.upload_options) + options = {**project.upload_options} if 'port' in options and port is None: port = options.get('port', None) if 'slot' in options and kwargs.get('slot', None) is None: diff --git a/pros/common/sentry.py b/pros/common/sentry.py index ac32d6b2..e166b03b 100644 --- a/pros/common/sentry.py +++ b/pros/common/sentry.py @@ -36,7 +36,7 @@ def prompt_to_send(event: Dict[str, Any], hint: Optional[Dict[str, Any]]) -> Opt return if not event['tags']: - event['tags'] = dict() + event['tags'] = {} extra_text = '' if 'message' in event: diff --git a/pros/common/ui/interactive/application.py b/pros/common/ui/interactive/application.py index 0db8dfaf..c2328a31 100644 --- a/pros/common/ui/interactive/application.py +++ b/pros/common/ui/interactive/application.py @@ -72,11 +72,11 @@ def __getstate__(self): """ Returns the dictionary representation of this Application """ - return dict( - etype=Application.get_hierarchy(self.__class__), - elements=[e.__getstate__() for e in self.build()], - uuid=self.uuid - ) + return { + "etype": Application.get_hierarchy(self.__class__), + "elements": [e.__getstate__() for e in self.build()], + "uuid": self.uuid + } class Modal(Application[P], Generic[P]): @@ -134,15 +134,15 @@ def __getstate__(self): extra_state = {} if self.description is not None: extra_state['description'] = self.description - return dict( + return { **super(Modal, self).__getstate__(), **extra_state, - title=self.title, - will_abort=self.will_abort, - confirm_button=self.confirm_button, - cancel_button=self.cancel_button, - can_confirm=self.can_confirm - ) + "title": self.title, + "will_abort": self.will_abort, + "confirm_button": self.confirm_button, + "cancel_button": self.cancel_button, + "can_confirm": self.can_confirm + } def _confirm(self, *args, **kwargs): """ diff --git a/pros/common/ui/interactive/components/button.py b/pros/common/ui/interactive/components/button.py index a3716158..746c6e27 100644 --- a/pros/common/ui/interactive/components/button.py +++ b/pros/common/ui/interactive/components/button.py @@ -17,8 +17,8 @@ def on_clicked(self, *handlers: Callable, **kwargs): return self.on('clicked', *handlers, **kwargs) def __getstate__(self) -> dict: - return dict( + return { **super(Button, self).__getstate__(), - text=self.text, - uuid=self.uuid - ) + "text": self.text, + "uuid": self.uuid + } diff --git a/pros/common/ui/interactive/components/component.py b/pros/common/ui/interactive/components/component.py index 254a6761..8ffe3759 100644 --- a/pros/common/ui/interactive/components/component.py +++ b/pros/common/ui/interactive/components/component.py @@ -29,9 +29,9 @@ def get_hierarchy(cls, base: type) -> Optional[List[str]]: return None def __getstate__(self) -> Dict: - return dict( - etype=Component.get_hierarchy(self.__class__) - ) + return { + "etype": Component.get_hierarchy(self.__class__) + } P = TypeVar('P', bound=Parameter) @@ -52,12 +52,12 @@ def __getstate__(self): reason = self.parameter.is_valid_reason() if reason: extra_state['valid_reason'] = self.parameter.is_valid_reason() - return dict( + return { **super(ParameterizedComponent, self).__getstate__(), **extra_state, - value=self.parameter.value, - uuid=self.parameter.uuid, - ) + "value": self.parameter.value, + "uuid": self.parameter.uuid, + } class BasicParameterizedComponent(ParameterizedComponent[P], Generic[P]): @@ -70,7 +70,7 @@ def __init__(self, label: AnyStr, parameter: P): self.label = label def __getstate__(self): - return dict( + return { **super(BasicParameterizedComponent, self).__getstate__(), - text=self.label, - ) + "text": self.label, + } diff --git a/pros/common/ui/interactive/components/container.py b/pros/common/ui/interactive/components/container.py index 736c4f90..23ece2f8 100644 --- a/pros/common/ui/interactive/components/container.py +++ b/pros/common/ui/interactive/components/container.py @@ -26,8 +26,8 @@ def __getstate__(self): extra_state['title'] = self.title if self.description is not None: extra_state['description'] = self.description - return dict( + return { **super(Container, self).__getstate__(), **extra_state, - elements=[e.__getstate__() for e in self.elements] - ) + "elements": [e.__getstate__() for e in self.elements] + } diff --git a/pros/common/ui/interactive/components/input.py b/pros/common/ui/interactive/components/input.py index 8d35b5e8..c543de53 100644 --- a/pros/common/ui/interactive/components/input.py +++ b/pros/common/ui/interactive/components/input.py @@ -16,10 +16,10 @@ def __getstate__(self) -> dict: extra_state = {} if self.placeholder is not None: extra_state['placeholder'] = self.placeholder - return dict( + return { **super(InputBox, self).__getstate__(), **extra_state, - ) + } class FileSelector(InputBox[P], Generic[P]): diff --git a/pros/common/ui/interactive/components/input_groups.py b/pros/common/ui/interactive/components/input_groups.py index 93171cfd..607e59c3 100644 --- a/pros/common/ui/interactive/components/input_groups.py +++ b/pros/common/ui/interactive/components/input_groups.py @@ -4,10 +4,10 @@ class DropDownBox(BasicParameterizedComponent[OptionParameter]): def __getstate__(self): - return dict( + return { **super(DropDownBox, self).__getstate__(), - options=self.parameter.options - ) + "options": self.parameter.options + } class ButtonGroup(DropDownBox): diff --git a/pros/common/ui/interactive/components/label.py b/pros/common/ui/interactive/components/label.py index 6b2e13ce..3559f9d5 100644 --- a/pros/common/ui/interactive/components/label.py +++ b/pros/common/ui/interactive/components/label.py @@ -8,10 +8,10 @@ def __init__(self, text: AnyStr): self.text = text def __getstate__(self): - return dict( + return { **super(Label, self).__getstate__(), - text=self.text - ) + "text": self.text + } class VerbatimLabel(Label): diff --git a/pros/common/ui/interactive/observable.py b/pros/common/ui/interactive/observable.py index ec8b0855..647bb3aa 100644 --- a/pros/common/ui/interactive/observable.py +++ b/pros/common/ui/interactive/observable.py @@ -6,7 +6,7 @@ from pros.common import logger -_uuid_table = dict() # type: Dict[str, Observable] +_uuid_table = {} # type: Dict[str, Observable] class Observable(observable.Observable): diff --git a/pros/conductor/interactive/UpdateProjectModal.py b/pros/conductor/interactive/UpdateProjectModal.py index 348400d6..5ba1665b 100644 --- a/pros/conductor/interactive/UpdateProjectModal.py +++ b/pros/conductor/interactive/UpdateProjectModal.py @@ -25,9 +25,9 @@ def is_processing(self, value: bool): def _generate_transaction(self) -> ProjectTransaction: transaction = ProjectTransaction(self.project, self.conductor) - apply_kwargs = dict( - force_apply=self.force_apply_parameter.value - ) + apply_kwargs = { + "force_apply": self.force_apply_parameter.value + } if self.name.value != self.project.name: transaction.change_name(self.name.value) if self.project.template_is_applicable(self.current_kernel.value, **apply_kwargs): @@ -130,9 +130,9 @@ def build(self) -> Generator[components.Component, None, None]: assert self.project is not None yield components.Label(f'Modify your {self.project.target} project.') yield components.InputBox('Project Name', self.name) - yield TemplateListingComponent(self.current_kernel, editable=dict(version=True), removable=False) + yield TemplateListingComponent(self.current_kernel, editable={"version": True}, removable=False) yield components.Container( - *(TemplateListingComponent(t, editable=dict(version=True), removable=True) for t in + *(TemplateListingComponent(t, editable={"version": True}, removable=True) for t in self.current_templates), *(TemplateListingComponent(t, editable=True, removable=True) for t in self.new_templates), self.add_template_button, diff --git a/pros/conductor/templates/base_template.py b/pros/conductor/templates/base_template.py index c7799d13..308780d3 100644 --- a/pros/conductor/templates/base_template.py +++ b/pros/conductor/templates/base_template.py @@ -65,7 +65,7 @@ def __hash__(self): def as_query(self, version='>0', metadata=False, **kwargs): if isinstance(metadata, bool) and not metadata: - metadata = dict() + metadata = {} return BaseTemplate(orig=self, version=version, metadata=metadata, **kwargs) @property diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index 8bfabbda..61672f3d 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -710,7 +710,7 @@ def ft_write(self, addr: int, payload: Union[Iterable, bytes, bytearray, str]): def ft_read(self, addr: int, n_bytes: int) -> bytearray: logger(__name__).debug('Sending ext 0x14 command') actual_n_bytes = n_bytes + (0 if n_bytes % 4 == 0 else 4 - n_bytes % 4) - ui.logger(__name__).debug(dict(actual_n_bytes=actual_n_bytes, addr=addr)) + ui.logger(__name__).debug({"actual_n_bytes": actual_n_bytes, "addr": addr}) tx_payload = struct.pack(" Date: Tue, 19 Mar 2024 21:50:34 -0400 Subject: [PATCH 48/58] Test R0401 --- .pylintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 87dfe7da..93d47773 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,7 +55,7 @@ # R0904: Too many public methods # C0302: Too many lines in module # W0603: Using the global statement -# R0401: Cyclic import +# R0401: Cyclic import -- Seems to be platform specific max-line-length = 120 disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, @@ -63,4 +63,4 @@ disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123 R0912, R0911, W0511, R0902, C0412, C0103, C0301, R0915, W1514, E1101, W1201, E0401, W0212, R0904, W0101, - C0302, E0110, W0603, R0401 + C0302, E0110, W0603 From bf70bdb24247da419b4c5d4edd263c5741f964a8 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:55:31 -0400 Subject: [PATCH 49/58] Disable R0401 --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 93d47773..05bc2530 100644 --- a/.pylintrc +++ b/.pylintrc @@ -63,4 +63,4 @@ disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123 R0912, R0911, W0511, R0902, C0412, C0103, C0301, R0915, W1514, E1101, W1201, E0401, W0212, R0904, W0101, - C0302, E0110, W0603 + C0302, E0110, W0603, R0401 From 2e9f7b3bb274f06827067a89acc25c3f7e15bf42 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Sun, 24 Mar 2024 00:20:44 -0400 Subject: [PATCH 50/58] Fix E0110 It fixed itself? idk --- .pylintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 05bc2530..c2f4da35 100644 --- a/.pylintrc +++ b/.pylintrc @@ -23,7 +23,6 @@ # E0401: Unable to import # W0212: Access to a protected member # W0101: Unreachable code -# E0110: Instantiated abstract class # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments @@ -63,4 +62,4 @@ disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123 R0912, R0911, W0511, R0902, C0412, C0103, C0301, R0915, W1514, E1101, W1201, E0401, W0212, R0904, W0101, - C0302, E0110, W0603, R0401 + C0302, W0603, R0401 From a3be5565e05be89da6e2ae5e69f46e1ee075cecf Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Sun, 24 Mar 2024 00:29:52 -0400 Subject: [PATCH 51/58] Fix W0223 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 3 ++- pros/serial/devices/vex/stm32_device.py | 4 ++++ pros/serial/ports/serial_share_port.py | 4 ++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index c2f4da35..779164a2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -14,7 +14,6 @@ # W0401: Wildcard import # R1725: Super with arguments # W0237: Renamed arguments -# W0223: Abstract method is not overridden # W0613: Unused argument # W0511: TODO # C0103: Variable name doesn't conform to naming style @@ -58,7 +57,7 @@ max-line-length = 120 disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, - W0614, W0401, W1202, W0718, R0914, R1725, C0411, W0237, W0702, W0223, W0613, + W0614, W0401, W1202, W0718, R0914, R1725, C0411, W0237, W0702, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R0915, W1514, E1101, W1201, E0401, W0212, R0904, W0101, diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 9cdb75b9..0460ad5c 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -67,7 +67,8 @@ class PROSCommand(PROSFormatted, click.Command): # Seems to be unused? class PROSMultiCommand(PROSFormatted, click.MultiCommand): - pass + def get_command(self, ctx: click.Context, cmd_name: str) -> Optional[click.Command]: + pass class PROSOption(click.Option): diff --git a/pros/serial/devices/vex/stm32_device.py b/pros/serial/devices/vex/stm32_device.py index 23e6f05b..db67150e 100644 --- a/pros/serial/devices/vex/stm32_device.py +++ b/pros/serial/devices/vex/stm32_device.py @@ -8,6 +8,7 @@ from pros.common import ui from pros.common import logger, retries +from pros.conductor import Project from pros.serial import bytes_to_str from pros.serial.devices.vex import VEXCommError from pros.serial.ports import BasePort @@ -189,3 +190,6 @@ def _txrx_command(self, command: Union[int, bytes], timeout: float = 0.01, check if data[0] == self.ACK_BYTE: return raise VEXCommError(f"Device never ACK'd to {command}", command) + + def upload_project(self, project: Project, **kwargs): + pass diff --git a/pros/serial/ports/serial_share_port.py b/pros/serial/ports/serial_share_port.py index 2ee58587..14c18910 100644 --- a/pros/serial/ports/serial_share_port.py +++ b/pros/serial/ports/serial_share_port.py @@ -82,3 +82,7 @@ def _kick_watchdog(self): self.to_device_sock.send_multipart([b'kick']) self.alive.wait(2.5) logger(__name__).info('Watchdog kicker is dying') + + @property + def name(self): + pass From 8838799725236a114e66a8ff7ea6c72f52a6a21b Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:08:04 -0400 Subject: [PATCH 52/58] Fix R1710 --- .pylintrc | 3 +-- pros/cli/click_classes.py | 2 +- pros/cli/common.py | 2 +- pros/cli/conductor.py | 1 + pros/cli/conductor_utils.py | 2 +- pros/cli/misc_commands.py | 2 +- pros/cli/terminal.py | 1 + pros/cli/v5_utils.py | 13 ++++++++++++- pros/common/sentry.py | 9 +++++---- pros/common/ui/__init__.py | 2 ++ pros/common/utils.py | 1 + pros/conductor/conductor.py | 3 ++- pros/conductor/project/ProjectTransaction.py | 1 + pros/serial/terminal/terminal.py | 2 +- 14 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.pylintrc b/.pylintrc index 779164a2..6a9329cc 100644 --- a/.pylintrc +++ b/.pylintrc @@ -8,7 +8,6 @@ # E1120: No value for argument in function call # E1123: Unexpected argument in function call # C0209: Consider using an f-string -# R1710: Either all return statements in a function should return an expression, or none of them should # W0621: Redefining name from outer scope # W0614: Unused import from wildcard import # W0401: Wildcard import @@ -56,7 +55,7 @@ # R0401: Cyclic import -- Seems to be platform specific max-line-length = 120 -disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, +disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, W0621, W0614, W0401, W1202, W0718, R0914, R1725, C0411, W0237, W0702, W0613, R0912, R0911, W0511, R0902, C0412, C0103, C0301, R0915, W1514, E1101, W1201, diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 0460ad5c..13fb6519 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -79,7 +79,7 @@ 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): diff --git a/pros/cli/common.py b/pros/cli/common.py index 5f6f8be5..fcf75186 100644 --- a/pros/cli/common.py +++ b/pros/cli/common.py @@ -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): diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index dd717135..60f556bc 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -77,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}) diff --git a/pros/cli/conductor_utils.py b/pros/cli/conductor_utils.py index a933acaa..580a95aa 100644 --- a/pros/cli/conductor_utils.py +++ b/pros/cli/conductor_utils.py @@ -161,7 +161,7 @@ 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: diff --git a/pros/cli/misc_commands.py b/pros/cli/misc_commands.py index 9aade94e..115bbcc6 100644 --- a/pros/cli/misc_commands.py +++ b/pros/cli/misc_commands.py @@ -20,7 +20,7 @@ def upgrade(force_check, no_install): with ui.Notification(): ui.echo('The "pros upgrade" command is currently non-functioning. Did you mean to run "pros c upgrade"?', color='yellow') - return # Dead code below + return None # Dead code below analytics.send("upgrade") from pros.upgrade import UpgradeManager diff --git a/pros/cli/terminal.py b/pros/cli/terminal.py index fafb8f26..8db429ea 100644 --- a/pros/cli/terminal.py +++ b/pros/cli/terminal.py @@ -83,6 +83,7 @@ def terminal(port: str, backend: str, **kwargs): else: device = devices.vex.V5UserDevice(ser) term = Terminal(device, request_banner=kwargs.pop('request_banner', True)) + return 0 class TerminalOutput: def __init__(self, file): diff --git a/pros/cli/v5_utils.py b/pros/cli/v5_utils.py index 8d85b3a5..11882caf 100644 --- a/pros/cli/v5_utils.py +++ b/pros/cli/v5_utils.py @@ -36,6 +36,7 @@ def status(port: str): print('CPU0 F/W version:', device.status['cpu0_version']) print('CPU1 SDK version:', device.status['cpu1_version']) print('System ID: 0x{:x}'.format(device.status['system_id'])) + return 0 @v5.command('ls-files') @@ -59,6 +60,7 @@ def ls_files(port: str, vid: int, options: int): c = device.get_dir_count(vid=vid, options=options) for i in range(0, c): print(device.get_file_metadata_by_idx(i)) + return 0 @v5.command(hidden=True) @@ -83,6 +85,7 @@ def read_file(file_name: str, port: str, vid: int, source: str): device = V5Device(ser) device.read_file(file=click.get_binary_stream('stdout'), remote_file=file_name, vid=vid, target=source) + return 0 @v5.command(hidden=True) @@ -108,6 +111,7 @@ def write_file(file, port: str, remote_file: str, **kwargs): ser = DirectPort(port) device = V5Device(ser) device.write_file(file=file, remote_file=remote_file or os.path.basename(file.name), **kwargs) + return 0 @v5.command('rm-file') @@ -131,6 +135,7 @@ def rm_file(file_name: str, port: str, vid: int, erase_all: bool): ser = DirectPort(port) device = V5Device(ser) device.erase_file(file_name, vid=vid, erase_all=erase_all) + return 0 @v5.command('cat-metadata') @@ -152,6 +157,7 @@ def cat_metadata(file_name: str, port: str, vid: int): ser = DirectPort(port) device = V5Device(ser) print(device.get_file_metadata_by_name(file_name, vid=vid)) + return 0 @v5.command('rm-program') @click.argument('slot') @@ -173,6 +179,7 @@ def rm_program(slot: int, port: str, vid: int): device = V5Device(ser) device.erase_file(f'{base_name}.ini', vid=vid) device.erase_file(f'{base_name}.bin', vid=vid) + return 0 @v5.command('rm-all') @click.argument('port', required=False, default=None) @@ -197,6 +204,7 @@ def rm_all(port: str, vid: int): files.append(device.get_file_metadata_by_idx(i)['filename']) for file in files: device.erase_file(file, vid=vid) + return 0 @v5.command(short_help='Run a V5 Program') @@ -221,6 +229,7 @@ def run(slot: str, port: str): ser = DirectPort(port) device = V5Device(ser) device.execute_program_file(file, run=True) + return 0 @v5.command(short_help='Stop a V5 Program') @@ -240,6 +249,7 @@ def stop(port: str): ser = DirectPort(port) device = V5Device(ser) device.execute_program_file('', run=False) + return 0 @v5.command(short_help='Take a screen capture of the display') @@ -275,7 +285,7 @@ def capture(file_name: str, port: str, force: bool = False): if file_name == '-': # Send the data to stdout to allow for piping print(i_data, end='') - return + return 0 if not file_name.endswith('.png'): file_name += '.png' @@ -290,6 +300,7 @@ def capture(file_name: str, port: str, force: bool = False): w.write(file_, i_data) print(f'Saved screen capture to {file_name}') + return 0 @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) diff --git a/pros/common/sentry.py b/pros/common/sentry.py index e166b03b..079af752 100644 --- a/pros/common/sentry.py +++ b/pros/common/sentry.py @@ -23,17 +23,17 @@ def prompt_to_send(event: Dict[str, Any], hint: Optional[Dict[str, Any]]) -> Opt """ with ui.Notification(): if cli_config is None or (cli_config.offer_sentry is not None and not cli_config.offer_sentry): - return + return None if force_prompt_off: ui.logger(__name__).debug('Sentry prompt was forced off through click option') - return + return None if 'extra' in event and not event['extra'].get('sentry', True): ui.logger(__name__).debug('Not sending candidate event because event was tagged with extra.sentry = False') - return + return None if 'exc_info' in hint and (not getattr(hint['exc_info'][1], 'sentry', True) or any(isinstance(hint['exc_info'][1], t) for t in SUPPRESSED_EXCEPTIONS)): ui.logger(__name__).debug('Not sending candidate event because exception was tagged with sentry = False') - return + return None if not event['tags']: event['tags'] = {} @@ -57,6 +57,7 @@ def prompt_to_send(event: Dict[str, Any], hint: Optional[Dict[str, Any]]) -> Opt ui.echo(f'Want to get updates? Visit https://pros.cs.purdue.edu/report.html?event={event["event_id"]}') return event ui.echo('Not sending bug report.') + return None def add_context(obj: object, override_handlers: bool = True, key: str = None) -> None: diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index 389b3cfa..ca2dadb5 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -31,6 +31,7 @@ def echo(text: Any, err: bool = False, nl: bool = True, notify_value: int = None return _machine_notify('echo', {'text': str(text) + ('\n' if nl else '')}, notify_value) else: return click.echo(str(text), nl=nl, err=err, color=color) + return None def confirm(text: str, default: bool = False, abort: bool = False, prompt_suffix: bool = ': ', @@ -61,6 +62,7 @@ def prompt(text, default=None, hide_input=False, return click.prompt(text, default=default, hide_input=hide_input, confirmation_prompt=confirmation_prompt, type=value_type, value_proc=value_proc, prompt_suffix=prompt_suffix, show_default=show_default, err=err) + return None def progressbar(iterable: Iterable = None, length: int = None, label: str = None, show_eta: bool = True, diff --git a/pros/common/utils.py b/pros/common/utils.py index ba877eb4..a786db13 100644 --- a/pros/common/utils.py +++ b/pros/common/utils.py @@ -97,6 +97,7 @@ def _wrap(*args, **kwargs): return func(*args, **kwargs) except BaseException as e: logger(__name__).exception(e) + return None return _wrap diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index f8821012..e756c5d9 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -309,7 +309,8 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate], kwargs['version'] = '>=0' kwargs['early_access'] = True # Recall the function with early access enabled - return self.apply_template(project, identifier, **kwargs) + self.apply_template(project, identifier, **kwargs) + return self.save() if not isinstance(template, LocalTemplate): diff --git a/pros/conductor/project/ProjectTransaction.py b/pros/conductor/project/ProjectTransaction.py index 8a01685b..320d6784 100644 --- a/pros/conductor/project/ProjectTransaction.py +++ b/pros/conductor/project/ProjectTransaction.py @@ -54,6 +54,7 @@ def describe(self, conductor: c.Conductor, project: c.Project): if self.suppress_already_installed: return f'{self.template.identifier} will not be re-applied.' return f'{self.template.identifier} cannot be applied to project because it is already installed.' + return None def can_execute(self, conductor: c.Conductor, project: c.Project) -> bool: action = project.get_template_actions(conductor.resolve_template(self.template)) diff --git a/pros/serial/terminal/terminal.py b/pros/serial/terminal/terminal.py index 31a7be53..80dbae72 100644 --- a/pros/serial/terminal/terminal.py +++ b/pros/serial/terminal/terminal.py @@ -148,7 +148,7 @@ def getkey(self): [], None) if self.pipe_r in ready: os.read(self.pipe_r, 1) - return + return None c = self.enc_stdin.read(1) if c == chr(0x7f): c = chr(8) # map the BS key (which yields DEL) to backspace From 5df6f16831da0b9342980494eff4ea25fbe78f39 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:13:51 -0400 Subject: [PATCH 53/58] Fix R1729 --- .pylintrc | 3 +-- pros/conductor/project/__init__.py | 8 ++++---- pros/conductor/templates/base_template.py | 2 +- pros/config/cli_config.py | 2 +- pros/serial/devices/vex/stm32_device.py | 4 ++-- pros/serial/devices/vex/v5_device.py | 6 +++--- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.pylintrc b/.pylintrc index 6a9329cc..2c3478bd 100644 --- a/.pylintrc +++ b/.pylintrc @@ -24,7 +24,6 @@ # Performance optimization # W1203: Use % formatting in logging functions and pass the parameters as arguments -# R1729: Use a generator instead of comprehension # W1202: Use % formatting in logging functions and pass the parameters as arguments # W1201: Specify string format arguments as logging function parameters @@ -55,7 +54,7 @@ # R0401: Cyclic import -- Seems to be platform specific max-line-length = 120 -disable = C0114, C0115, C0116, R0903, C0415, R0913, W1203, R1729, E1120, E1123, C0209, W0621, +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, C0103, C0301, R0915, W1514, E1101, W1201, diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index 54b90250..5fad0a00 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -85,7 +85,7 @@ def get_template_actions(self, template: BaseTemplate) -> TemplateAction: if current > template: return TemplateAction.Downgradable - if any([template > current for current in self.templates.values()]): + if any(template > current for current in self.templates.values()): return TemplateAction.Upgradable return TemplateAction.Installable @@ -144,8 +144,8 @@ def new_user_filter(new_file: str) -> bool: src/opcontrol.c and src/opcontrol.cpp are friends because they have the same stem src/opcontrol.c and include/opcontrol.h are not because they are in different directories """ - return not any([(os.path.normpath(file) in transaction.effective_state) for file in template.user_files if - os.path.splitext(file)[0] == os.path.splitext(new_file)[0]]) + return not any((os.path.normpath(file) in transaction.effective_state) for file in template.user_files if + os.path.splitext(file)[0] == os.path.splitext(new_file)[0]) if force_user: new_user_files = template.real_user_files @@ -153,7 +153,7 @@ def new_user_filter(new_file: str) -> bool: new_user_files = filter(new_user_filter, template.real_user_files) transaction.extend_add(new_user_files, template.location) - if any([file in transaction.effective_state for file in template.system_files]) and not force_system: + if any(file in transaction.effective_state for file in template.system_files) and not force_system: confirm(f'Some required files for {template.identifier} already exist in the project. ' f'Overwrite the existing files?', abort=True) transaction.extend_add(template.system_files, template.location) diff --git a/pros/conductor/templates/base_template.py b/pros/conductor/templates/base_template.py index 308780d3..2b993cf2 100644 --- a/pros/conductor/templates/base_template.py +++ b/pros/conductor/templates/base_template.py @@ -40,7 +40,7 @@ def satisfies(self, query: 'BaseTemplate', kernel_version: Union[str, Version] = # Find the intersection of the keys in the template's metadata with the keys in the query metadata # This is what allows us to throw all arguments into the query metadata (from the CLI, e.g. those intended # for the depot or template application hints) - if any([self.metadata[k] != query.metadata[k] for k in keys_intersection]): + if any(self.metadata[k] != query.metadata[k] for k in keys_intersection): return False return True diff --git a/pros/config/cli_config.py b/pros/config/cli_config.py index 72d77c17..0e4fe101 100644 --- a/pros/config/cli_config.py +++ b/pros/config/cli_config.py @@ -32,7 +32,7 @@ def use_build_compile_commands(self): if self.override_use_build_compile_commands is not None: return self.override_use_build_compile_commands paths = [os.path.join('~', '.pros-atom'), os.path.join('~', '.pros-editor')] - return any([os.path.exists(os.path.expanduser(p)) for p in paths]) + return any(os.path.exists(os.path.expanduser(p)) for p in paths) def get_upgrade_manifest(self, force: bool = False) -> Optional['UpgradeManifestV1']: from pros.upgrade.manifests.upgrade_manifest_v1 import UpgradeManifestV1 # noqa: F811 diff --git a/pros/serial/devices/vex/stm32_device.py b/pros/serial/devices/vex/stm32_device.py index db67150e..64f0b764 100644 --- a/pros/serial/devices/vex/stm32_device.py +++ b/pros/serial/devices/vex/stm32_device.py @@ -148,7 +148,7 @@ def erase_memory(self, page_numbers: List[int]): if not self.commands[6] == 0x43: raise VEXCommError('Standard erase not supported on this device (only extended erase)') assert 0 < len(page_numbers) <= 255 - assert all([0 <= p <= 255 for p in page_numbers]) + assert all(0 <= p <= 255 for p in page_numbers) self._txrx_command(0x43) self._txrx_command(bytes([len(page_numbers) - 1, *page_numbers])) @@ -158,7 +158,7 @@ def extended_erase(self, page_numbers: List[int]): if not self.commands[6] == 0x44: raise IOError('Extended erase not supported on this device (only standard erase)') assert 0 < len(page_numbers) < 0xfff0 - assert all([0 <= p <= 0xffff for p in page_numbers]) + assert all(0 <= p <= 0xffff for p in page_numbers) self._txrx_command(0x44) self._txrx_command(bytes([len(page_numbers) - 1, *struct.pack(f'>{len(page_numbers)}H', *page_numbers)])) diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index 61672f3d..68f59380 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -37,9 +37,9 @@ def filter_vex_ports(p): p.name is not None and ('VEX' in p.name or 'V5' in p.name) def filter_v5_ports(p, locations, names): - return (p.location is not None and any([p.location.endswith(l) for l in locations])) or \ - (p.name is not None and any([n in p.name for n in names])) or \ - (p.description is not None and any([n in p.description for n in names])) + return (p.location is not None and any(p.location.endswith(l) for l in locations)) or \ + (p.name is not None and any(n in p.name for n in names)) or \ + (p.description is not None and any(n in p.description for n in names)) def filter_v5_ports_mac(p, device): return (p.device is not None and p.device.endswith(device)) From 5d925daf8cd68164cd8bc66c7b28bfcfe34be570 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:06:57 -0400 Subject: [PATCH 54/58] Fix terminal Broken in 8838799725236a114e66a8ff7ea6c72f52a6a21b --- pros/cli/terminal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pros/cli/terminal.py b/pros/cli/terminal.py index 8db429ea..048c498d 100644 --- a/pros/cli/terminal.py +++ b/pros/cli/terminal.py @@ -83,7 +83,6 @@ def terminal(port: str, backend: str, **kwargs): else: device = devices.vex.V5UserDevice(ser) term = Terminal(device, request_banner=kwargs.pop('request_banner', True)) - return 0 class TerminalOutput: def __init__(self, file): @@ -118,3 +117,4 @@ def end(self): output.end() term.join() logger(__name__).info('CLI Main Thread Dying') + return 0 From 609d479debc4a35600318f439d3d8f7f16060042 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:01:20 -0400 Subject: [PATCH 55/58] Fix C0103 -- variables --- pros/cli/click_classes.py | 4 +- pros/cli/common.py | 2 +- pros/cli/main.py | 12 +++--- pros/common/sentry.py | 8 ++-- pros/common/ui/__init__.py | 36 ++++++++-------- pros/conductor/conductor.py | 18 ++++---- pros/conductor/project/ProjectTransaction.py | 16 +++---- pros/conductor/project/__init__.py | 22 +++++----- pros/conductor/project/template_resolution.py | 14 +++---- pros/ga/analytics.py | 32 +++++++------- pros/serial/devices/vex/v5_device.py | 22 +++++----- pros/upgrade/manifests/upgrade_manifest_v2.py | 24 +++++------ pros/upgrade/upgrade_manager.py | 6 +-- version.py | 42 +++++++++---------- 14 files changed, 129 insertions(+), 129 deletions(-) diff --git a/pros/cli/click_classes.py b/pros/cli/click_classes.py index 13fb6519..4ab301d2 100644 --- a/pros/cli/click_classes.py +++ b/pros/cli/click_classes.py @@ -160,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 diff --git a/pros/cli/common.py b/pros/cli/common.py index fcf75186..5cdebd91 100644 --- a/pros/cli/common.py +++ b/pros/cli/common.py @@ -138,7 +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 + 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__ diff --git a/pros/cli/main.py b/pros/cli/main.py index 858f5cc2..e44a8f9d 100644 --- a/pros/cli/main.py +++ b/pros/cli/main.py @@ -45,14 +45,14 @@ ] if getattr(sys, 'frozen', False): - exe_file = sys.executable + EXE_FILE = sys.executable else: - exe_file = __file__ + EXE_FILE = __file__ -if os.path.exists(os.path.join(os.path.dirname(exe_file), os.pardir, os.pardir, '.git')): +if os.path.exists(os.path.join(os.path.dirname(EXE_FILE), os.pardir, os.pardir, '.git')): root_sources.append('test') -if os.path.exists(os.path.join(os.path.dirname(exe_file), os.pardir, os.pardir, '.git')): +if os.path.exists(os.path.join(os.path.dirname(EXE_FILE), os.pardir, os.pardir, '.git')): import pros.cli.test for root_source in root_sources: @@ -89,7 +89,7 @@ def version(ctx: click.Context, param, value): def use_analytics(ctx: click.Context, param, value): if value is None: return - touse = not analytics.useAnalytics + touse = not analytics.use_analytics if str(value).lower().startswith("t"): touse = True elif str(value).lower().startswith("f"): @@ -99,7 +99,7 @@ def use_analytics(ctx: click.Context, param, value): ctx.exit(0) ctx.ensure_object(dict) analytics.set_use(touse) - ui.echo(f'Analytics usage set to: {analytics.useAnalytics}') + ui.echo(f'Analytics usage set to: {analytics.use_analytics}') ctx.exit(0) def use_early_access(ctx: click.Context, param, value): diff --git a/pros/common/sentry.py b/pros/common/sentry.py index 079af752..8934f51f 100644 --- a/pros/common/sentry.py +++ b/pros/common/sentry.py @@ -10,12 +10,12 @@ from pros.config.cli_config import CliConfig # noqa: F401, flake8 issue, flake8 issue with "if TYPE_CHECKING" cli_config: 'CliConfig' = None -force_prompt_off = False +FORCE_PROMPT_OFF = False SUPPRESSED_EXCEPTIONS = [PermissionError, click.Abort] def disable_prompt(): - global force_prompt_off - force_prompt_off = True + global FORCE_PROMPT_OFF + FORCE_PROMPT_OFF = True def prompt_to_send(event: Dict[str, Any], hint: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]: """ @@ -24,7 +24,7 @@ def prompt_to_send(event: Dict[str, Any], hint: Optional[Dict[str, Any]]) -> Opt with ui.Notification(): if cli_config is None or (cli_config.offer_sentry is not None and not cli_config.offer_sentry): return None - if force_prompt_off: + if FORCE_PROMPT_OFF: ui.logger(__name__).debug('Sentry prompt was forced off through click option') return None if 'extra' in event and not event['extra'].get('sentry', True): diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index ca2dadb5..237a9ec0 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -6,8 +6,8 @@ from ..utils import * -_last_notify_value = 0 -_current_notify_value = 0 +_LAST_NOTIFY_VALUE = 0 +_CURRENT_NOTIFY_VALUE = 0 _machine_pickler = jsonpickle.JSONBackend() @@ -17,7 +17,7 @@ def _machineoutput(obj: Dict[str, Any]): def _machine_notify(method: str, obj: Dict[str, Any], notify_value: Optional[int]): if notify_value is None: - notify_value = _current_notify_value + notify_value = _CURRENT_NOTIFY_VALUE obj['type'] = f'notify/{method}' obj['notify_value'] = notify_value _machineoutput(obj) @@ -121,7 +121,7 @@ def finalize(method: str, data: Union[str, Dict, object, List[Union[str, Dict, o class _MachineOutputProgressBar(_click_ProgressBar): def __init__(self, *args, **kwargs): kwargs['file'] = open(os.devnull, 'w', encoding='UTF-8') # pylint: disable=consider-using-with - self.notify_value = kwargs.pop('notify_value', _current_notify_value) + self.notify_value = kwargs.pop('notify_value', _CURRENT_NOTIFY_VALUE) super(_MachineOutputProgressBar, self).__init__(*args, **kwargs) def __del__(self): @@ -137,21 +137,21 @@ def render_progress(self): class Notification: def __init__(self, notify_value: Optional[int] = None): - global _last_notify_value + global _LAST_NOTIFY_VALUE if not notify_value: - notify_value = _last_notify_value + 1 - _last_notify_value = max(_last_notify_value, notify_value) + notify_value = _LAST_NOTIFY_VALUE + 1 + _LAST_NOTIFY_VALUE = max(_LAST_NOTIFY_VALUE, notify_value) self.notify_value = notify_value self.old_notify_values = [] def __enter__(self): - global _current_notify_value - self.old_notify_values.append(_current_notify_value) - _current_notify_value = self.notify_value + global _CURRENT_NOTIFY_VALUE + self.old_notify_values.append(_CURRENT_NOTIFY_VALUE) + _CURRENT_NOTIFY_VALUE = self.notify_value def __exit__(self, exc_type, exc_val, exc_tb): - global _current_notify_value - _current_notify_value = self.old_notify_values.pop() + global _CURRENT_NOTIFY_VALUE + _CURRENT_NOTIFY_VALUE = self.old_notify_values.pop() class EchoPipe(threading.Thread): @@ -163,27 +163,27 @@ def __init__(self, err: bool = False, ctx: Optional[click.Context] = None): self.is_err = err threading.Thread.__init__(self) self.daemon = False - self.fdRead, self.fdWrite = os.pipe() - self.pipeReader = os.fdopen(self.fdRead, encoding='UTF-8') + self.fd_read, self.fd_write = os.pipe() + self.pipe_reader = os.fdopen(self.fd_read, encoding='UTF-8') self.start() def fileno(self): """Return the write file descriptor of the pipe """ - return self.fdWrite + return self.fd_write def run(self): """Run the thread, logging everything. """ - for line in iter(self.pipeReader.readline, ''): + for line in iter(self.pipe_reader.readline, ''): echo(line.strip('\n'), ctx=self.click_ctx, err=self.is_err) - self.pipeReader.close() + self.pipe_reader.close() def close(self): """Close the write end of the pipe. """ - os.close(self.fdWrite) + os.close(self.fd_write) __all__ = ['finalize', 'echo', 'confirm', 'prompt', 'progressbar', 'EchoPipe'] diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index e756c5d9..70488b47 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -25,8 +25,8 @@ """ # TBD? Currently, EarlyAccess value is stored in config file class ReleaseChannel(Enum): - Stable = 'stable' - Beta = 'beta' + STABLE = 'stable' + BETA = 'beta' """ def is_pathname_valid(pathname: str) -> bool: @@ -282,8 +282,8 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate], # warn and prompt user if upgrading to PROS 4 or downgrading to PROS 3 if template.name == 'kernel': - isProject = Project.find_project("") - if isProject: + is_project = Project.find_project("") + if is_project: curr_proj = Project() if curr_proj.kernel: if template.version[0] == '4' and curr_proj.kernel[0] == '3': @@ -320,21 +320,21 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate], logger(__name__).info(str(project)) valid_action = project.get_template_actions(template) - if valid_action == TemplateAction.NotApplicable: + if valid_action == TemplateAction.NOT_APPLICABLE: raise dont_send( InvalidTemplateException(f'{template.identifier} is not applicable to {project}', reason=valid_action) ) should_apply = force \ - or (valid_action == TemplateAction.Upgradable and upgrade_ok) \ - or (valid_action == TemplateAction.Installable and install_ok) \ - or (valid_action == TemplateAction.Downgradable and downgrade_ok) + or (valid_action == TemplateAction.UPGRADABLE and upgrade_ok) \ + or (valid_action == TemplateAction.INSTALLABLE and install_ok) \ + or (valid_action == TemplateAction.DOWNGRADABLE and downgrade_ok) if should_apply: project.apply_template(template, force_system=kwargs.pop('force_system', False), force_user=kwargs.pop('force_user', False), remove_empty_directories=kwargs.pop('remove_empty_directories', False)) ui.finalize('apply', f'Finished applying {template.identifier} to {project.location}') - elif valid_action != TemplateAction.AlreadyInstalled: + elif valid_action != TemplateAction.ALREADY_INSTALLED: raise dont_send( InvalidTemplateException(f'Could not install {template.identifier} because it is {valid_action.name},' f' and that is not allowed.', reason=valid_action) diff --git a/pros/conductor/project/ProjectTransaction.py b/pros/conductor/project/ProjectTransaction.py index 320d6784..04bdb6f8 100644 --- a/pros/conductor/project/ProjectTransaction.py +++ b/pros/conductor/project/ProjectTransaction.py @@ -32,23 +32,23 @@ def execute(self, conductor: c.Conductor, project: c.Project): try: conductor.apply_template(project, self.template, **self.apply_kwargs) except InvalidTemplateException as e: - if e.reason != TemplateAction.AlreadyInstalled or not self.suppress_already_installed: + if e.reason != TemplateAction.ALREADY_INSTALLED or not self.suppress_already_installed: raise e ui.logger(__name__).warning(str(e)) def describe(self, conductor: c.Conductor, project: c.Project): action = project.get_template_actions(conductor.resolve_template(self.template)) - if action == TemplateAction.NotApplicable: + if action == TemplateAction.NOT_APPLICABLE: return f'{self.template.identifier} cannot be applied to project!' - if action == TemplateAction.Installable: + if action == TemplateAction.INSTALLABLE: return f'{self.template.identifier} will installed to project.' - if action == TemplateAction.Downgradable: + if action == TemplateAction.DOWNGRADABLE: return f'Project will be downgraded to {self.template.identifier} from' \ f' {project.templates[self.template.name].version}.' - if action == TemplateAction.Upgradable: + if action == TemplateAction.UPGRADABLE: return f'Project will be upgraded to {self.template.identifier} from' \ f' {project.templates[self.template.name].version}.' - if action == TemplateAction.AlreadyInstalled: + if action == TemplateAction.ALREADY_INSTALLED: if self.apply_kwargs.get('force_apply'): return f'{self.template.identifier} will be re-applied.' if self.suppress_already_installed: @@ -58,9 +58,9 @@ def describe(self, conductor: c.Conductor, project: c.Project): def can_execute(self, conductor: c.Conductor, project: c.Project) -> bool: action = project.get_template_actions(conductor.resolve_template(self.template)) - if action == TemplateAction.AlreadyInstalled: + if action == TemplateAction.ALREADY_INSTALLED: return self.apply_kwargs.get('force_apply') or self.suppress_already_installed - return action in [TemplateAction.Installable, TemplateAction.Downgradable, TemplateAction.Upgradable] + return action in [TemplateAction.INSTALLABLE, TemplateAction.DOWNGRADABLE, TemplateAction.UPGRADABLE] class RemoveTemplateAction(Action): diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index 5fad0a00..b53a41f9 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -69,36 +69,36 @@ def all_files(self) -> Set[str]: def get_template_actions(self, template: BaseTemplate) -> TemplateAction: ui.logger(__name__).debug(template) if template.target != self.target: - return TemplateAction.NotApplicable + return TemplateAction.NOT_APPLICABLE from semantic_version import Spec, Version if template.name != 'kernel' and Version(self.kernel) not in Spec(template.supported_kernels or '>0'): if template.name in self.templates.keys(): - return TemplateAction.AlreadyInstalled - return TemplateAction.NotApplicable + return TemplateAction.ALREADY_INSTALLED + return TemplateAction.NOT_APPLICABLE for current in self.templates.values(): if template.name != current.name: continue if template > current: - return TemplateAction.Upgradable + return TemplateAction.UPGRADABLE if template == current: - return TemplateAction.AlreadyInstalled + return TemplateAction.ALREADY_INSTALLED if current > template: - return TemplateAction.Downgradable + return TemplateAction.DOWNGRADABLE if any(template > current for current in self.templates.values()): - return TemplateAction.Upgradable - return TemplateAction.Installable + return TemplateAction.UPGRADABLE + return TemplateAction.INSTALLABLE def template_is_installed(self, query: BaseTemplate) -> bool: - return self.get_template_actions(query) == TemplateAction.AlreadyInstalled + return self.get_template_actions(query) == TemplateAction.ALREADY_INSTALLED def template_is_upgradeable(self, query: BaseTemplate) -> bool: - return self.get_template_actions(query) == TemplateAction.Upgradable + return self.get_template_actions(query) == TemplateAction.UPGRADABLE def template_is_applicable(self, query: BaseTemplate, force_apply: bool = False) -> bool: ui.logger(__name__).debug(query.target) return self.get_template_actions(query) in ( - TemplateAction.ForcedApplicable if force_apply else TemplateAction.UnforcedApplicable) + TemplateAction.FORCED_APPLICABLE if force_apply else TemplateAction.UNFORCED_APPLICABLE) def apply_template(self, template: LocalTemplate, force_system: bool = False, force_user: bool = False, remove_empty_directories: bool = False): diff --git a/pros/conductor/project/template_resolution.py b/pros/conductor/project/template_resolution.py index f9b9aeb0..62b14a50 100644 --- a/pros/conductor/project/template_resolution.py +++ b/pros/conductor/project/template_resolution.py @@ -2,14 +2,14 @@ class TemplateAction(Flag): - NotApplicable = auto() - Installable = auto() - Upgradable = auto() - AlreadyInstalled = auto() - Downgradable = auto() + NOT_APPLICABLE = auto() + INSTALLABLE = auto() + UPGRADABLE = auto() + ALREADY_INSTALLED = auto() + DOWNGRADABLE = auto() - UnforcedApplicable = Installable | Upgradable | Downgradable - ForcedApplicable = UnforcedApplicable | AlreadyInstalled + UNFORCED_APPLICABLE = INSTALLABLE | UPGRADABLE | DOWNGRADABLE + FORCED_APPLICABLE = UNFORCED_APPLICABLE | ALREADY_INSTALLED class InvalidTemplateException(Exception): diff --git a/pros/ga/analytics.py b/pros/ga/analytics.py index 209bf5c6..88b57902 100644 --- a/pros/ga/analytics.py +++ b/pros/ga/analytics.py @@ -3,8 +3,8 @@ import random from concurrent.futures import as_completed -url = 'https://www.google-analytics.com/collect' -agent = 'pros-cli' +URL = 'https://www.google-analytics.com/collect' +AGENT = 'pros-cli' """ PROS ANALYTICS CLASS @@ -25,23 +25,23 @@ def __init__(self): self.cli_config.save() self.sent = False #Variables that the class will use - self.gaID = self.cli_config.ga['ga_id'] - self.useAnalytics = self.cli_config.ga['enabled'] - self.uID = self.cli_config.ga['u_id'] - self.pendingRequests = [] + self.ga_id = self.cli_config.ga['ga_id'] + self.use_analytics = self.cli_config.ga['enabled'] + self.u_id = self.cli_config.ga['u_id'] + self.pending_requests = [] def send(self,action): - if not self.useAnalytics or self.sent: + if not self.use_analytics or self.sent: return self.sent=True # Prevent Send from being called multiple times try: #Payload to be sent to GA, idk what some of them are but it works payload = { 'v': 1, - 'tid': self.gaID, + 'tid': self.ga_id, 'aip': 1, 'z': random.random(), - 'cid': self.uID, + 'cid': self.u_id, 't': 'event', 'ec': 'action', 'ea': action, @@ -53,11 +53,11 @@ def send(self,action): session = FuturesSession() #Send payload to GA servers - future = session.post(url=url, + future = session.post(url=URL, data=payload, - headers={'User-Agent': agent}, + headers={'User-Agent': AGENT}, timeout=5.0) - self.pendingRequests.append(future) + self.pending_requests.append(future) except Exception: from pros.cli.common import logger @@ -65,13 +65,13 @@ def send(self,action): def set_use(self, value: bool): #Sets if GA is being used or not - self.useAnalytics = value - self.cli_config.ga['enabled'] = self.useAnalytics + self.use_analytics = value + self.cli_config.ga['enabled'] = self.use_analytics self.cli_config.save() def process_requests(self): responses = [] - for future in as_completed(self.pendingRequests): + for future in as_completed(self.pending_requests): try: response = future.result() @@ -85,7 +85,7 @@ def process_requests(self): print("Something went wrong while sending analytics!") - self.pendingRequests.clear() + self.pending_requests.clear() return responses diff --git a/pros/serial/devices/vex/v5_device.py b/pros/serial/devices/vex/v5_device.py index 68f59380..800c0d3e 100644 --- a/pros/serial/devices/vex/v5_device.py +++ b/pros/serial/devices/vex/v5_device.py @@ -28,7 +28,7 @@ from .vex_device import VEXDevice from ..system_device import SystemDevice -int_str = Union[int, str] +IntStr = Union[int, str] def find_v5_ports(p_type: str): @@ -353,7 +353,7 @@ def write_program(self, file: typing.BinaryIO, remote_name: str = None, ini: Con raise ValueError(f'Unknown quirk option: {quirk}') ui.finalize('upload', f'{finish_string} to V5') - def ensure_library_space(self, name: Optional[str] = None, vid: int_str = None, + def ensure_library_space(self, name: Optional[str] = None, vid: IntStr = None, target_name: Optional[str] = None): """ Uses algorithms, for loops, and if statements to determine what files should be removed @@ -467,7 +467,7 @@ def ensure_library_space(self, name: Optional[str] = None, vid: int_str = None, else: self.erase_file(file_name=file, erase_all=True, vid='user') - def upload_library(self, file: typing.BinaryIO, remote_name: str = None, file_len: int = -1, vid: int_str = 'pros', + def upload_library(self, file: typing.BinaryIO, remote_name: str = None, file_len: int = -1, vid: IntStr = 'pros', force_upload: bool = False, compress: bool = True, **kwargs): """ Upload a file used for linking. Contains the logic to check if the file is already present in the filesystem @@ -511,7 +511,7 @@ def upload_library(self, file: typing.BinaryIO, remote_name: str = None, file_le self.ensure_library_space(remote_name, vid, ) self.write_file(file, remote_name, file_len, vid=vid, **kwargs) - def read_file(self, file: typing.IO[bytes], remote_file: str, vid: int_str = 'user', target: int_str = 'flash', + def read_file(self, file: typing.IO[bytes], remote_file: str, vid: IntStr = 'user', target: IntStr = 'flash', addr: Optional[int] = None, file_len: Optional[int] = None): if isinstance(vid, str): vid = self.vid_map[vid.lower()] @@ -540,7 +540,7 @@ def read_file(self, file: typing.IO[bytes], remote_file: str, vid: int_str = 'us def write_file(self, file: typing.BinaryIO, remote_file: str, file_len: int = -1, run_after: FTCompleteOptions = FTCompleteOptions.DONT_RUN, linked_filename: Optional[str] = None, - linked_vid: int_str = 'pros', compress: bool = False, **kwargs): + linked_vid: IntStr = 'pros', compress: bool = False, **kwargs): if file_len < 0: file_len = file.seek(0, 2) file.seek(0, 0) @@ -630,7 +630,7 @@ def query_system_version(self) -> SystemVersion: return V5Device.SystemVersion(ret) @retries - def ft_transfer_channel(self, channel: int_str): + def ft_transfer_channel(self, channel: IntStr): logger(__name__).debug(f'Transferring to {channel} channel') logger(__name__).debug('Sending ext 0x10 command') if isinstance(channel, str): @@ -718,7 +718,7 @@ def ft_read(self, addr: int, n_bytes: int) -> bytearray: return ret @retries - def ft_set_link(self, link_name: str, vid: int_str = 'user', options: int = 0): + def ft_set_link(self, link_name: str, vid: IntStr = 'user', options: int = 0): logger(__name__).debug('Sending ext 0x15 command') if isinstance(vid, str): vid = self.vid_map[vid.lower()] @@ -731,7 +731,7 @@ def ft_set_link(self, link_name: str, vid: int_str = 'user', options: int = 0): return ret @retries - def get_dir_count(self, vid: int_str = 1, options: int = 0) \ + def get_dir_count(self, vid: IntStr = 1, options: int = 0) \ -> int: logger(__name__).debug('Sending ext 0x16 command') if isinstance(vid, str): @@ -755,7 +755,7 @@ def get_file_metadata_by_idx(self, file_idx: int, options: int = 0) \ return rx @retries - def execute_program_file(self, file_name: str, vid: int_str = 'user', run: bool = True): + def execute_program_file(self, file_name: str, vid: IntStr = 'user', run: bool = True): logger(__name__).debug('Sending ext 0x18 command') if isinstance(vid, str): vid = self.vid_map[vid.lower()] @@ -768,7 +768,7 @@ def execute_program_file(self, file_name: str, vid: int_str = 'user', run: bool return ret @retries - def get_file_metadata_by_name(self, file_name: str, vid: int_str = 1, options: int = 0) \ + def get_file_metadata_by_name(self, file_name: str, vid: IntStr = 1, options: int = 0) \ -> Dict[str, Any]: logger(__name__).debug('Sending ext 0x19 command') if isinstance(vid, str): @@ -811,7 +811,7 @@ def set_program_file_metadata(self, file_name: str, **kwargs): return ret @retries - def erase_file(self, file_name: str, erase_all: bool = False, vid: int_str = 'user'): + def erase_file(self, file_name: str, erase_all: bool = False, vid: IntStr = 'user'): logger(__name__).debug('Sending ext 0x1B command') if isinstance(vid, str): vid = self.vid_map[vid.lower()] diff --git a/pros/upgrade/manifests/upgrade_manifest_v2.py b/pros/upgrade/manifests/upgrade_manifest_v2.py index dfebbf0f..34b81a2f 100644 --- a/pros/upgrade/manifests/upgrade_manifest_v2.py +++ b/pros/upgrade/manifests/upgrade_manifest_v2.py @@ -8,12 +8,12 @@ class PlatformsV2(Enum): - Unknown = 0 - Windows86 = 1 - Windows64 = 2 - MacOS = 3 - Linux = 4 - Pip = 5 + UNKNOWN = 0 + WINDOWS86 = 1 + WINDOWS64 = 2 + MACOS = 3 + LINUX = 4 + PIP = 5 class UpgradeManifestV2(UpgradeManifestV1): @@ -34,7 +34,7 @@ def __init__(self): def platform(self) -> 'PlatformsV2': """ Attempts to detect the current platform type - :return: The detected platform type, or Unknown + :return: The detected platform type, or UNKNOWN """ if self._platform is not None: return self._platform @@ -43,22 +43,22 @@ def platform(self) -> 'PlatformsV2': frozen_platform = getattr(_constants, 'FROZEN_PLATFORM_V1', None) if isinstance(frozen_platform, str): if frozen_platform.startswith('Windows86'): - self._platform = PlatformsV2.Windows86 + self._platform = PlatformsV2.WINDOWS86 elif frozen_platform.startswith('Windows64'): - self._platform = PlatformsV2.Windows64 + self._platform = PlatformsV2.WINDOWS64 elif frozen_platform.startswith('MacOS'): - self._platform = PlatformsV2.MacOS + self._platform = PlatformsV2.MACOS else: try: from pip._vendor import pkg_resources # pylint: disable=not-an-iterable results = [p for p in pkg_resources.working_set if p.project_name.startswith('pros-cli')] if any(results): - self._platform = PlatformsV2.Pip + self._platform = PlatformsV2.PIP except ImportError: pass if not self._platform: - self._platform = PlatformsV2.Unknown + self._platform = PlatformsV2.UNKNOWN return self._platform @property diff --git a/pros/upgrade/upgrade_manager.py b/pros/upgrade/upgrade_manager.py index 93360a19..167b4a53 100644 --- a/pros/upgrade/upgrade_manager.py +++ b/pros/upgrade/upgrade_manager.py @@ -12,8 +12,8 @@ class ReleaseChannel(Enum): - Stable = 'stable' - Beta = 'beta' + STABLE = 'stable' + BETA = 'beta' class UpgradeManager(Config): @@ -22,7 +22,7 @@ def __init__(self, file=None): file = os.path.join(cli_config().directory, 'upgrade.pros.json') self._last_check: datetime = datetime.min self._manifest: Optional[UpgradeManifestV1] = None - self.release_channel: ReleaseChannel = ReleaseChannel.Stable + self.release_channel: ReleaseChannel = ReleaseChannel.STABLE super().__init__(file) diff --git a/version.py b/version.py index 39542079..9b9a6f0b 100644 --- a/version.py +++ b/version.py @@ -4,32 +4,32 @@ try: with open(os.devnull, 'w') as devnull: - v = subprocess.check_output(['git', 'describe', '--tags', '--dirty', '--abbrev'], stderr=stdout).decode().strip() - if '-' in v: - bv = v[:v.index('-')] - bv = bv[:bv.rindex('.') + 1] + str(int(bv[bv.rindex('.') + 1:]) + 1) - sempre = 'dirty' if v.endswith('-dirty') else 'commit' - pippre = 'alpha' if v.endswith('-dirty') else 'pre' - build = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip() - number_since = subprocess.check_output( - ['git', 'rev-list', v[:v.index('-')] + '..HEAD', '--count']).decode().strip() - semver = bv + '-' + sempre + '+' + build - pipver = bv + pippre + number_since - winver = v[:v.index('-')] + '.' + number_since + V = subprocess.check_output(['git', 'describe', '--tags', '--dirty', '--abbrev'], stderr=stdout).decode().strip() + if '-' in V: + BV = V[:V.index('-')] + BV = BV[:BV.rindex('.') + 1] + str(int(BV[BV.rindex('.') + 1:]) + 1) + SEMPRE = 'dirty' if V.endswith('-dirty') else 'commit' + PIPPRE = 'alpha' if V.endswith('-dirty') else 'pre' + BUILD = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip() + NUMBER_SINCE = subprocess.check_output( + ['git', 'rev-list', V[:V.index('-')] + '..HEAD', '--count']).decode().strip() + SEMVER = BV + '-' + SEMPRE + '+' + BUILD + PIPVER = BV + PIPPRE + NUMBER_SINCE + WINVER = V[:V.index('-')] + '.' + NUMBER_SINCE else: - semver = v - pipver = v - winver = v + '.0' + SEMVER = V + PIPVER = V + WINVER = V + '.0' with open('version', 'w') as f: - print('Semantic version is ' + semver) - f.write(semver) + print('Semantic version is ' + SEMVER) + f.write(SEMVER) with open('pip_version', 'w') as f: - print('PIP version is ' + pipver) - f.write(pipver) + print('PIP version is ' + PIPVER) + f.write(PIPVER) with open('win_version', 'w') as f: - print('Windows version is ' + winver) - f.write(winver) + print('Windows version is ' + WINVER) + f.write(WINVER) except Exception as e: print('Error calling git') print(e) From a23bbbfd18fb5f5e6624f8c91611a8d56aed8399 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:41:33 -0400 Subject: [PATCH 56/58] Fix C0103 -- modules --- .pylintrc | 3 +-- .../cli/compile_commands/{intercept-cc.py => intercept_cc.py} | 0 pros/cli/interactive.py | 4 ++-- pros/cli/test.py | 2 +- pros/common/ui/__init__.py | 2 +- .../ui/interactive/{ConfirmModal.py => confirm_modal.py} | 0 pros/common/ui/interactive/renderers/__init__.py | 2 +- .../{MachineOutputRenderer.py => machine_output_renderer.py} | 2 +- pros/conductor/interactive/__init__.py | 4 ++-- .../interactive/{NewProjectModal.py => new_project_modal.py} | 0 .../{UpdateProjectModal.py => update_project_modal.py} | 2 +- pros/conductor/project/__init__.py | 2 +- .../conductor/project/{ProjectReport.py => project_report.py} | 0 .../project/{ProjectTransaction.py => project_transaction.py} | 0 pros/serial/interactive/__init__.py | 2 +- .../{UploadProjectModal.py => upload_project_modal.py} | 0 16 files changed, 12 insertions(+), 13 deletions(-) rename pros/cli/compile_commands/{intercept-cc.py => intercept_cc.py} (100%) rename pros/common/ui/interactive/{ConfirmModal.py => confirm_modal.py} (100%) rename pros/common/ui/interactive/renderers/{MachineOutputRenderer.py => machine_output_renderer.py} (99%) rename pros/conductor/interactive/{NewProjectModal.py => new_project_modal.py} (100%) rename pros/conductor/interactive/{UpdateProjectModal.py => update_project_modal.py} (98%) rename pros/conductor/project/{ProjectReport.py => project_report.py} (100%) rename pros/conductor/project/{ProjectTransaction.py => project_transaction.py} (100%) rename pros/serial/interactive/{UploadProjectModal.py => upload_project_modal.py} (100%) diff --git a/.pylintrc b/.pylintrc index 2c3478bd..e9df67ae 100644 --- a/.pylintrc +++ b/.pylintrc @@ -15,7 +15,6 @@ # W0237: Renamed arguments # W0613: Unused argument # W0511: TODO -# C0103: Variable name doesn't conform to naming style # W1514: Using open without explicitly specifying an encoding # E1101: Nonexistent member # E0401: Unable to import @@ -56,7 +55,7 @@ max-line-length = 120 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, C0103, C0301, R0915, W1514, + R0912, R0911, W0511, R0902, C0412, C0301, R0915, W1514, E1101, W1201, E0401, W0212, R0904, W0101, C0302, W0603, R0401 diff --git a/pros/cli/compile_commands/intercept-cc.py b/pros/cli/compile_commands/intercept_cc.py similarity index 100% rename from pros/cli/compile_commands/intercept-cc.py rename to pros/cli/compile_commands/intercept_cc.py diff --git a/pros/cli/interactive.py b/pros/cli/interactive.py index 1fb3c09f..bc852ec6 100644 --- a/pros/cli/interactive.py +++ b/pros/cli/interactive.py @@ -20,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() @@ -30,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() diff --git a/pros/cli/test.py b/pros/cli/test.py index f19ac9a8..7608c53f 100644 --- a/pros/cli/test.py +++ b/pros/cli/test.py @@ -1,5 +1,5 @@ from pros.common.ui.interactive.renderers import MachineOutputRenderer -from pros.conductor.interactive.NewProjectModal import NewProjectModal +from pros.conductor.interactive.new_project_modal import NewProjectModal from .common import default_options, pros_root diff --git a/pros/common/ui/__init__.py b/pros/common/ui/__init__.py index 237a9ec0..1e55c982 100644 --- a/pros/common/ui/__init__.py +++ b/pros/common/ui/__init__.py @@ -39,7 +39,7 @@ def confirm(text: str, default: bool = False, abort: bool = False, prompt_suffix log: str = None): add_breadcrumb(message=text, category='confirm') if ismachineoutput(): - from pros.common.ui.interactive.ConfirmModal import ConfirmModal + from pros.common.ui.interactive.confirm_modal import ConfirmModal from pros.common.ui.interactive.renderers import MachineOutputRenderer app = ConfirmModal(text, abort, title, log) diff --git a/pros/common/ui/interactive/ConfirmModal.py b/pros/common/ui/interactive/confirm_modal.py similarity index 100% rename from pros/common/ui/interactive/ConfirmModal.py rename to pros/common/ui/interactive/confirm_modal.py diff --git a/pros/common/ui/interactive/renderers/__init__.py b/pros/common/ui/interactive/renderers/__init__.py index b032cb28..e759f9fe 100644 --- a/pros/common/ui/interactive/renderers/__init__.py +++ b/pros/common/ui/interactive/renderers/__init__.py @@ -1 +1 @@ -from .MachineOutputRenderer import MachineOutputRenderer +from .machine_output_renderer import MachineOutputRenderer diff --git a/pros/common/ui/interactive/renderers/MachineOutputRenderer.py b/pros/common/ui/interactive/renderers/machine_output_renderer.py similarity index 99% rename from pros/common/ui/interactive/renderers/MachineOutputRenderer.py rename to pros/common/ui/interactive/renderers/machine_output_renderer.py index 5ce856b1..a22cbe79 100644 --- a/pros/common/ui/interactive/renderers/MachineOutputRenderer.py +++ b/pros/common/ui/interactive/renderers/machine_output_renderer.py @@ -6,7 +6,7 @@ from pros.common import ui from pros.common.ui.interactive.observable import Observable -from .Renderer import Renderer +from .renderer import Renderer from ..application import Application current: List['MachineOutputRenderer'] = [] diff --git a/pros/conductor/interactive/__init__.py b/pros/conductor/interactive/__init__.py index 89f1e51c..c70e4700 100644 --- a/pros/conductor/interactive/__init__.py +++ b/pros/conductor/interactive/__init__.py @@ -1,4 +1,4 @@ -from .NewProjectModal import NewProjectModal -from .UpdateProjectModal import UpdateProjectModal +from .new_project_modal import NewProjectModal +from .update_project_modal import UpdateProjectModal from .parameters import ExistingProjectParameter, NonExistentProjectParameter diff --git a/pros/conductor/interactive/NewProjectModal.py b/pros/conductor/interactive/new_project_modal.py similarity index 100% rename from pros/conductor/interactive/NewProjectModal.py rename to pros/conductor/interactive/new_project_modal.py diff --git a/pros/conductor/interactive/UpdateProjectModal.py b/pros/conductor/interactive/update_project_modal.py similarity index 98% rename from pros/conductor/interactive/UpdateProjectModal.py rename to pros/conductor/interactive/update_project_modal.py index 5ba1665b..0feb2633 100644 --- a/pros/conductor/interactive/UpdateProjectModal.py +++ b/pros/conductor/interactive/update_project_modal.py @@ -7,7 +7,7 @@ from pros.common import ui from pros.common.ui.interactive import application, components, parameters from pros.conductor import BaseTemplate, Conductor, Project -from pros.conductor.project.ProjectTransaction import ProjectTransaction +from pros.conductor.project.project_transaction import ProjectTransaction from .components import TemplateListingComponent from .parameters import ExistingProjectParameter, TemplateParameter diff --git a/pros/conductor/project/__init__.py b/pros/conductor/project/__init__.py index b53a41f9..c6da6b94 100644 --- a/pros/conductor/project/__init__.py +++ b/pros/conductor/project/__init__.py @@ -11,7 +11,7 @@ from pros.common.ui import EchoPipe from pros.conductor.project.template_resolution import TemplateAction from pros.config.config import Config, ConfigNotFoundException -from .ProjectReport import ProjectReport +from .project_report import ProjectReport from ..templates import BaseTemplate, LocalTemplate, Template from ..transaction import Transaction diff --git a/pros/conductor/project/ProjectReport.py b/pros/conductor/project/project_report.py similarity index 100% rename from pros/conductor/project/ProjectReport.py rename to pros/conductor/project/project_report.py diff --git a/pros/conductor/project/ProjectTransaction.py b/pros/conductor/project/project_transaction.py similarity index 100% rename from pros/conductor/project/ProjectTransaction.py rename to pros/conductor/project/project_transaction.py diff --git a/pros/serial/interactive/__init__.py b/pros/serial/interactive/__init__.py index aa7f4062..18e769f4 100644 --- a/pros/serial/interactive/__init__.py +++ b/pros/serial/interactive/__init__.py @@ -1,3 +1,3 @@ -from .UploadProjectModal import UploadProjectModal +from .upload_project_modal import UploadProjectModal __all__ = ['UploadProjectModal'] diff --git a/pros/serial/interactive/UploadProjectModal.py b/pros/serial/interactive/upload_project_modal.py similarity index 100% rename from pros/serial/interactive/UploadProjectModal.py rename to pros/serial/interactive/upload_project_modal.py From f501518a42bb55df5dbee153b579908490b880f6 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:50:07 -0400 Subject: [PATCH 57/58] Fix case sensitive file rename --- pros/common/ui/interactive/renderers/{Renderer.py => renderer.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pros/common/ui/interactive/renderers/{Renderer.py => renderer.py} (100%) diff --git a/pros/common/ui/interactive/renderers/Renderer.py b/pros/common/ui/interactive/renderers/renderer.py similarity index 100% rename from pros/common/ui/interactive/renderers/Renderer.py rename to pros/common/ui/interactive/renderers/renderer.py From f27b927dd96012fd00e0dbbeddc4b980ff927fb2 Mon Sep 17 00:00:00 2001 From: Mayank Patibandla <34776435+mayankpatibandla@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:57:29 -0400 Subject: [PATCH 58/58] Fix interpret-cc in workflow --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 76145e6b..7c11183b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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