โครงการนี้เป็นเครื่องมือที่จะให้ความช่วยเหลือแก่อาจารย์วิทยาการคอมพิวเตอร์เพื่อช่วยในการจัดเตรียมการมอบหมาย เครื่องมือนี้จะนับและส่งออกจำนวน 'ข้อผิดพลาดทั่วไป' (เช่นคลาสที่ไม่มีเอกสารฟังก์ชั่นที่ไม่มีเอกสาร ฯลฯ ) รวมถึงจำนวนโครงสร้างการคำนวณทั่วไป (เช่นฟังก์ชั่นคลาสคลาสการสร้างการนำเข้านำเข้า ฯลฯ ) ทั้งหมดตามที่ผู้ใช้ระบุไว้
โครงการนี้ยังสามารถทำหน้าที่เป็นการเพิ่มความร่วมมือในการนำเข้าเครื่องมือนี้ไปยัง Gatorgrader ของ Allegheny College เพื่อสร้างการตรวจสอบ Gatorgrader ใหม่ โปรแกรมใช้ libcst ซึ่งวิเคราะห์รหัส Python เป็น CST (แผนผังไวยากรณ์คอนกรีต) ที่เก็บรายละเอียดการจัดรูปแบบทั้งหมด (ความคิดเห็นพื้นที่สีขาววงเล็บ ฯลฯ ) ในฐานะเครื่องมือที่วางจำหน่ายบน Pipy เครื่องมือนี้สามารถนำเข้าสู่เครื่องมือการให้เกรดอัตโนมัติอื่น ๆ ได้เช่นกัน
poetry add pypi-counter ในเทอร์มินัลของคุณfrom pypi_count.py_counter import PyPiCountPyPiCount ในไฟล์ที่ระบุด้วยไวยากรณ์ต่อไปนี้: 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 คำสั่ง Run Sample:
poetry run pypicount - - class - with - docstrings - - input - file tests / input / sample_file . pyตัวอย่างเอาท์พุท:
# of functions with docstrings: 1