Skip to content

Commit 359f72b

Browse files
Add style checks to CI
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent d2a7115 commit 359f72b

File tree

13 files changed

+39
-30
lines changed

13 files changed

+39
-30
lines changed

.github/workflows/docs-ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Documentation
1+
name: CI Documentation and Code style
22

33
on: [push, pull_request]
44

@@ -21,7 +21,7 @@ jobs:
2121
python-version: ${{ matrix.python-version }}
2222

2323
- name: Install Dependencies
24-
run: pip install -e .[docs]
24+
run: pip install -e .[docs,testing]
2525

2626
- name: Check Sphinx Documentation build minimally
2727
working-directory: ./docs
@@ -31,4 +31,5 @@ jobs:
3131
working-directory: ./docs
3232
run: ./scripts/doc8_style_check.sh
3333

34-
34+
- name: Check for Code style errors
35+
run: make check-ci

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ valid: isort black
3333

3434
check:
3535
@echo "-> Run pycodestyle (PEP8) validation"
36-
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,migrations,settings.py,.cache .
36+
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,scripts,tests,migrations,settings.py,.cache .
3737
@echo "-> Run isort imports ordering validation"
38-
@${ACTIVATE} isort --sl --check-only -l 100 setup.py src tests .
38+
@${ACTIVATE} isort --sl -l 100 src tests setup.py --check-only
3939
@echo "-> Run black validation"
40-
@${ACTIVATE} black --check --check -l 100 src tests setup.py
40+
@${ACTIVATE} black --check -l 100 src tests setup.py
41+
42+
check-ci:
43+
@echo "-> Run pycodestyle (PEP8) validation"
44+
pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,scripts,tests,migrations,settings.py,.cache .
45+
@echo "-> Run isort imports ordering validation"
46+
isort --sl -l 100 src tests setup.py --check-only
47+
@echo "-> Run black validation"
48+
black --check -l 100 src tests setup.py
4149

4250
clean:
4351
@echo "-> Clean the Python env"

etc/scripts/utils_thirdparty.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ def fetch_license_files(self, dest_dir=THIRDPARTY_DIR, use_cached_index=False):
854854
if TRACE:
855855
print(f"Fetched license from remote: {lic_url}")
856856

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

870-
except:
870+
except Exception:
871871
msg = f'No text for license {filename} in expression "{self.license_expression}" from {self}'
872872
print(msg)
873873
errors.append(msg)
@@ -1302,7 +1302,7 @@ def is_pure(self):
13021302
def is_pure_wheel(filename):
13031303
try:
13041304
return Wheel.from_filename(filename).is_pure()
1305-
except:
1305+
except Exception:
13061306
return False
13071307

13081308

src/commoncode/cliutils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import sys
1111

1212
import click
13-
14-
# FIXME: this is NOT API
15-
from click._termui_impl import ProgressBar
13+
from click._termui_impl import ProgressBar # FIXME: this is NOT API
1614
from click.termui import style
1715
from click.types import BoolParamType
1816
from click.utils import echo

src/commoncode/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def close_pipe(p):
203203
# Ensure process death otherwise proc.wait may hang in some cases
204204
# NB: this will run only on POSIX OSes supporting signals
205205
os.kill(proc.pid, signal.SIGKILL) # NOQA
206-
except:
206+
except Exception:
207207
pass
208208

209209
# This may slow things down a tad on non-POSIX Oses but is safe:

src/commoncode/fileset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def load(location):
161161
assert os.path.exists(fn) and os.path.isfile(fn), msg
162162
mode = "r"
163163
with open(fn, mode) as f:
164-
return [l.strip() for l in f if l and l.strip()]
164+
return [line.strip() for line in f if line and line.strip()]
165165

166166

167167
def includes_excludes(patterns, message):

src/commoncode/fileutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def _rm_handler(function, path, excinfo): # NOQA
557557
elif function == os.remove:
558558
try:
559559
delete(path, _err_handler=None)
560-
except:
560+
except Exception:
561561
pass
562562

563563
if os.path.exists(path):

src/commoncode/hash.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,8 @@ def multi_checksums(location, checksum_names=("md5", "sha1", "sha256", "sha512",
284284
mapping is guaranted to contains all the requested names as keys. If the location is not a file,
285285
or if the file is empty, the values are None.
286286
287-
The purpose of this function is to return a set of checksums for a supported set of checksum
288-
algorithms for a given location. This is an API function used in ScanCode --info plugin to get
289-
checksum values.
287+
The purpose of this function is to avoid read the same file multiple times
288+
to compute different checksums.
290289
"""
291290
if not filetype.is_file(location):
292291
return {name: None for name in checksum_names}

src/commoncode/resource.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ def _create_resources_from_paths(self, root, paths):
511511
)
512512
if not newpar:
513513
raise Exception(
514-
f"ERROR: Codebase._create_resources_from_paths: cannot create parent for: {parent_path!r}"
514+
"ERROR: Codebase._create_resources_from_paths:"
515+
f" cannot create parent for: {parent_path!r}"
515516
)
516517
parent = newpar
517518

@@ -1686,7 +1687,7 @@ def _get_scan_data_helper(self, location):
16861687
"""
16871688
try:
16881689
return json.loads(location)
1689-
except:
1690+
except Exception:
16901691
location = abspath(normpath(expanduser(location)))
16911692
with open(location) as f:
16921693
scan_data = json.load(f)
@@ -1842,7 +1843,7 @@ def _populate(self, scan_data):
18421843
##########################################################
18431844
for attr_name in self.codebase_attributes:
18441845
value = scan_data.get(attr_name)
1845-
if value == None:
1846+
if not value:
18461847
continue
18471848
setattr(self.attributes, attr_name, value)
18481849

src/commoncode/system.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ def has_case_sensitive_fs():
113113
case sensitive by default, newer macOS use APFS which is no longer case
114114
sensitive by default.
115115
116-
From https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/APFS_Guide/FAQ/FAQ.html
117-
How does Apple File System handle filenames?
118-
APFS accepts only valid UTF-8 encoded filenames for creation, and preserves
119-
both case and normalization of the filename on disk in all variants. APFS,
120-
like HFS+, is case-sensitive on iOS and is available in case-sensitive and
121-
case-insensitive variants on macOS, with case-insensitive being the default.
116+
From
117+
https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/APFS_Guide/FAQ/FAQ.html
118+
How does Apple File System handle filenames?
119+
APFS accepts only valid UTF-8 encoded filenames for creation, and preserves
120+
both case and normalization of the filename on disk in all variants. APFS,
121+
like HFS+, is case-sensitive on iOS and is available in case-sensitive and
122+
case-insensitive variants on macOS, with case-insensitive being the default.
122123
"""
123124
return not os.path.exists(__file__.upper())
124125

0 commit comments

Comments
 (0)