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