Skip to main content

A package that performs static analysis on code submissions.

Project description

Usage:

from ece241_submission_static_analyzer.main import check, StaticAnalysisItem
from ece241_submission_static_analyzer.all_rules import RULES_YOU_ARE_CHECKING

request = [
    StaticAnalysisItem(
        rule=RULES_YOU_ARE_CHECKING(), 
        kwargs=KWARGS,
        file=FILE_NAME
    ),
    # other rules
]

results = check(request)

Rules

FunctionMustReturnRule

This rule checks if the last statement of given functions are return statements. If students uses print instead of return, this rule will be violated.

kwargs={"function_names": ["func1", "func2"]}

Note, if you meant to check member function of a class, the function name should be ClassName.FunctionName

RequireClassRule

This rule checks if the given class is defined in a file/module.

kwargs={"class_names": ["class1", "class2"]}

RequireFileRule

This rule checks if the a file exist.

kwargs={}

RequireFunctionRule

This rule checks if given functions are defined.

kwargs={"function_names": ["func1", "func2"]}

Note, if you meant to check member function of a class, the function name should be ClassName.FunctionName

NoInputFuncRule

This rule requires no input function is used inside the given file. This applies whether students use them inside the class definition, function definition, regardless the function might be called. One exception is node under if __name__ == "__main__": block is NOT checked.

kwargs={}

NoRootStatementsRule

This rule that no statement is allowed at root level. This checks if there is any function calls, print statements, input statements are used at root level. Class definitions function definitions, package imports, if __name__ == "__main__": block are allowed.

kwargs={}

Returns:

A list of ViolationResult objects.

class ViolationResult(NamedTuple):
    file_path: str
    line_number: int
    message: str
    rule: RuleType
    severity: SeverityType  # Updated to use SeverityType

SeverityType values:

class SeverityType(Enum):
    ERROR = "error"
    WARNING = "warning"
    INFO = "info"

Bundled check

Usage

from ece241_submission_static_analyzer.main import bundle

Function bundle signature

def bundle(file: str, classes: list[str], functions: list[str]) -> list[StaticAnalysisItem]:

This function builds RequireClassRule->RequireFunctionRule->NoInputFuncRule->NoRootStatementsRule->FunctionMustReturnRule lists. Note: there is no file check. File check is suggested as a upstream parent check.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ece241_submission_static_analyzer-0.0.3.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file ece241_submission_static_analyzer-0.0.3.tar.gz.

File metadata

File hashes

Hashes for ece241_submission_static_analyzer-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2e5fae6aa528c0d49c6c76e734eac59d391c602055dde48d55faf88c406bbbec
MD5 c9d1bc7f91d81a7f79b272873e9ea057
BLAKE2b-256 79a8e09beed94da6a81921c9d3349034cd66d930a39af9f34a40a36510351c55

See more details on using hashes here.

File details

Details for the file ece241_submission_static_analyzer-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for ece241_submission_static_analyzer-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 878dc85ae6c514dab922b26ae3f7a770cce24e24b7417f1ffe85adf035f7efe8
MD5 440b1e03a4725cff7fd7642071c408cb
BLAKE2b-256 effe06eb9b94368e0feb9130b91874c5eab01dc38c7446698139c32fdf5c4ca6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page