Skip to content

Commit

Permalink
Add PyCodeStyle (formaly pep8) checks to CI
Browse files Browse the repository at this point in the history
Add a config file
Make the required fixes

Signed-off-by: Ygal Blum <[email protected]>
  • Loading branch information
ygalblum committed Jan 14, 2024
1 parent 8e8cdf7 commit b649c9d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
59 changes: 59 additions & 0 deletions .github/workflows/pycodestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: PyCodeStyle
on:
- push
- pull_request
- workflow_call

jobs:
python-3:
name: PyCodeStyle
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install pylint
run: |
python -m pip install --upgrade pip
pip install pycodestyle
- name: Analysing the code with pylint
run: |
pycodestyle --config=./.pycodestyle .
python-2-7:
name: PyCodeStyle
runs-on: ubuntu-latest
container:
image: python:2.7.18-buster
strategy:
fail-fast: false
matrix:
python-version: ["2.7"]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pylint
run: |
python -m pip install --upgrade pip
pip install pycodestyle
- name: Analysing the code with pylint
run: |
pycodestyle --config=./.pycodestyle .
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
uses: redhat-cop/infra.lvm_snapshots/.github/workflows/ansible-lint.yml@main
pylint:
uses: redhat-cop/infra.lvm_snapshots/.github/workflows/pylint.yml@main
pycodestyle:
uses: redhat-cop/infra.lvm_snapshots/.github/workflows/pycodestyle.yml@main
shellcheck:
uses: redhat-cop/infra.lvm_snapshots/.github/workflows/shellcheck.yml@main
codespell:
Expand All @@ -19,6 +21,7 @@ jobs:
needs:
- ansible-lint
- pylint
- pycodestyle
- shellcheck
- codespell
runs-on: ubuntu-latest
Expand All @@ -27,6 +30,7 @@ jobs:
python -c "assert set([
'${{ needs.ansible-lint.result }}',
'${{ needs.pylint.result }}',
'${{ needs.pycodestyle.result }}',
'${{ needs.shellcheck.result }}',
'${{ needs.codespell.result }}',
]) == {'success'}"
Expand Down
2 changes: 2 additions & 0 deletions .pycodestyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pycodestyle]
max-line-length=120
6 changes: 5 additions & 1 deletion roles/snapshot_create/files/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
'ext4'
]


class CheckException(Exception):
""" Exception wrapper """


parser = argparse.ArgumentParser()
parser.add_argument('that', help='What should the script check', type=str, choices=['snapshots', 'resize'])
parser.add_argument('volumes', help='Volumes JSON array in a string', type=str)


def _main():
args = parser.parse_args()

Expand Down Expand Up @@ -157,7 +160,7 @@ def _calc_requested_size(group_info, volume):

def _get_volume_size(vol):
volume_info_str = subprocess.check_output(
[_LVS_COMMAND, "{vg}/{lv}".format(vg=vol['vg'],lv=vol['lv']), '-v', '--units', 'b', '--reportformat', 'json']
[_LVS_COMMAND, "{vg}/{lv}".format(vg=vol['vg'], lv=vol['lv']), '-v', '--units', 'b', '--reportformat', 'json']
)
volume_info_json = json.loads(volume_info_str)
volume_info = volume_info_json['report'][0]['lv'][0]
Expand Down Expand Up @@ -230,5 +233,6 @@ def _to_printable_volumes(volumes):
} for volume in volumes
}


if __name__ == '__main__':
_main()

0 comments on commit b649c9d

Please sign in to comment.