Proyek ini adalah alat yang, dengan sendirinya, akan memberikan bantuan kepada profesor ilmu komputer untuk membantu dalam penilaian penugasan. Alat ini akan menghitung dan mengeluarkan jumlah 'kesalahan umum' (misalnya, kelas tanpa docstring, fungsi tanpa docstring, dll.) Serta jumlah struktur komputasi umum (misalnya, fungsi, kelas, konstruksi looping, impor, dll.) Semua seperti yang ditentukan oleh pengguna dalam antarmuka baris perintah.
Proyek ini juga dapat berfungsi sebagai peningkatan kolaboratif untuk mengimpor alat ini ke GatorGrader Allegheny College sendiri untuk membuat cek GatorGrader baru. Program ini menggunakan libcst, yang mem -parsing kode Python sebagai CST (pohon sintaks beton) yang membuat semua detail pemformatan (komentar, ruang putih, tanda kurung, dll.). Sebagai alat yang dirilis di PIPY, alat ini dapat diimpor ke alat penilaian otomatis lainnya juga.
poetry add pypi-counter di terminal Anda.from pypi_count.py_counter import PyPiCount .PyPiCount pada file yang ditentukan dengan sintaks berikut: stored_path = PyPiCount("path_to_file") di seluruh contoh ini, stored_path adalah variabel instance yang menyimpan hasil dari file yang diuraikan. Fungsi harus dipanggil pada file parsed.stored_path.[function_name] . Misalnya, stored_path.count_comments()Untuk hasil terbaik, kami sarankan menambahkan pernyataan cetak, karena fungsinya hanya akan mengembalikan jumlah konstruk yang ditentukan. Misalnya,
console . print ( f"Number of comments in this file: { stored_path . count_comments () } " )Akan menghasilkan:
Number of comments in this file : 26Daftar fungsi yang tersedia adalah:
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 ( + = , -= )Pengguna dapat memulai dengan proyek ini dengan mengikuti langkah -langkah berikut:
pip install pypi-counter atau pipx install pypi-counterpoetry run pypicount --help . Perintah ini menampilkan semua argumen berbeda yang dapat dilewati. Daftar argumen yang berbeda tercantum di bawah ini: 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 .Ini adalah berbagai jenis argumen yang akan diterima Pypicount dalam rilis ini.
Setelah Anda menemukan argumen yang Anda pilih, jalankan yang berikut:
poetry run pypicount - - [ argument ] - - input - file path / to / file Perintah Jalankan Sampel:
poetry run pypicount - - class - with - docstrings - - input - file tests / input / sample_file . pyOutput sampel:
# of functions with docstrings: 1