Skip to content

Commit

Permalink
Add Flake8, Pydocstyle and Black in CI workflows (#209)
Browse files Browse the repository at this point in the history
* Add flake8, black and pycodestyle in workflow

* reordered the steps

* fix bug

* Update GitHub workflows for pushes to include linting and formatting checks

* fix invalid job id

* Corrected flake command

* Add suggested files

* Fix linting and formatting errors

* Update ignore flags in Flake8 Linter job

* fix flake8 command

* Fix formating and linting errors

* fix spelling mistake

* Fixed errors

* added error code

* fix error

* fixed failing test case

* Refactor docstrings and comments in test packages

---------

Co-authored-by: im-vedant <194vedantgutpa@gmail.com>
  • Loading branch information
im-vedant and im-vedant authored Jan 6, 2025
1 parent aeb7e55 commit bac3ee0
Show file tree
Hide file tree
Showing 59 changed files with 450 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
ignore = E402,E722,E203,F401
max-line-length = 80
26 changes: 26 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ jobs:
echo "Error: Source and Target Branches are the same. Please ensure they are different."
echo "Error: Close this PR and try again."
exit 1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black pydocstyle
- name: Run Black Formatter Check
run: |
black --check .
- name: Run Flake8 Linter
run: |
flake8 switchmap bin setup --ignore E402,E722,E203,F401
- name: Run pydocstyle
run: |
pydocstyle switchmap setup bin tests --convention=google --add-ignore=D415,D205
Check-Sensitive-Files:
if: ${{ github.actor != 'dependabot[bot]' && !contains(github.event.pull_request.labels.*.name, 'ignore-sensitive-files-pr') }}
Expand Down Expand Up @@ -70,11 +92,15 @@ jobs:
.gitignore
CODEOWNERS
LICENSE
.pydocstyle
pyproject.toml
.flake8
requirements.txt
CNAME
yaml.lock
package.json
package-lock.json
- name: List all changed unauthorized files
if: steps.changed-unauth-files.outputs.any_changed == 'true' || steps.changed-unauth-files.outputs.any_deleted == 'true'
env:
Expand Down
35 changes: 33 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
##############################################################################
##############################################################################
#
# PR Workflow
# Push Workflow
#
##############################################################################
##############################################################################

name: PR Workflow
name: Push Workflow

on:
push:
Expand Down Expand Up @@ -72,3 +72,34 @@ jobs:
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

Linting-and-Formatting:
name: Linting and Formatting Checks
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install Linting and Formatting Tools
run: |
python -m pip install --upgrade pip
pip install flake8 black pydocstyle
- name: Run Flake8 Linter
run: |
flake8 . --ignore E402,E722,E203,F401
- name: Run Black Formatter Check
run: |
black --check .
- name: Run Pydocstyle for Docstring Style
run: |
pydocstyle switchmap setup bin tests --convention=google --add-ignore=D415,D205
3 changes: 3 additions & 0 deletions .pydocstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pydocstyle]
convention=google
add-ignore=D415,D205
2 changes: 1 addition & 1 deletion bin/tools/switchmap_ingester_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Switchmap-NG ingest test script"""
"""Switchmap-NG ingest test script."""

# Standard libraries
import sys
Expand Down
2 changes: 1 addition & 1 deletion bin/tools/switchmap_poller_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Switchmap-NG polling test script"""
"""Switchmap-NG polling test script."""

# Standard libraries
import sys
Expand Down
7 changes: 6 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ mock
pytest

# Other
more-itertools
more-itertools

#Linting and formatting
flake8
pydocstyle
black
9 changes: 9 additions & 0 deletions switchmap/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.core package.
Args:
None
Returns:
None
"""
1 change: 0 additions & 1 deletion switchmap/core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ def __init__(self, app, parent, options=None):
"""Initialize the class.
Args:
app: Flask application object of type Flask(__name__)
parent: Name of parent process that is invoking the API
options: Gunicorn CLI options
Expand Down
9 changes: 4 additions & 5 deletions switchmap/core/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def run(self):


class GracefulDaemon(Daemon):
"""Daemon that allows for graceful shutdown
"""Daemon that allows for graceful shutdown.
This daemon should allow for stop/restart commands to perform graceful
shutdown of a given process. A graceful shutdown involves checking that
Expand All @@ -327,7 +327,7 @@ def __init__(self, agent, timeout=30):
Daemon.__init__(self, agent)

def __daemon_running(self):
"""Determines if daemon is processing data
"""Determines if daemon is processing data.
Daemon is running based on whether it has an associated lockfile
Expand All @@ -346,8 +346,7 @@ def __daemon_running(self):
return running

def graceful_shutdown(self, callback):
"""Wrapper class that handles graceful_shutdown prior to using
callaback function `fn`
"""Initializes the wrapper with the callback function `fn`.
Args:
callback: callback method
Expand All @@ -358,7 +357,7 @@ def graceful_shutdown(self, callback):
"""

def wrapper():
"""Wrapper function"""
"""Wrapper function."""
if self.__daemon_running():
log_message = """\
Lock file {} exists. Process still running.""".format(
Expand Down
9 changes: 9 additions & 0 deletions switchmap/dashboard/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.dashboard.data package.
Args:
None
Returns:
None
"""
2 changes: 0 additions & 2 deletions switchmap/dashboard/data/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def macips(self):
None
Returns:
result: List of MacIpState objects
"""
Expand Down Expand Up @@ -174,7 +173,6 @@ def macips(interface):
None
Returns:
result: List of MacIpState objects
"""
Expand Down
9 changes: 9 additions & 0 deletions switchmap/dashboard/net/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.dashboard.net package.
Args:
None
Returns:
None
"""
9 changes: 9 additions & 0 deletions switchmap/dashboard/net/html/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.dashboard.net.html package.
Args:
None
Returns:
None
"""
9 changes: 9 additions & 0 deletions switchmap/dashboard/net/html/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.dashboard.net.html.pages package.
Args:
None
Returns:
None
"""
9 changes: 9 additions & 0 deletions switchmap/dashboard/net/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.dashboard.net.routes package.
Args:
None
Returns:
None
"""
9 changes: 9 additions & 0 deletions switchmap/dashboard/net/routes/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.dashboard.net.routes.api package.
Args:
None
Returns:
None
"""
9 changes: 9 additions & 0 deletions switchmap/dashboard/net/routes/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.dashboard.net.routes.pages package.
Args:
None
Returns:
None
"""
9 changes: 9 additions & 0 deletions switchmap/dashboard/table/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.dashboard.table package.
Args:
None
Returns:
None
"""
2 changes: 1 addition & 1 deletion switchmap/dashboard/table/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def enabled(self):


def table(_interfaces):
"""Get Interface data from the device
"""Get Interface data from the device.
Args:
_interfaces: Interface dict
Expand Down
10 changes: 10 additions & 0 deletions switchmap/poller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""Define the switchmap.poller package.
Args:
None
Returns:
None
"""

from collections import namedtuple

SNMP = namedtuple(
Expand Down
9 changes: 9 additions & 0 deletions switchmap/poller/snmp/mib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.poller.snmp.mib package.
Args:
None
Returns:
None
"""
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def layer1(self):
return final

def cviroutedvlanifindex(self, oidonly=False):
"""Return dict of CISCO-VLAN-IFTABLE-RELATIONSHIP-MIB
cviRoutedVlanIfIndex for each VLAN.
"""Return dictionary of CISCO-VLAN-IFTABLE-RELATIONSHIP-MIB
cviRoutedVlanIfIndex for each VLAN.
Args:
oidonly: Return OID's value, not results, if True
Expand Down
9 changes: 9 additions & 0 deletions switchmap/poller/snmp/mib/generic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Define the switchmap.poller.snmp.mib.generic package.
Args:
None
Returns:
None
"""
6 changes: 4 additions & 2 deletions switchmap/poller/snmp/mib/generic/mib_if_64.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def ifhcinmulticastpkts(self, oidonly=False):
return data_dict

def ifhcoutmulticastpkts(self, oidonly=False):
"""Return dict of IFMIB ifHCOutMulticastPkts for each ifIndex for device.
"""Return dict of IFMIB ifHCOutMulticastPkts for each ifIndex for
device.
Args:
oidonly: Return OID's value, not results, if True
Expand Down Expand Up @@ -290,7 +291,8 @@ def ifhcinbroadcastpkts(self, oidonly=False):
return data_dict

def ifhcoutbroadcastpkts(self, oidonly=False):
"""Return dict of IFMIB ifHCOutBroadcastPkts for each ifIndex for device.
"""Return dict of IFMIB ifHCOutBroadcastPkts for each ifIndex for
device.
Args:
oidonly: Return OID's value, not results, if True
Expand Down
1 change: 0 additions & 1 deletion switchmap/poller/snmp/mib/generic/mib_ipv6.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Class interacts with CISCO-IETF-IP-MIB."""

from collections import defaultdict
import binascii

from switchmap.poller.snmp.base_query import Query
from switchmap.core import general
Expand Down
2 changes: 0 additions & 2 deletions switchmap/poller/snmp/snmp_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class Query:
Returns:
None
Methods:
"""

def __init__(self, snmp_object):
Expand Down
10 changes: 10 additions & 0 deletions switchmap/poller/update/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""Define the switchmap.poller.update package.
Args:
None
Returns:
None
"""

from collections import namedtuple

TrunkInterface = namedtuple("TrunkInterface", "vlan nativevlan trunk ")
Loading

0 comments on commit bac3ee0

Please sign in to comment.