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.5.tar.gz (9.3 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.5.tar.gz.

File metadata

File hashes

Hashes for ece241_submission_static_analyzer-0.0.5.tar.gz
Algorithm Hash digest
SHA256 bba64f76ad0f4915a7a46ff3f1af79f8a175600b2e93dae17815201381a3dace
MD5 2d765ab264a9988af649807e730577f7
BLAKE2b-256 c41fb4837ac48010159617079db55542dcbc74843cb067163473cd4e50efe4a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ece241_submission_static_analyzer-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e6fdf18469c6c1b5999f9b13c44de28846ac892b7c41a5ea129bbc12530ebf51
MD5 25766c637e85162d7ea3769c419c6724
BLAKE2b-256 f137af644fe1c22374af514a1f143631c7676151dd6b291d64c8af440be45f80

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