هذا المشروع هو أداة ، من تلقاء نفسها ، ستوفر المساعدة لأساتذة علوم الكمبيوتر للمساعدة في مهام الدرجات. ستعمل هذه الأداة على إخراج عدد "الأخطاء الشائعة" (على سبيل المثال ، فئات بدون docstrings ، وظائف بدون docstrings ، وما إلى ذلك) وكذلك عدد هياكل الحوسبة الشائعة (على سبيل المثال ، الوظائف ، الفئات ، بنيات الحلقات ، الواردات ، إلخ) كلها على النحو المحدد من قبل المستخدم في واجهة سطر الأوامر.
يمكن أن يكون هذا المشروع أيضًا بمثابة تعزيز تعاوني لاستيراد هذه الأداة إلى Gatorgryer الخاص بكلية Allegheny لإنشاء فحوصات جديدة في 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