Skip to content

Commit

Permalink
Merge pull request #1 from nyu-software-engineering/test-lint
Browse files Browse the repository at this point in the history
Lint improvement
  • Loading branch information
bloombar authored Nov 25, 2023
2 parents f3eeb7b + 5852ddd commit b1ddc8e
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 37 deletions.
46 changes: 11 additions & 35 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,35 @@ name: check lint and format
on: [push, pull_request]

jobs:
lint-web-app:
lint-and-format:
runs-on: ubuntu-latest
strategy:
matrix:
# repeat same job for each subsystem in the following subdirectories
subdir: [web-app, machine-learning-client]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10" # update version(s) as needed
- name: Install dependencies
if: ${{ hashFiles('web-app/**/*.py') != '' }}
if: ${{ hashFiles(format('{0}/**/*.py', matrix.subdir)) != '' }}
run: |
cd web-app
cd ${{ matrix.subdir }}
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv sync --dev --python $(which python)
pipenv shell --fancy --python $(which python)
- name: Lint with pylint
if: ${{ hashFiles('web-app/**/*.py') != '' }}
if: ${{ hashFiles(format('{0}/**/*.py', matrix.subdir)) != '' }}
# you may set pylint to ignore any files or dependencies that make no sense to lint
run: |
cd web-app
cd ${{ matrix.subdir }}
pipenv run pylint **/*.py
- name: Format with black
if: ${{ hashFiles('web-app/**/*.py') != '' }}
if: ${{ hashFiles(format('{0}/**/*.py', matrix.subdir)) != '' }}
# you may set black to ignore any files or dependencies that make no sense to format
run: |
cd web-app
pipenv run black --diff --check .
lint-machine-learning-client:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10" # update version(s) as needed
- name: Install dependencies
if: ${{ hashFiles('machine-learning-client/**/*.py') != '' }}
run: |
cd machine-learning-client
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv sync --dev --python $(which python)
pipenv shell --fancy --python $(which python)
- name: Lint with pylint
if: ${{ hashFiles('machine-learning-client/**/*.py') != '' }}
# you may set pylint to ignore any files or dependencies that make no sense to lint
run: |
cd machine-learning-client
pipenv run pylint **/*.py
- name: Format with black
if: ${{ hashFiles('machine-learning-client/**/*.py') != '' }}
# you may set black to ignore any files or dependencies that make no sense to format
run: |
cd machine-learning-client
cd ${{ matrix.subdir }}
pipenv run black --diff --check .
4 changes: 2 additions & 2 deletions instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ All developers are expected to participate in reviewing and approving teammates'

### Code linting and formatting

A [GitHub Actions workflow script](./.github/workflows/lint.yml) is included in this repository that will automatically run the `pylint` linter and the `black` formatter to check the code in every pull request for its adherence to the proper code conventions. If the code does not pass such a check, the pull request must not be approved or merged.
A [GitHub Actions workflow script](./.github/workflows/lint.yml) is included in this repository that will automatically run the `pylint` linter and the `black` formatter in both the `web-app` and `machine-learning-client` subdirectories to check the code in every pull request for its adherence to the proper code conventions. If the code does not pass such a check, the pull request must not be approved or merged.

Due to its general-purpose design, and the fact that it checks all code the same way, regardless of whether that code is part of the web app, machine learning client, or other subsystem, **the given workflow script may not be appropriate for all projects**. You are welcome to modify it as necessary to suit your project's needs, as long as the spirit of the check remains the same.

For example, you may need to set up separate linting and formatting jobs for each subsystem and/or set the linter or formatter to ignore certain files or dependencies, e.g. using `pylint`'s `--ignore` or `--ignored-modules` flags or `black`'s `--exclude` flag. It is up to your team to research and implement any such changes.
For example, you may need to set up separate linting and formatting jobs for each subsystem and/or set the linter or formatter to ignore certain files or dependencies that are incapable of passing the linter/formatter checks for reasons outside the control of this project's developers, for example by using `pylint`'s `--ignore` or `--ignored-modules` flags or `black`'s `--exclude` flag. It is up to your team to research and implement any such changes.

## Documentation

Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions web-app/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pylint = "*"
black = "*"

[dev-packages]

[requires]
python_version = "3.10"
149 changes: 149 additions & 0 deletions web-app/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1ddc8e

Please sign in to comment.