Этот проект представляет собой инструмент, который сам по себе окажет помощь профессорам компьютерных наук, чтобы помочь в оценке заданий. Этот инструмент будет рассчитывать и выводить количество «общих ошибок» (например, классов без докторов, функций без докторов и т. Д.), А также количество общих вычислительных структур (например, функции, классы, конструкции цикла, импорт и т. Д.) Все, как указано пользователем в интерфейсе командной строки.
Этот проект также может служить совместным улучшением для импорта этого инструмента в собственный GatorGrader Allegheny College для создания новых чеков GatorGrader. Программа использует 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-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