File: pyedit-products/unzipped/__sloc__.py

#!/usr/bin/python3
"""
simple source-code line count script, used for dev metrics only [2.2]
"""
import os, glob, sys
srcenc = 'utf8'          # allow for Unicode source files

def collect(paths):
    manifest = []
    for path in paths:
        manifest += glob.glob(path.replace('/', os.sep))
    return manifest

# the basics 
sources = ('*.py', '*.pyw', '*.bat')    # files here

# imported tools from PP4E, many updated much for 2.2
pkg = '../../..'
sources += (
           pkg + '/PP4E/Gui/Tools/guimaker.py',     # menus, toolbars
           pkg + '/PP4E/Gui/ShellGui/formrows.py',  # input fields
           pkg + '/PP4E/Gui/Tour/scrolledlist.py',  # grep list 
           pkg + '/PP4E/Tools/find.py',             # grep walk
           pkg + '/PP4E/launchmodes.py'             # run code exec
           )

# app/exe/src build scripts count too (but skip iconify.py and tools/)
sources += ('build/build-app-exe/build4.0/*.py',)
sources += ('build/build-source/*.py',)

# skip generated pyinstaller or py2app stdlib module list files
skips = ('setup.py', 'hook-os.py')
                     
tally = count = 0
for fname in collect(sources):                   # used files in this tree
    if (not fname.startswith('__') and           # skip self and extras in '.'
        not fname.endswith(skips)):              # skip generated stdlib lists         
        fobj = open(fname, encoding=srcenc)      # else do os.path.basename()
        lcnt = len(fobj.readlines())
        tally += lcnt
        count += 1
        print(f'{fname} => {lcnt:,}')
        
print(f'Total sloc in {count} files (sans docs): {tally:,}')
if sys.platform.startswith('win'):
    input('Press Enter')  # if clicked on Windows


"""
================================================================================
Example output (current counts/manifest):

textEditor.py => 6,742
multiprocessing_exe_patch.py => 180
fixfrozenpaths.py => 453
subprocproxy.py => 415
textConfig.py => 917
textEditorNoConsole.pyw => 12
pyedit.bat => 27
../../../PP4E/Gui/Tools/guimaker.py => 730
../../../PP4E/Gui/ShellGui/formrows.py => 71
../../../PP4E/Gui/Tour/scrolledlist.py => 62
../../../PP4E/Tools/find.py => 35
../../../PP4E/launchmodes.py => 632
build/build-app-exe/build4.0/build.py => 894
build/build-app-exe/build4.0/_winver-maker.py => 23
build/build-app-exe/build4.0/include-full-stdlib.py => 116
build/build-source/build.py => 113
Total sloc in 16 files (sans docs): 11,422

================================================================================
"""



[Home page] Books Code Blog Python Author Train Find ©M.Lutz