PyPiCounter
v.0.2.0
このプロジェクトは、それ自体がコンピューターサイエンスの教授に支援を提供して、課題の採点を支援するツールです。このツールは、「共通エラー」の数(例、ドキュストリングのないクラス、ドキュストリングのない機能など)の数と、コマンドラインインターフェイスのユーザーが指定した一般的なコンピューティング構造(機能、クラス、ループ、インポートなど)の数をカウントおよび出力します。
このプロジェクトは、このツールをアレゲニーカレッジ自身のゲーターグレード担当者にインポートして、新しいGatorgraderチェックを作成するための共同の強化としても機能します。このプログラムは、すべてのフォーマットの詳細(コメント、白いスペース、括弧など)を保持するCST(コンクリート構文ツリー)としてPythonコードを解析するLIBCSTを使用します。 Pipyのリリースツールとして、このツールは他の自動化されたグレーディングツールにもインポートできます。
poetry add pypi-counter 。from pypi_count.py_counter import PyPiCount構文からPypicounterパッケージをインポートします。PyPiCountクラスを呼び出す: stored_path = PyPiCount("path_to_file")この例を通して、 stored_path解析されたファイルの結果を保存するインスタンス変数です。解析されたファイルで関数を呼び出す必要があります。stored_path.[function_name] syntaxを使用して、パッケージ内の関数を実行します。たとえば、 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-counterpoetry 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