This project is a tool that, on its own, will provide assistance to computer science professors to assist in grading assignments. This tool will count and output the number of 'common errors' (e.g., Classes without docstrings, functions without docstrings, etc.) as well as the number of common computing structures (e.g., functions, Classes, looping constructs, imports, etc.) all as specified by the user in the command line interface.
This project also can serve as a collaborative enhancement to import this tool into Allegheny College's own GatorGrader to create new GatorGrader checks. The program utilizes LibCST, which parses Python code as a CST (Concrete Syntax Tree) that keeps all formatting details (comments, white spaces, parentheses, etc.). As a released tool on PiPy, this tool can be imported into any other automated grading tool as well.
poetry add pypi-counter in your terminal.from pypi_count.py_counter import PyPiCount.PyPiCount Class on specified file with the following syntax:
stored_path = PyPiCount("path_to_file")
Throughout this example, stored_path is an instance variable that stores the
result of the parsed file. Functions must be called on a parsed file.stored_path.[function_name] syntax.
For example, stored_path.count_comments()For best results, we recommend adding a print statement, as the functions will only return the number of the specified construct. For example,
console.print(f"Number of comments in this file: {stored_path.count_comments()}")Will produce:
Number of comments in this file: 26The list of functions available are:
count_class_definitions(file_name)
# returns the number of class definitions
count_comments(file_name)
# returns the number of comments
count_import_statements(file_name)
# returns the number of import statements
count_for_loops(file_name)
# returns the number of for loops
count_while_loops(file_name)
# returns the number of while loops
count_function_definitions(file_name)
# returns the number of function definitions
count_functions_without_docstrings(file_name)
# returns the number of functions without docstrings
count_functions_with_docstrings(file_name)
# returns the number of functions with docstrings
count_classes_with_docstrings(file_name)
# returns the number of classes with docstrings
count_classes_without_docstrings(file_name)
# returns the number of classes without docstrings
count_function_parameters(file_name, function_name)
# returns the number of function parameters
# after specifying the function name
count_assignment_statements(file_name)
# returns the number of assignment statements
count_augmented_assignment_statements(file_name)
# returns the number of assignment statements that include
an augmented assignment operator (+=, -=)Users can get started with this project by following the following steps:
pip install pypi-counter
or pipx install pypi-counterpoetry run pypicount --help. This command displays all of the
different arguments that can be passed. The list of the different arguments
are listed below:Usage: pypicount [OPTIONS] INPUT_FILE
Main method to display the different options.
Arguments:
INPUT_FILE [required]
Options:
--class-definitions [default: False]
--import-statements [default: False]
--comments [default: False]
--function-definitions [default: False]
--if-statements [default: False]
--function-without-docstrings [default: False]
--function-with-docstrings [default: False]
--class-with-docstrings [default: False]
--class-without-docstrings [default: False]
--function-parameters TEXT
--assignment-statements [default: False]
--augmented-assignment-statements
[default: False]
--while-loops [default: False]
--for-loops [default: False]
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to
copy it or customize the installation.
--help Show this message and exit.These are the different types of arguments that PyPiCount will accept in this release.
Once you find your chosen arguments, run the following:
poetry run pypicount --[argument] --input-file path/to/fileSample run command:
poetry run pypicount --class-with-docstrings --input-file tests/input/sample_file.pySample Output:
# of functions with docstrings: 1