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 auto formatter #325

Draft
wants to merge 49 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9578627
Add pre-commit and disable most warnings
mayankpatibandla Oct 18, 2023
141f50b
Fix whitespace
mayankpatibandla Oct 18, 2023
63b2dbe
Sort alphabetically
mayankpatibandla Oct 18, 2023
f015da3
Fixed some errors
mayankpatibandla Oct 18, 2023
491f4e6
Add pre-commit and pylint
mayankpatibandla Oct 25, 2023
a943805
Add pylint to github actions
mayankpatibandla Oct 25, 2023
9346d25
Add rcfile
mayankpatibandla Oct 25, 2023
adf167e
Merge branch 'pre-commit' into pylint-ci
mayankpatibandla Oct 25, 2023
f251a16
Disable cyclic import
mayankpatibandla Oct 25, 2023
c01517b
Merge branch 'develop' into pylint-ci
mayankpatibandla Jan 22, 2024
682a491
Add pre-commit and pylint
mayankpatibandla Jan 22, 2024
5eaccfb
Fix whitespace
mayankpatibandla Jan 22, 2024
29570d1
Readd removed requirements
mayankpatibandla Jan 22, 2024
9d807fd
Merge remote-tracking branch 'origin/develop' into pylint-ci
mayankpatibandla Feb 2, 2024
a0e62e2
Add black formatter
mayankpatibandla Feb 2, 2024
7819ea6
Run black
mayankpatibandla Feb 2, 2024
d13ceee
Add isort
mayankpatibandla Feb 2, 2024
10c8f8d
Run isort
mayankpatibandla Feb 2, 2024
6e284f2
Add pre-commit to CI
mayankpatibandla Feb 2, 2024
340d037
Skip pylint
mayankpatibandla Feb 2, 2024
986af1f
Use environment variable to skip pylint
mayankpatibandla Feb 2, 2024
baa5f17
Remove redundant skip
mayankpatibandla Feb 2, 2024
c57fd3c
Add pre-commit action
mayankpatibandla Feb 2, 2024
975e51f
Move pylint action to separate file
mayankpatibandla Feb 2, 2024
7c70259
Merge branch 'pylint-ci' into auto-formatter
mayankpatibandla Feb 2, 2024
dd23c0f
Normalize strings
mayankpatibandla Feb 2, 2024
ea4aab7
Update black
mayankpatibandla Feb 20, 2024
b1fa6d3
Add formatter actions
mayankpatibandla Feb 20, 2024
4a201e7
Spelling
mayankpatibandla Feb 20, 2024
b878ca0
Testing action
mayankpatibandla Feb 20, 2024
8cc43ad
Testing action
mayankpatibandla Feb 20, 2024
90e847d
Testing action
mayankpatibandla Feb 20, 2024
7573f59
Testing action
mayankpatibandla Feb 20, 2024
846f556
Fix action
mayankpatibandla Feb 20, 2024
bf7c3fb
Add auto commit
mayankpatibandla Feb 21, 2024
68581bc
Testing action
mayankpatibandla Feb 21, 2024
b714982
Testing action
mayankpatibandla Feb 21, 2024
f1a794c
Run black
mayankpatibandla Feb 21, 2024
004ca6b
Run synchronously
mayankpatibandla Feb 21, 2024
0c9c796
Format code with isort and black
mayankpatibandla Feb 21, 2024
6b72a7a
Testing action
mayankpatibandla Feb 21, 2024
e54887f
Testing action
mayankpatibandla Feb 21, 2024
3cb2f74
Consolidate
mayankpatibandla Feb 21, 2024
d378bef
Format code with isort and black
mayankpatibandla Feb 21, 2024
4b2db8b
Update black
mayankpatibandla Mar 19, 2024
5b80149
Update black in workflow
mayankpatibandla Mar 19, 2024
e4383ee
Merge branch 'develop' into auto-formatter
mayankpatibandla Mar 19, 2024
b5ee8a4
Formatter
mayankpatibandla Mar 19, 2024
30a68e2
Disable R1731 and W0612
mayankpatibandla Mar 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
54 changes: 54 additions & 0 deletions .github/workflows/lint-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Formatter

on:
pull_request:
push:

env:
SKIP: pylint,isort,black

jobs:
Formatter:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4.1.1
with:
ref: ${{ github.head_ref }}
- uses: isort/isort-action@v1.1.0
with:
configuration: "--settings-file=.isort.cfg"
requirements-files: "requirements.txt"
- uses: psf/black@stable
with:
options: "--line-length=120"
version: "24.3.0"
- uses: stefanzweifel/git-auto-commit-action@v5.0.0
with:
commit_message: "Format code with isort and black"
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.1
- uses: actions/setup-python@v5.0.0
- uses: pre-commit/action@v3.0.0
Pylint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4.1.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5.0.0
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')
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/checkout@v3.1.0
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4.3.0
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
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]

line_length = 120

profile = black
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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: https://github.com/pycqa/isort
rev: "5.13.2"
hooks:
- id: isort
name: isort
types: [python]
args: [--settings-file=.isort.cfg]
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
args: ["--line-length=120"]
- 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, R1731, W0612
2 changes: 1 addition & 1 deletion install_requires.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
with open('requirements.txt') as reqs:
with open("requirements.txt") as reqs:
install_requires = [req.strip() for req in reqs.readlines()]
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
51 changes: 28 additions & 23 deletions pros/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import click

import pros.conductor as c
from pros.ga.analytics import analytics
from pros.cli.common import default_options, logger, project_option, pros_root, shadow_command
from pros.ga.analytics import analytics

from .upload import upload


Expand All @@ -15,9 +16,9 @@ def build_cli():
pass


@build_cli.command(aliases=['build','m'])
@build_cli.command(aliases=["build", "m"])
@project_option()
@click.argument('build-args', nargs=-1)
@click.argument("build-args", nargs=-1)
@default_options
def make(project: c.Project, build_args):
"""
Expand All @@ -26,17 +27,17 @@ def make(project: c.Project, build_args):
analytics.send("make")
exit_code = project.compile(build_args)
if exit_code != 0:
if sys.platform == 'win32':
if sys.platform == "win32":
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)

logger(__name__).error(f'Failed to make project: Exit Code {exit_code}', extra={'sentry': False})
raise click.ClickException('Failed to build')
logger(__name__).error(f"Failed to make project: Exit Code {exit_code}", extra={"sentry": False})
raise click.ClickException("Failed to build")
return exit_code


@build_cli.command('make-upload', aliases=['mu'], hidden=True)
@click.option('build_args', '--make', '-m', multiple=True, help='Send arguments to make (e.g. compile target)')
@build_cli.command("make-upload", aliases=["mu"], hidden=True)
@click.option("build_args", "--make", "-m", multiple=True, help="Send arguments to make (e.g. compile target)")
@shadow_command(upload)
@project_option()
@click.pass_context
Expand All @@ -46,41 +47,45 @@ def make_upload(ctx, project: c.Project, build_args: List[str], **upload_args):
ctx.invoke(upload, project=project, **upload_args)


@build_cli.command('make-upload-terminal', aliases=['mut'], hidden=True)
@click.option('build_args', '--make', '-m', multiple=True, help='Send arguments to make (e.g. compile target)')
@build_cli.command("make-upload-terminal", aliases=["mut"], hidden=True)
@click.option("build_args", "--make", "-m", multiple=True, help="Send arguments to make (e.g. compile target)")
@shadow_command(upload)
@project_option()
@click.pass_context
def make_upload_terminal(ctx, project: c.Project, build_args, **upload_args):
analytics.send("make-upload-terminal")
from .terminal import terminal

ctx.invoke(make, project=project, build_args=build_args)
ctx.invoke(upload, project=project, **upload_args)
ctx.invoke(terminal, port=project.target, request_banner=False)


@build_cli.command('build-compile-commands', hidden=True)
@build_cli.command("build-compile-commands", hidden=True)
@project_option()
@click.option('--suppress-output/--show-output', 'suppress_output', default=False, show_default=True,
help='Suppress output')
@click.option('--compile-commands', type=click.File('w'), default=None)
@click.option('--sandbox', default=False, is_flag=True)
@click.argument('build-args', nargs=-1)
@click.option(
"--suppress-output/--show-output", "suppress_output", default=False, show_default=True, help="Suppress output"
)
@click.option("--compile-commands", type=click.File("w"), default=None)
@click.option("--sandbox", default=False, is_flag=True)
@click.argument("build-args", nargs=-1)
@default_options
def build_compile_commands(project: c.Project, suppress_output: bool, compile_commands, sandbox: bool,
build_args: List[str]):
def build_compile_commands(
project: c.Project, suppress_output: bool, compile_commands, sandbox: bool, build_args: List[str]
):
"""
Build a compile_commands.json compatible with cquery
:return:
"""
analytics.send("build-compile-commands")
exit_code = project.make_scan_build(build_args, cdb_file=compile_commands, suppress_output=suppress_output,
sandbox=sandbox)
exit_code = project.make_scan_build(
build_args, cdb_file=compile_commands, suppress_output=suppress_output, sandbox=sandbox
)
if exit_code != 0:
if sys.platform == 'win32':
if sys.platform == "win32":
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)

logger(__name__).error(f'Failed to make project: Exit Code {exit_code}', extra={'sentry': False})
raise click.ClickException('Failed to build')
logger(__name__).error(f"Failed to make project: Exit Code {exit_code}", extra={"sentry": False})
raise click.ClickException("Failed to build")
return exit_code
Loading
Loading