Skip to content

Commit a1a3476

Browse files
authored
POD-2631: Add GitHub Action to run Linting (#22)
* add github action to run linting * separate checks * remove pre-commit, use tools directly * reformat to pass mypy errors * reformat to pass mypy errors
1 parent f858dbc commit a1a3476

10 files changed

+65
-12
lines changed

Diff for: .github/workflows/check-coverage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Python
1818
uses: actions/setup-python@v4
1919
with:
20-
python-version: '3.11'
20+
python-version: "3.11"
2121

2222
- name: Install dependencies
2323
run: |

Diff for: .github/workflows/docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- uses: actions/checkout@v4
2222
- uses: actions/setup-python@v5
2323
with:
24-
python-version: '3.13'
24+
python-version: "3.13"
2525

2626
# ADJUST THIS: install all dependencies (including pdoc)
2727
- run: |

Diff for: .github/workflows/lint.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Linting and Static Analysis
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
lint:
10+
name: Lint (flake8)
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-python@v4
15+
with:
16+
python-version: "3.11"
17+
- name: Install flake8
18+
run: pip install flake8
19+
- name: Run flake8
20+
run: flake8 . --max-line-length=120 --exclude=docs,ops_utils/tests
21+
22+
type-check:
23+
name: Type Checking (mypy)
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
- uses: actions/setup-python@v4
28+
with:
29+
python-version: "3.11"
30+
- name: Install mypy and stubs
31+
run: |
32+
pip install mypy types-requests types-python-dateutil types-pytz
33+
- name: Run mypy
34+
run: |
35+
mypy . \
36+
--disallow-untyped-defs \
37+
--disallow-incomplete-defs \
38+
--disallow-untyped-calls \
39+
--ignore-missing-imports \
40+
--python-version=3.11 \
41+
--exclude '^(docs/|ops_utils/tests/)'
42+
43+
yaml-check:
44+
name: YAML Syntax Check
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v3
48+
- name: Install PyYAML
49+
run: pip install pyyaml
50+
- name: Validate YAML files
51+
run: |
52+
find . -name "*.yml" -o -name "*.yaml" | while read file; do
53+
echo "Checking $file"
54+
python -c "import yaml, sys; yaml.safe_load(open('$file'))"
55+
done

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repos:
3939
hooks:
4040
- id: flake8
4141
additional_dependencies: [flake8]
42-
args: [--max-line-length=120] # <-- customize your preferred max length
42+
args: [--max-line-length=120, ] # <-- customize your preferred max length
4343

4444
# Excludes these directories globally (i.e. no hooks will be applied to the docs/ or ops_utils/test/ dirs)
4545
exclude: ^(docs/|ops_utils/tests/)

Diff for: VERSION.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
1.6.0
2-
- Add documentation link to README
3-
- Add build badges to README
1+
1.7.0
2+
- Add GitHub action to run linting checks

Diff for: ops_utils/azure_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_blob_details(self, max_per_page: int = 500) -> list[dict]:
3030
logging.info(
3131
f"Getting page {page_count} of max {max_per_page} blobs")
3232
for blob in blob_page:
33-
blob_client = container_client.get_blob_client(blob)
33+
blob_client = container_client.get_blob_client(blob) # type: ignore[arg-type]
3434
props = blob_client.get_blob_properties()
3535
if not blob.name.endswith('/'):
3636
md5_hash = base64.b64encode(props.content_settings.content_md5).decode(

Diff for: ops_utils/gcp_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, project: Optional[str] = None) -> None:
2525
Initialize the GCPCloudFunctions class.
2626
Authenticates using the default credentials and sets up the storage client.
2727
"""
28-
from google.cloud import storage
28+
from google.cloud import storage # type: ignore[attr-defined]
2929
from google.auth import default
3030
credentials, default_project = default()
3131
if not project:

Diff for: ops_utils/jira_util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_issues_by_criteria(
5757
max_results: int = 200,
5858
fields: Optional[Union[list, str]] = None,
5959
expand_info: Optional[str] = None
60-
) -> dict:
60+
) -> list[dict]:
6161
logging.info(f"Getting issues by criteria: {criteria}")
6262
if fields:
6363
return self.jira.search_issues(criteria, fields=fields, maxResults=max_results, expand=expand_info)

Diff for: ops_utils/tdr_utils/tdr_api_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def create_dataset( # type: ignore[return]
835835
if additional_dataset_properties:
836836
dataset_properties.update(additional_dataset_properties)
837837
try:
838-
CreateDatasetSchema(**dataset_properties)
838+
CreateDatasetSchema(**dataset_properties) # type: ignore[arg-type]
839839
except ValidationError as e:
840840
raise ValueError(f"Schema validation error: {e}")
841841
uri = f"{self.TDR_LINK}/datasets"

Diff for: ops_utils/tdr_utils/tdr_ingest_utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,7 @@ def _reformat_metric(self, row_dict: dict) -> Optional[dict]:
464464
reformatted_dict[key] = update_value
465465
if not valid:
466466
row_valid = False
467-
reformatted_dict["last_modified_date"] = datetime.now(
468-
tz=pytz.UTC).strftime("%Y-%m-%dT%H:%M:%S") # type: ignore[assignment]
467+
reformatted_dict["last_modified_date"] = datetime.now(tz=pytz.UTC).strftime("%Y-%m-%dT%H:%M:%S") # type: ignore[assignment] # noqa: E501
469468
if row_valid:
470469
return reformatted_dict
471470
else:

0 commit comments

Comments
 (0)