Package: castanet
CASTanetTable of ContentsAbout CASTanetInstalling CASTanetRunning CASTanetCASTanet's Command Line InterfaceTestingContributionsContact UsAbout CASTanetCASTanet is a tool created by students at
Allegheny College, allowing users to understand
the contents of Python (.py) files. Through
using concrete abstract syntax trees (CASTs), a
combination of abstract syntax trees (ASTs) and
concrete syntax trees (CSTs), CASTanet usesLibCSTto reorganize and name node types and
fields. CASTanet has functionality to iterate
through a user-specified directory and generate
metrics associated with the Python files in that
given directory. This tool can be used by
educators interested in evaluating students'
code, or individual developers who would like to
better understand their own implementation
strategies.Currently, CASTanet is able to count:Number of if statements in a Python file (and
total in directory)Number of looping constructs in a Python file
(and total in directory)Number of comments in a Python file (and total
in directory)Number of arguments for a specified Python functionNumber of functions in a specified Python file (and total
in directory)Number of function definitionswithoutdocstrings in a Python file (and total in
directory)Number of classes in a Python file (and total in directory)Number of class definitionswithoutdocstrings in a
Python file (and total in directory)Number of assignment statements in a Python file (and
total in directory)Whether a specified function has a docstring or notNumber of import statements in a Python file (and total in
directory)Installing CASTanet - PyPIRun the command to install:pip install castanetInstalling CASTanet - RepositoryClone the CASTanet repository onto your machineIn the appropriate directory, clone the CASTanet
repository following GitFlow and the GitHubdocumentationInstall Poetry and dependenciesThe documentation and instructions on installingPoetrycan be foundhere.Poetryallows dependency installation with
ease. After
cloning the CASTanet
repository, and installingPoetry, install all
necessary dependencies for the tool with the
command:poetry installRunning CASTanetCASTanet is a fully-functional tool with a dynamic command
line interface,
built with the user in mind. To run the CASTanet CLI, in the
base directory of your local, cloned
repository and type the command:castanet[command-here]Without specifying a command, you will receive this error in
your terminal:Usage:castanet[OPTIONS]COMMAND[ARGS]...Try'castanet --help'forhelp.Error:Missingcommand.Please refer to the next section to see what functionality
CASTanet has, and what commands to run.CASTanet's Command Line InterfaceCASTanet's command line interface is created withTyper,
a library for building CLI applications based
on Python 3.6+ type hints.In order to familiarize yourself with the commands for
CASTanet, run the command:poetry run castanet --helpCASTanet's commands are as follows:PLEASE NOTE: Each of the following commands must be run with
thefile pathof the directory of interest given as
input. This directory must be present on your
machine, and CASTanet will provide output pertaining to this
specified directory.castanet assignmentsDetermine number of assignment statements.Usage:castanet assignment [OPTIONS] PATHArguments:PATH: [required]castanet total-classesDetermine number of classes without docstrings.Usage:castanet total-classes [OPTIONS] PATHArguments:PATH: [required]castanet classes-without-docstringsDetermine number of classes without docstrings.Usage:castanet classes-without-docstrings [OPTIONS] PATHArguments:PATH: [required]castanet commentsDetermine number of comments.Usage:castanet comments [OPTIONS] PATHArguments:PATH: [required]castanet function-argumentsDetermine the number of parameters for a given function.Usage:castanet function-arguments [OPTIONS] PATH FUNCTION_NAMEArguments:PATH: [required]FUNCTION_NAME: [required]castanet function-docstring-existsDetermine if a given function has a docstring.Usage:castanet function-docstring-exists [OPTIONS] PATH FUNCTION_NAMEArguments:PATH: [required]FUNCTION_NAME: [required]castanet functions-without-docstringsDetermine number of functions without docstrings.Usage:castanet functions-without-docstrings [OPTIONS] PATHArguments:PATH: [required]castanet if-statementsDetermine number of if statements in a Python directory.Usage:castanet if-statements [OPTIONS] PATHArguments:PATH: [required]castanet importsDetermine number of import statements.Usage:castanet imports [OPTIONS] PATHArguments:PATH: [required]castanet looping-constructsDetermine number of looping constructs.Usage:castanet looping-constructs [OPTIONS] PATHArguments:PATH: [required]castanet functions-per-moduleDetermine number of functions in a Python directory.Usage:castanet functions-per-module [OPTIONS] PATHArguments:PATH: [required]castanet total-functionsDetermine total number of functions in a Python directory.Usage:castanet total-functions [OPTIONS] PATHArguments:PATH: [required]Currently, CASTanet only has functionality
foronemetric to be calculated at a time.
As a result, if you are interested in one or
more metric, you must run CASTanet for the first metric
(with the corresponding CLI command),
and then run CASTanet subsequently for
each additional metric (with the corresponding CLI command).CASTanet as a Python LibraryCASTanet is also available on PyPI to be used as a Python
library. Find ithere.
With the CASTanet library, a user is able to investigate
their Python files with many different function calls.
Specifically, CASTanet is broken down into two parts:generate_trees: Traverses a directory and generates
concrete-abstract-syntax trees of Python files using
LibCSTcounter: Uses concrete-abstract-syntax-trees to
calculate metrics associated with the contents of a Python
modulecounterfrom castanet import countersum_dict_valsCalculate the sums of values from dictionaries.
Called to get number values from the result of a
function. Must always be run on the results ofcountfunctions to get final numbers.counter.sum_dict_vals(values_dict)ARGUMENTS:values_dict: dictionary of total values for metricsRETURNS:int: total number of items in dictionarycount_importsCount the number of import statements in a Python file.counter.count_imports(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of import statementscount_functionsCount the number of function definitions in a Python file.counter.count_functions(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:*dict: files and the corresponding amount of function definitionscount_commentsCount the number of comments in a Python file.counter.count_comments(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of commentscount_while_loopsCount the number of while loops in a Python file.counter.count_while_loops(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of while loopscount_for_loopsCount the number of for loops in a Python file.counter.count_for_loops(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of for loopscount_if_statementsCount the number of if statements in a Python file.counter.count_if_statements(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of if statementscount_func_defsCount the number of function definitions in a Python file.counter.count_func_defs(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of function_definitionscount_function_without_docstringsCount the number of functions without docstrings.counter.count_function_without_docstrings(func_count)ARGUMENTS:dict: A dictionary of functions and docstring counts per fileRETURNS:int: total number of functions - total number of docstringsNote:It is required to first callcount_func_defsin
order for this function call to work correctly.docstring_existsDetermine if a docstring exists for a specified function.counter.docstring_exists(path, function_name)ARGUMENTS:path: A string path corresponding to a Python file or a directoryfunction_name (str): Name of function to check for docstringsRETURNS:-1: function does not exist0: function exists without docstring1: function exists with docstringmatch_class_defsCount the number of class definitions in a Python file.counter.count_class_defs(cast_dict)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of class definitionscount_class_defs_without_docstringsCount the number of class definitions without docstrings.counter.count_class_defs_without_docstrings(class_count)ARGUMENTS:dict: A dictionary of classes and docstring counts per fileRETURNS:int: total number of classes - total number of docstringsNote:It is required to first callcount_class_defsin
order for this function call to work correctly.count_function_argumentsCount the number of arguments for a specified function.counter.count_function_arguments(path, function_name)ARGUMENTS:path: A string path corresponding to a Python file or a directoryfunction_name: User-specified file of interestRETURNS:-1: Function was not foundelse: The amount of parameters for the given functioncount_assignmentsCount the number of assignment statements in a Python file.(does not include augmented assignment)counter.count_assignments(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of assignment statementscount_aug_assignmentCount the number of aug assignment statements (x += 5) in a Python file.counter.count_aug_assignment(path)ARGUMENTS:path: A string path corresponding to a Python file or a directoryRETURNS:dict: files and the corresponding amount of aug assignment statementsTestingAutomated TestingDevelopers of this program can run the test
suite withPytestwith the command:poetry run task testContributionsWe welcome everyone who is interested in helping to improve
CASTanet!
If you are interested in being a contributor, please review
ourCode of ConductandGuidelines for Contributorsbefore raising an issue, or beginning a contribution.To raise an issue inCASTanet's Issue Trackerplease follow these templates:bug_report.mdfeature_request.mdTo create a pull request, please follow this template:pull_request_template.mdContact UsIf you have any questions or concerns about CASTanet, please contact:Madelyn Kapfhammer (kapfhammerm@allegheny.edy)Thomas Antle (antlet@allegheny.edu)Nolan Thompson (thompsonn2@allegheny.edu)Caden Hinckley (hinckleyc@allegheny.edu)Bailey Matrascia (matrasciab@allegheny.edu)