PyPiCounter
v.0.2.0
该项目是一种工具,它本身将为计算机科学教授提供帮助,以协助分级任务。该工具将计算并输出“常见错误”的数量(例如,没有DocStrings的类,无需DOCSTRINGS等功能等)以及通用计算结构的数量(例如,函数,类,循环构造,导入等)。
该项目还可以作为协作增强功能,以将该工具导入Allegheny College自己的Gatorgrader,以创建新的GatorGrader检查。该程序利用libcst,该LIBCST将Python代码解析为CST(具体语法树),该代码继续所有格式化的细节(注释,白色空间,括号等)。作为PIPY上已发布的工具,此工具也可以将其导入到任何其他自动化分级工具中。
poetry add pypi-counter 。from pypi_count.py_counter import PyPiCount 。PyPiCount类: stored_path = PyPiCount("path_to_file") , stored_path是一个实例变量,可存储解析文件的结果。必须在解析文件上调用功能。stored_path.[function_name]语法。例如, stored_path.count_comments()为了获得最佳结果,我们建议添加打印语句,因为功能只会返回指定构造的数量。例如,
console . print ( f"Number of comments in this file: { stored_path . count_comments () } " )将产生:
Number of comments in this file : 26可用功能列表是:
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 ( + = , -= )用户可以通过遵循以下步骤开始该项目:
pip install pypi-counter或pipx install pypi-counter安装软件包poetry run pypicount --help 。此命令显示可以通过的所有不同参数。不同参数的列表如下列出: 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 .这些是Pypicount在此版本中会接受的不同类型的参数。
一旦找到所选的论点,请运行以下内容:
poetry run pypicount - - [ argument ] - - input - file path / to / file 示例运行命令:
poetry run pypicount - - class - with - docstrings - - input - file tests / input / sample_file . py样本输出:
# of functions with docstrings: 1