Skip to content

Commit

Permalink
Add style checks to CI
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
  • Loading branch information
AyanSinhaMahapatra committed Dec 6, 2024
1 parent d2a7115 commit b467d2e
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 30 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI Documentation
name: CI Documentation and Code style

on: [push, pull_request]

Expand All @@ -21,7 +21,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: pip install -e .[docs]
run: ./configure --dev && ./configure --docs && source venv/bin/activate

- name: Check Sphinx Documentation build minimally
working-directory: ./docs
Expand All @@ -31,4 +31,5 @@ jobs:
working-directory: ./docs
run: ./scripts/doc8_style_check.sh


- name: Check for Code style errors
run: make check
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ valid: isort black

check:
@echo "-> Run pycodestyle (PEP8) validation"
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,migrations,settings.py,.cache .
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,scripts,tests,migrations,settings.py,.cache .
@echo "-> Run isort imports ordering validation"
@${ACTIVATE} isort --sl --check-only -l 100 setup.py src tests .
@${ACTIVATE} isort --sl -l 100 src tests setup.py --check-only
@echo "-> Run black validation"
@${ACTIVATE} black --check --check -l 100 src tests setup.py
@${ACTIVATE} black --check -l 100 src tests setup.py

clean:
@echo "-> Clean the Python env"
Expand Down
6 changes: 3 additions & 3 deletions etc/scripts/utils_thirdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def fetch_license_files(self, dest_dir=THIRDPARTY_DIR, use_cached_index=False):
if TRACE:
print(f"Fetched license from remote: {lic_url}")

except:
except Exception:
try:
# try licensedb second
lic_url = f"{LICENSEDB_API_URL}/{filename}"
Expand All @@ -867,7 +867,7 @@ def fetch_license_files(self, dest_dir=THIRDPARTY_DIR, use_cached_index=False):
if TRACE:
print(f"Fetched license from licensedb: {lic_url}")

except:
except Exception:
msg = f'No text for license {filename} in expression "{self.license_expression}" from {self}'
print(msg)
errors.append(msg)
Expand Down Expand Up @@ -1302,7 +1302,7 @@ def is_pure(self):
def is_pure_wheel(filename):
try:
return Wheel.from_filename(filename).is_pure()
except:
except Exception:
return False


Expand Down
4 changes: 1 addition & 3 deletions src/commoncode/cliutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import sys

import click

# FIXME: this is NOT API
from click._termui_impl import ProgressBar
from click._termui_impl import ProgressBar # FIXME: this is NOT API
from click.termui import style
from click.types import BoolParamType
from click.utils import echo
Expand Down
2 changes: 1 addition & 1 deletion src/commoncode/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def close_pipe(p):
# Ensure process death otherwise proc.wait may hang in some cases
# NB: this will run only on POSIX OSes supporting signals
os.kill(proc.pid, signal.SIGKILL) # NOQA
except:
except Exception:
pass

# This may slow things down a tad on non-POSIX Oses but is safe:
Expand Down
2 changes: 1 addition & 1 deletion src/commoncode/fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def load(location):
assert os.path.exists(fn) and os.path.isfile(fn), msg
mode = "r"
with open(fn, mode) as f:
return [l.strip() for l in f if l and l.strip()]
return [line.strip() for line in f if line and line.strip()]


def includes_excludes(patterns, message):
Expand Down
2 changes: 1 addition & 1 deletion src/commoncode/fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def _rm_handler(function, path, excinfo): # NOQA
elif function == os.remove:
try:
delete(path, _err_handler=None)
except:
except Exception:
pass

if os.path.exists(path):
Expand Down
5 changes: 2 additions & 3 deletions src/commoncode/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ def multi_checksums(location, checksum_names=("md5", "sha1", "sha256", "sha512",
mapping is guaranted to contains all the requested names as keys. If the location is not a file,
or if the file is empty, the values are None.
The purpose of this function is to return a set of checksums for a supported set of checksum
algorithms for a given location. This is an API function used in ScanCode --info plugin to get
checksum values.
The purpose of this function is to avoid read the same file multiple times
to compute different checksums.
"""
if not filetype.is_file(location):
return {name: None for name in checksum_names}
Expand Down
7 changes: 4 additions & 3 deletions src/commoncode/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ def _create_resources_from_paths(self, root, paths):
)
if not newpar:
raise Exception(
f"ERROR: Codebase._create_resources_from_paths: cannot create parent for: {parent_path!r}"
"ERROR: Codebase._create_resources_from_paths:"
f" cannot create parent for: {parent_path!r}"
)
parent = newpar

Expand Down Expand Up @@ -1686,7 +1687,7 @@ def _get_scan_data_helper(self, location):
"""
try:
return json.loads(location)
except:
except Exception:
location = abspath(normpath(expanduser(location)))
with open(location) as f:
scan_data = json.load(f)
Expand Down Expand Up @@ -1842,7 +1843,7 @@ def _populate(self, scan_data):
##########################################################
for attr_name in self.codebase_attributes:
value = scan_data.get(attr_name)
if value == None:
if not value:
continue
setattr(self.attributes, attr_name, value)

Expand Down
13 changes: 7 additions & 6 deletions src/commoncode/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ def has_case_sensitive_fs():
case sensitive by default, newer macOS use APFS which is no longer case
sensitive by default.
From https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/APFS_Guide/FAQ/FAQ.html
How does Apple File System handle filenames?
APFS accepts only valid UTF-8 encoded filenames for creation, and preserves
both case and normalization of the filename on disk in all variants. APFS,
like HFS+, is case-sensitive on iOS and is available in case-sensitive and
case-insensitive variants on macOS, with case-insensitive being the default.
From
https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/APFS_Guide/FAQ/FAQ.html
How does Apple File System handle filenames?
APFS accepts only valid UTF-8 encoded filenames for creation, and preserves
both case and normalization of the filename on disk in all variants. APFS,
like HFS+, is case-sensitive on iOS and is available in case-sensitive and
case-insensitive variants on macOS, with case-insensitive being the default.
"""
return not os.path.exists(__file__.upper())

Expand Down
2 changes: 1 addition & 1 deletion src/commoncode/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def lines(s):
splitlines.
"""
# FIXME: leverage new Pythin 3.8 scopeing rules
return [l.strip() for l in s.splitlines() if l.strip()]
return [line.strip() for line in s.splitlines() if line.strip()]


def foldcase(text):
Expand Down
2 changes: 1 addition & 1 deletion src/commoncode/timeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def tstamp2time(stamp):
# deal with optional microsec
try:
microsec = dt_ms[1]
except:
except Exception:
microsec = None
if microsec:
microsec = int(microsec)
Expand Down
3 changes: 2 additions & 1 deletion src/commoncode/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def get_nupkg_nv(filename):
"""
Return a NameVersion tuple parsed from the .nupkg NuGet archive `filename`.
For example (taken from https://stackoverflow.com/questions/51662737/regex-to-parse-package-name-and-version-number-from-nuget-package-filenames/51662926):
For example (taken from
https://stackoverflow.com/questions/51662737/regex-to-parse-package-name-and-version-number-from-nuget-package-filenames/51662926):
>>> get_nupkg_nv('knockoutjs.3.4.2.nupkg')
NameVersion(name='knockoutjs', version='3.4.2')
>>> get_nupkg_nv('log4net.2.0.8.nupkg')
Expand Down

0 comments on commit b467d2e

Please sign in to comment.