Dieses Projekt ist ein Instrument, das für die Professoren von Informatik bei der Bewertung von Aufträgen behilflich ist. Dieses Tool zählt und gibt die Anzahl der „gemeinsamen Fehler“ (z. B. Klassen ohne Docstrings, Funktionen ohne Docstrings usw.) sowie die Anzahl der gemeinsamen Computerstrukturen (z. B. Funktionen, Klassen, Schleifenkonstrukte, Importe usw.) aus, die vom Benutzer in der Befehlslinienschnittstelle angegeben sind.
Dieses Projekt kann auch als kollaborative Verbesserung dienen, um dieses Tool in den eigenen Gatorgrader des Allegheny College zu importieren, um neue Gatorgrater -Schecks zu erstellen. Das Programm verwendet Libcst, das Python -Code als CST (Betonsyntaxbaum) analysiert, der alle Formatierungsdetails (Kommentare, weiße Räume, Klammern usw.) hält. Als freigegebenes Tool für Pipy kann dieses Tool auch in jedes andere automatisierte Bewertungswerkzeug importiert werden.
poetry add pypi-counter in Ihrem Terminal.from pypi_count.py_counter import PyPiCount .PyPiCount -Klasse in der angegebenen Datei mit der folgenden Syntax an: stored_path = PyPiCount("path_to_file") Während dieses Beispiels ist stored_path eine Instanzvariable, die das Ergebnis der Parsen -Datei speichert. Funktionen müssen in eine analysierte Datei aufgerufen werden.stored_path.[function_name] Syntax. Zum Beispiel stored_path.count_comments()Für die besten Ergebnisse empfehlen wir eine Druckanweisung hinzuzufügen, da die Funktionen nur die Anzahl des angegebenen Konstrukts zurückgeben. Zum Beispiel,
console . print ( f"Number of comments in this file: { stored_path . count_comments () } " )Wird produzieren:
Number of comments in this file : 26Die Liste der verfügbaren Funktionen lautet:
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 ( + = , -= )Benutzer können mit diesem Projekt beginnen, indem sie die folgenden Schritte ausführen:
pip install pypi-counter oder pipx install pypi-counterpoetry run pypicount --help aus. Dieser Befehl zeigt alle verschiedenen Argumente an, die übergeben werden können. Die Liste der verschiedenen Argumente ist unten aufgeführt: 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 .Dies sind die verschiedenen Argumente, die Pypicount in dieser Veröffentlichung akzeptieren wird.
Sobald Sie Ihre gewählten Argumente gefunden haben, führen Sie Folgendes aus:
poetry run pypicount - - [ argument ] - - input - file path / to / file Beispiel für den Beispiel für den Lauf: Befehl:
poetry run pypicount - - class - with - docstrings - - input - file tests / input / sample_file . pyBeispielausgabe:
# of functions with docstrings: 1