Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨🚨 Add pre-commit and Pylint #301

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
Expand All @@ -61,7 +61,7 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ jobs:
- uses: actions/[email protected]
with:
fetch-depth: 0

- name: Setup Python
uses: actions/[email protected]
with:
python-version: 3.9
cache: 'pip'
if: matrix.os != 'macos-latest'

- name: Setup Python MacOS
run: |
wget https://www.python.org/ftp/python/3.10.11/python-3.10.11-macos11.pkg
sudo installer -verbose -pkg ./python-3.10.11-macos11.pkg -target /
echo "/Library/Frameworks/Python.framework/Versions/3.10/bin" >> $GITHUB_PATH
if: matrix.os == 'macos-latest'

- name: Install Requirements
run: python3 -m pip install --upgrade pip && pip3 install wheel && pip3 install -r requirements.txt && pip3 uninstall -y typing

- name: Build Wheel
run: python3 setup.py bdist_wheel
if: matrix.os == 'ubuntu-latest'
Expand All @@ -61,7 +61,7 @@ jobs:
name: pros-cli-wheel-${{needs.update_build_number.outputs.output1}}
path: dist/*
if: matrix.os == 'ubuntu-latest'

- name: Run Pyinstaller
run: |
python3 version.py
Expand All @@ -80,7 +80,7 @@ jobs:
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
shell: bash
run: |
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Pylint

on:
pull_request:
push:

jobs:
Pylint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
steps:
- uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --rcfile=$(git ls-files '.pylintrc')
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: mixed-line-ending
args: [--fix=lf]
- id: end-of-file-fixer
- id: check-yaml
- id: check-vcs-permalinks
- id: check-merge-conflict
- id: check-case-conflict
- id: check-ast
- id: trailing-whitespace
- id: requirements-txt-fixer
- repo: local
hooks:
- id: pylint
name: pylint
entry: python -m pylint
language: system
types: [python]
args: [--rcfile=.pylintrc]
9 changes: 9 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[MASTER]

max-line-length = 120
disable = C0114, C0115, C0116, R0903, C0415, R1705, R0913, W1203, R1729, E1120, E1123, C0209, R1710, W0621, C0121,
W0614, W0401, W1202, C0117, W0718, R0205, R0402, R0914, R1725, R1735, C0411, W0237, W0702, W0223, W0613,
W0108, R0912, R0911, W0511, E1136, R0902, W0611, C0412, C0103, C0301, R1732, R0915, W1514, R1718, W1510,
E0602, W1309, C0325, E1101, R1714, R0916, W0719, R1734, E1133, W1201, W0107, W3101, W0640, C0201, W1113,
W0246, W0622, W0221, E1111, R1720, W0221, R1723, E0102, W0201, E0203, E0401, W0602, W0212, W0707, R0904,
W0101, C0302, E0110, W0603, R1701, W0106, R1721, W0601, R0401, W0612, W1406, C0303, R1731
2 changes: 1 addition & 1 deletion pip_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.0
3.5.0
2 changes: 1 addition & 1 deletion pros/cli/click_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ def invoke(self, *args, **kwargs):
if (isProject): #check if there is a project
curr_proj = p()
click.echo("PROS-Kernel Version: {}".format(curr_proj.kernel))
raise e
raise e
2 changes: 1 addition & 1 deletion pros/cli/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def callback(ctx: click.Context, param: click.Parameter, value: bool):
if value:
echo("Not sending analytics for this command.\n")
analytics.useAnalytics = False
pass
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__
Expand Down
6 changes: 3 additions & 3 deletions pros/cli/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def new_project(ctx: click.Context, path: str, target: str, version: str,
if version.lower() == 'latest' or not version:
version = '>0'
if not force_system and c.Project.find_project(path) is not None:
logger(__name__).error('A project already exists in this location at ' + c.Project.find_project(path) +
logger(__name__).error('A project already exists in this location at ' + c.Project.find_project(path) +
'! Delete it first. Are you creating a project in an existing one?', extra={'sentry': False})
ctx.exit(-1)
try:
Expand Down Expand Up @@ -315,7 +315,7 @@ def info_project(project: c.Project, ls_upgrades):

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
analytics.send("info-project")
analytics.send("info-project")
from pros.conductor.project import ProjectReport
report = ProjectReport(project)
_conductor = c.Conductor()
Expand Down Expand Up @@ -385,7 +385,7 @@ def reset(force: bool):
if not ui.confirm("This will remove all depots and templates. You will be unable to create a new PROS project if you do not have internet connection. Are you sure you want to continue?"):
ui.echo("Aborting")
return

# Delete conductor.pros
file = os.path.join(click.get_app_dir('PROS'), 'conductor.pros')
if os.path.exists(file):
Expand Down
4 changes: 2 additions & 2 deletions pros/cli/misc_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ 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

analytics.send("upgrade")
from pros.upgrade import UpgradeManager
manager = UpgradeManager()
Expand Down
4 changes: 2 additions & 2 deletions pros/cli/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def terminal(port: str, backend: str, **kwargs):
may be preferred when "share" doesn't perform adequately.

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
Expand Down Expand Up @@ -91,7 +91,7 @@ def __init__(self, file):
self.log = open(file, 'a')
def write(self, data):
self.terminal.write(data)
self.log.write(data)
self.log.write(data)
def flush(self):
pass
def end(self):
Expand Down
14 changes: 7 additions & 7 deletions pros/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def upload_cli():
cls=PROSDeprecated, replacement='after')
@click.option('--run-screen/--execute', 'run_screen', default=None, help='Display run program screen on the brain after upload.',
cls=PROSDeprecated, replacement='after')
@click.option('-af', '--after', type=click.Choice(['run','screen','none']), default=None, help='Action to perform on the brain after upload.',
@click.option('-af', '--after', type=click.Choice(['run','screen','none']), default=None, help='Action to perform on the brain after upload.',
cls=PROSOption, group='V5 Options')
@click.option('--quirk', type=int, default=0)
@click.option('--name', 'remote_name', type=str, default=None, required=False, help='Remote program name.',
Expand All @@ -37,9 +37,9 @@ def upload_cli():
cls=PROSOption, group='V5 Options', hidden=True)
@click.option('--compress-bin/--no-compress-bin', 'compress_bin', cls=PROSOption, group='V5 Options', default=True,
help='Compress the program binary before uploading.')
@click.option('--description', default="Made with PROS", type=str, cls=PROSOption, group='V5 Options',
@click.option('--description', default="Made with PROS", type=str, cls=PROSOption, group='V5 Options',
help='Change the description displayed for the program.')
@click.option('--name', default=None, type=str, cls=PROSOption, group='V5 Options',
@click.option('--name', default=None, type=str, cls=PROSOption, group='V5 Options',
help='Change the name of the program.')

@default_options
Expand Down Expand Up @@ -119,12 +119,12 @@ def upload(path: Optional[str], project: Optional[c.Project], port: str, **kwarg
kwargs['remote_name'] = os.path.splitext(os.path.basename(path))[0]
kwargs['remote_name'] = kwargs['remote_name'].replace('@', '_')
kwargs['slot'] -= 1

action_to_kwarg = {
'run' : vex.V5Device.FTCompleteOptions.RUN_IMMEDIATELY,
'screen' : vex.V5Device.FTCompleteOptions.RUN_SCREEN,
'run' : vex.V5Device.FTCompleteOptions.RUN_IMMEDIATELY,
'screen' : vex.V5Device.FTCompleteOptions.RUN_SCREEN,
'none' : vex.V5Device.FTCompleteOptions.DONT_RUN
}
}
after_upload_default = 'screen'
#Determine which FTCompleteOption to assign to run_after
if kwargs['after']==None:
Expand Down
2 changes: 1 addition & 1 deletion pros/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_version():
module = pros.cli.main.__name__
for dist in pkg_resources.working_set:
scripts = dist.get_entry_map().get('console_scripts') or {}
for script_name, entry_point in iter(scripts.items()):
for _, entry_point in iter(scripts.items()):
if entry_point.module_name == module:
ver = dist.version
if ver is not None:
Expand Down
18 changes: 9 additions & 9 deletions pros/conductor/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def is_pathname_valid(pathname: str) -> bool:
try:
if not isinstance(pathname, str) or not pathname:
return False

_, pathname = os.path.splitdrive(pathname)

root_dirname = os.environ.get('HOMEDRIVE', 'C:') \
if sys.platform == 'win32' else os.path.sep
assert os.path.isdir(root_dirname)

root_dirname = root_dirname.rstrip(os.path.sep) + os.path.sep
for pathname_part in pathname.split(os.path.sep):
try:
Expand All @@ -55,7 +55,7 @@ def is_pathname_valid(pathname: str) -> bool:
return False
elif exc.errno in {errno.ENAMETOOLONG, errno.ERANGE}:
return False

# Check for emojis
# https://stackoverflow.com/a/62898106/11177720
ranges = [
Expand Down Expand Up @@ -225,7 +225,7 @@ def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online:
if len(results) == 0 and not use_early_access:
raise dont_send(
InvalidTemplateException(f'{identifier.name} does not support kernel version {kernel_version}'))

return list(results)

def resolve_template(self, identifier: Union[str, BaseTemplate], **kwargs) -> Optional[BaseTemplate]:
Expand Down Expand Up @@ -312,7 +312,7 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate],
kwargs['early_access'] = True
# Recall the function with early access enabled
return self.apply_template(project, identifier, **kwargs)

self.save()
if not isinstance(template, LocalTemplate):
with ui.Notification():
Expand Down Expand Up @@ -377,10 +377,10 @@ def new_project(self, path: str, no_default_libs: bool = False, **kwargs) -> Pro

if not is_pathname_valid(str(Path(path).absolute())):
raise dont_send(ValueError('Project path contains invalid characters.'))

if Path(path).exists() and Path(path).samefile(os.path.expanduser('~')):
raise dont_send(ValueError('Will not create a project in user home directory'))

proj = Project(path=path, create=True, early_access=use_early_access)
if 'target' in kwargs:
proj.target = kwargs['target']
Expand Down Expand Up @@ -413,6 +413,6 @@ def add_depot(self, name: str, url: str):
def remove_depot(self, name: str):
del self.depots[name]
self.save()

def query_depots(self, url: bool):
return [name + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()]
8 changes: 4 additions & 4 deletions pros/conductor/depots.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ pros conduct add-depot test "https://pros.cs.purdue.edu/v5/_static/beta/testin
`pros conduct remove-depot <name-of-your-depot>`

Example:
```bash
```bash
$ pros conduct remove-depot test
> Removed depot test
```
Expand All @@ -28,11 +28,11 @@ Examples:
```bash
$ pros conduct query-depots --url
> Available Depots:
>
>
> kernel-beta-mainline -- https://raw.githubusercontent.com/purduesigbots/pros-mainline/master/beta/kernel-beta-mainline.json
> pros-mainline -- https://purduesigbots.github.io/pros-mainline/pros-mainline.json
> test -- https://pros.cs.purdue.edu/v5/_static/beta/testing-mainline.json
>
>
```
```bash
$ pros conduct query-depots
Expand All @@ -41,5 +41,5 @@ $ pros conduct query-depots
> kernel-beta-mainline
> pros-mainline
> test
>
>
```
1 change: 0 additions & 1 deletion pros/conductor/project/ProjectTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def execute(self, conductor: c.Conductor, project: c.Project):
raise e
else:
ui.logger(__name__).warning(str(e))
return None

def describe(self, conductor: c.Conductor, project: c.Project):
action = project.get_template_actions(conductor.resolve_template(self.template))
Expand Down
4 changes: 2 additions & 2 deletions pros/conductor/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def libscanbuild_capture(args: argparse.Namespace) -> Tuple[int, Iterable[Compil
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__).error(f"ERROR WHILE CALLING '{make_cmd}' WITH EXCEPTION: {str(e)}\n",extra={'sentry':False})
if not suppress_output:
if not suppress_output:
pipe.close()
sys.exit()
if not suppress_output:
Expand Down Expand Up @@ -412,7 +412,7 @@ def find_project(path: str, recurse_times: int = 10):
if os.path.isfile(path):
path = os.path.dirname(path)
if os.path.isdir(path):
for n in range(recurse_times):
for _ in range(recurse_times):
if path is not None and os.path.isdir(path):
files = [f for f in os.listdir(path)
if os.path.isfile(os.path.join(path, f)) and f.lower() == 'project.pros']
Expand Down
Loading
Loading