Giter Site home page Giter Site logo

cmpsc-481-s22-m1 / pypicounter Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 2.0 2.33 MB

A Python package that counts different segments of a Python package or module, as specified by the user.

Home Page: https://pypi.org/project/pypi-counter/

License: MIT License

Python 100.00%
python counting pypi-package

pypicounter's Introduction

PyPi-Counter

PyPi-Counter License: MIT example workflow github issues

Table of Contents

Overview

  • 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.

Usefulness of Project

  • Within 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 Started

Importing into Another Grading Tool

  1. Install from PyPi by running poetry add pypi-counter in your terminal.
  2. Import the PyPiCounter package with the syntax: from pypi_count.py_counter import PyPiCount.
  3. Call 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.
  4. Run the functions in the package using the 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: 26

The 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 (+=, -=)

Stand-Alone Usage

Users can get started with this project by following the following steps:

  1. Install the package with pip, using the command pip install pypi-counter or pipx install pypi-counter
  2. To familiarize yourself with the arguments accepted for this project, run the command poetry 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/file

Example of Output

Sample run command:

poetry run pypicount --class-with-docstrings --input-file tests/input/sample_file.py

Sample Output:

# of functions with docstrings: 1

Help and Bug Fixes

  • Users who are having trouble with navigating the program can come to the ReadMe for assistance.
  • Users can also open an issue on our Issue Tracker with the following format:
    • Describe the bug
    • Include steps to replicate the bug
    • Expected behavior
    • Screenshots
    • Desktop OS

Authors

pypicounter's People

Contributors

caldwella2 avatar guzmanr04 avatar michionlion avatar rachaelharris avatar ryanhiltyallegheny avatar solisa986 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pypicounter's Issues

Duplicate Packages

In the pyproject.toml file, there are two packages that mean the same thing. Remove one of the packages and import the entirety of our package instead of just a single file in our package.

Rename Main Package

Currently the name of our main package is src, but in order to make the program more user friendly we should change it to the name of the acutal program.

The DS_store is in a bad place in the code, we should either place it in a user-level git-ignore or project-level git-ignore

Line Length

The line length in test_command_line_interface is too long. Split it up by splitting it into two or more lines so it will pass the Pylint errors.

Error in README

The end of the readme is in a code block. We need to make sure that only the sample output is in the code block.

Pylint fixes

Currently some pylint features were disabled but need to be resolved. Error code W1514 should be resolved and R1732 does not need to be disabled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.