Package: pypi-counter
PyPi-CounterTable of ContentsOverviewProject UsageGetting StartedImporting to Another ToolStand-Alone UsageHelp and Bug FixesAuthorsOverviewThis 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.Usefulness of ProjectWithin LibCST, it has many nodes to "match" modules, expressions, and
statements which allowed us as programmers to complete our user stories in a
more uniform way. This project is useful because of the exploration of LibCST,
which ultimately allows end users to specify a given construct they would like
to identify in the source code (as LibCST will find all matches of this construct).Getting StartedImporting into Another Grading ToolIf you would like to display the results for all of our functions, please follow the following steps. Please note that these steps will only work if your program is able to useTyperas a dependency.Install from PyPi by runningpoetry add pypi-counterorpip install pypiin your terminal.Add the following import statements to your main program file:from pypi_count import command_line_interfaceandfrom pypi_count import *andimport typerAdd the desired file you want analyzed as a part of the main arguments in the following way:cli=typer.Typer()@cli.command()defmain(analyze:Path=typer.Option("path/to/file"),):Throughout this example,analyzeis an instance variable that stores the
result of the parsed file. Functions must be called on a parsed file.
4. Add the following syntax inside your main function:command_line_interface.main(analyze).
This will display the counting results forallof our available functions in the format that they are given.Alternatively, the following steps should be used if you would like to add the PyPi-Counter as a part of your program or project. This will ensure that only specified functions will be displayed in your output along with the rest of your program.Install from PyPi by runningpoetry add pypi-counterin your terminal.Import the PyPiCounter package with the syntax:from pypi_count.py_counter import PyPiCount.CallPyPiCountClass on specified file with the following syntax:stored_path = PyPiCount("path_to_file")Throughout this example,stored_pathis an instance variable that stores the
result of the parsed file. Functions must be called on a parsed file.Run the functions in the package using thestored_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:Numberofcommentsinthisfile:26The list of functions available are:count_class_definitions(file_name)# returns the number of class definitionscount_comments(file_name)# returns the number of commentscount_import_statements(file_name)# returns the number of import statementscount_for_loops(file_name)# returns the number of for loopscount_while_loops(file_name)# returns the number of while loopscount_function_definitions(file_name)# returns the number of function definitionscount_functions_without_docstrings(file_name)# returns the number of functions without docstringscount_functions_with_docstrings(file_name)# returns the number of functions with docstringscount_classes_with_docstrings(file_name)# returns the number of classes with docstringscount_classes_without_docstrings(file_name)# returns the number of classes without docstringscount_function_parameters(file_name,function_name)# returns the number of function parameters# after specifying the function namecount_assignment_statements(file_name)# returns the number of assignment statementscount_augmented_assignment_statements(file_name)# returns the number of assignment statements that includeanaugmentedassignmentoperator(+=,-=)Stand-Alone UsageUsers can get started with this project by following the following steps:Install the package with pip, using the commandpip install pypi-counter,pipx install pypi-counter, orpoetry add pypi-counterTo familiarize yourself with the arguments accepted for this project, run the
commandpoetry run pypicount --helpif your program contains a poetry.lock file
orpypicount --helpif your program does not use poetry. 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_FILEMainmethodtodisplaythedifferentoptions.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-parametersTEXT--assignment-statements[default:False]--augmented-assignment-statements[default:False]--while-loops[default:False]--for-loops[default:False]--install-completionInstallcompletionforthecurrentshell.--show-completionShowcompletionforthecurrentshell,tocopyitorcustomizetheinstallation.--helpShowthismessageandexit.These are the different types of arguments that PyPi-Counter will accept in this release.
As the path to a file is a required parameter, you will not be able to run this
program without specifying a path to a file in your run command.Once you find your chosen arguments, run the following if using with poetry:poetryrunpypicount--[argument]path/to/fileor if you are using without poetry:pypicount--[argument]path/to/fileExample of OutputSample run command with installation using poetry:poetryrunpypicount--class-with-docstringstests/input/sample_file.pySample Output:# of functions with docstrings: 1Sample run command with installation using pip:pypicount--class-with-docstringstests/input/sample_file.pySample Output:# of functions with docstrings: 1Help and Bug FixesUsers who are having trouble with navigating the program can come to the ReadMe
for assistance.Users can also open an issue on ourIssue Trackerwith the following format:Describe the bugInclude steps to replicate the bugExpected behaviorScreenshotsDesktop OSAuthorsThe people who maintain and contribute to this project areAlexis Caldwell,@caldwella2Adriana Solis,@solisa986Rachael Harris,@rachaelharrisRamon Guzman,@guzmanr04Ryan Hilty,@RyanHiltyAllegheny