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.4.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.4.tar.gz.

File metadata

File hashes

Hashes for ece241_submission_static_analyzer-0.0.4.tar.gz
Algorithm Hash digest
SHA256 4625570c4f5f1524f1b9524c5314a91f3f339803e2bd0ffa3b6b6bcf14a217ed
MD5 da56cd2d047b48d39d0ecc69f7c5b1f2
BLAKE2b-256 846e91d64853171e6256e2f534bba03a8da2f231502cd022c1313fbe518b4f85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ece241_submission_static_analyzer-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 84c5626d63436c70ec436ee9e57bc96214570595abb5cc26715865fde785badd
MD5 dd87bd63f9a69b9feacd3d4f9ef11d22
BLAKE2b-256 91f1985d3112c4e237c5f75ba5c6bb2a24b40fca067c28148e77f65621cdbbab

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