Skip to content

Commit

Permalink
Fix typing and add it to CI (#55)
Browse files Browse the repository at this point in the history
* Fix typing and add it to CI
  • Loading branch information
kunaltyagi authored Oct 14, 2023
1 parent d79d9ed commit 14cac75
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Lint CI

on:
pull_request:
branches: [ "master" ]
branches: ["master"]

jobs:
run-lints:
Expand All @@ -16,11 +16,13 @@ jobs:
- name: Set up pip cache
uses: actions/[email protected]
with:
path: ~/.cache/pip
path: |
~/.cache/pip
${{ github.workspace }}/.mypy_cache
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: ${{ runner.os }}-pip-
- name: Install Hatch
run: pipx install hatch

- name: Check style
run: hatch run lint:style
- name: Check style and typing
run: hatch run lint:all
5 changes: 0 additions & 5 deletions nsiqcppstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
#
from nsiqcppstyle_util import *

try:
import hashlib # @UnusedImport
except ImportError:
import md5 # @UnusedImport


if __name__ == "__main__":
sys.path.append(GetRuntimePath())
Expand Down
6 changes: 4 additions & 2 deletions nsiqcppstyle_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2022 All rights reserved.
# SPDX-License-Identifier: GPL-2.0-only

from typing import NewType, Union
from typing import NewType, TypeVar

import nsiqcppstyle_checker
import nsiqcppstyle_lexer
Expand Down Expand Up @@ -32,7 +32,9 @@
LineText = NewType("LineText", str)

# The target directory currently being analyzed
TargetDirectory = NewType("TargetDirectory", Union[str, bytes])
TargetDirectoryStr = NewType("TargetDirectoryStr", str)
TargetDirectoryBytes = NewType("TargetDirectoryBytes", bytes)
TargetDirectory = TypeVar("TargetDirectory", TargetDirectoryStr, TargetDirectoryBytes)

# The token currently being processed
Token = NewType("Token", nsiqcppstyle_lexer.LexToken)
Expand Down
22 changes: 10 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
]
dependencies = []

[project.optional-dependencies]
dev = [
"pip_search"
]
test = [
"pytest == 7.4.*",
]
dev = ["pip_search"]
test = ["pytest == 7.4.*"]

[project.urls]
Documentation = "https://github.com/kunaltyagi/nsiqcppstyle/blob/master/README.md"
Expand Down Expand Up @@ -79,8 +74,8 @@ python = "3.8"
typing = "mypy --install-types --non-interactive {args:.}"
# style = ["ruff {args:.}", "black --check --diff {args:.}"]
style = ["black --check --diff {args:.}"]
# fmt = ["black {args:.}", "ruff --fix {args:.}", "style"]
fmt = ["black {args:.}"]
fmt = ["black {args:.}", "ruff --fix {args:.}", "style"]
# fmt = ["black {args:.}"]
all = ["style", "typing"]

[tool.hatch.build.targets.sdist]
Expand All @@ -95,15 +90,15 @@ exclude = ["/updateagent"]
# mypy-args = ["--no-warn-unused-ignores"]

[tool.black]
target-version = ["py310"]
target-version = ["py38"]
line-length = 120
skip-string-normalization = true
extend-exclude = """
temp/
"""

[tool.ruff]
target-version = "py310"
target-version = "py38"
line-length = 120
select = [
"A",
Expand Down Expand Up @@ -215,6 +210,9 @@ warn_unreachable = true
[[tool.mypy.overrides]]
module = "nsiqcppstyle.*"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "updateagent.*"
ignore_errors = true

[tool.bandit]
exclude_dirs = ["tests"]
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test8(self):
)
self.ExpectError(__name__)

def test8(self):
def test9(self):
self.Analyze(
"thisfile.c",
"""
Expand All @@ -190,7 +190,7 @@ def test8(self):
)
self.ExpectError(__name__)

def test9(self):
def test10(self):
# known issue. Not a problem
self.Analyze(
"thisfile.c",
Expand Down
4 changes: 2 additions & 2 deletions rules/RULE_3_2_B_do_not_use_same_filename_more_than_once.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
testdir/stadfx.*
testdir1/stdafx.*
"""
import string
from typing import Dict, List

from nsiqcppstyle_reporter import * # @UnusedWildImport
from nsiqcppstyle_rulemanager import * # @UnusedWildImport
from nsiqunittest.nsiqcppstyle_unittestbase import *

filenameMap = {}
filenameMap: Dict[str, List[str]] = {}


def RunRule(lexer, filename, dirname):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class J {
)
self.ExpectSuccess(__name__)

def test14(self):
def test16(self):
self.Analyze(
"thisfile.h",
"""
Expand All @@ -282,7 +282,7 @@ class J {
)
self.ExpectError(__name__)

def test15(self):
def test17(self):
self.Analyze(
"thisfile.h",
"""
Expand Down

0 comments on commit 14cac75

Please sign in to comment.