Package: linestats
linestatsEver wanted/needed to know how many lines are empty, comments, docstrings or actual code in some Python scripts of yours ?Presentinglinestats: a small Python module to count the number of scripted, commented, docstringed, and empty lines in Python code. Here is what linestats containsandwhat it does:linestats.txtTable of contentsInstallationRunningLimitationsChangelogInstallationlinestats is available on pypi. The following command should take care of things:pip install linestatsAlternatively, you can also get the code from itsdedicated Github repository.RunningUsing linestats is fairly straightforward. You can do so (1) in any decent terminal using the in-built entry point, or (2) from within a Python shell by importing the corresponding module. Both methods are the same, and here's how they work:from a terminal: The basic syntax islinestats -p some/path/to/dir/or/file.pyThis will process thefile.py(or all.pyfile located at the indicated location, if a directory is specified). The other options are:-hfor help,-rto run a recursive search for.pyfiles in subfolders,-s output_file.txtto save the statistics to file instead ofsys.stdout,-vto print the linestats version, and-wto print detailed info for every file.from a Python script/shell:importlinestatsfrompathlibimportPathp=Path('some','path','to','dir','or','file.py')s=Path('.','output_file.py')linestats.extract_line_stats(p,recursive=True,save_to_file=s,verbose=False)Limitationslinestats is extremely basic, and the output should be largely self-explanatory. Still, here are a few aspects to keep in mind when using this code:linestats will only process.pyfiles. At present, there is no way to force the processing of other file types.The different lines are counted in the following category order:docstrings -> comments -> emtpy -> code.
Each step feeds the following only with the lines that do not belong to it. This implies, for example, thatan empty line inside a docstring is counted as a docstring line,a docstring line starting with#is also counted as a docstring line,a = 4 # A comment on the same line as codewould be counted as a code line, andeach line belongs to a single category, is counted once only, so the sum of all the categories adds up to 100%.ChangelogSeehere.Information for dev workCode of conductThis project and everyone participating in it is governed by thelinestats Code of Conduct. By participating, you are expected to uphold this code.
Please report unacceptable behavior tofrederic.vogt@alumni.anu.edu.au.Branching modelThedevelopbranch is the default one, where all contributions get merged. When a new release is
warranted, a Pull Request to themasterbranch is issued. This implies that themasterbranch
will always reflect the state of the latest release of the code.Contributors are required to work in their own branches, and issue Pull Requests into thedevelopbranch when appropriate.Themasteranddevelopbranches are protected.CI/CDAutomated CI/CD checks are triggered upon Pull Requests being issued towards thedevelopandmasterbranches. At the time being, they are implemented using dedicated Github Actions specified under.github/workflows. These checks include:code linting usingpylintcode testing usingpytestcheck that the CHANGELOG was updatedcheck that the code version was incremented (for PR tomasteronly)Release mechanismAssuming the content ofdevelopis ready for a release, here are the steps to follow:Issue a PR fromdevelopintomaster. Merge it if all looks ok.:white_check_mark: TheCI_check_versionAction will run to check that the version has been increased.Create a new release from Github. This step has not been automated yet. Make sure to enter the
same version number as set in the code !:white_check_mark: Upon publication of the release, theCI_pypiAction will directly upload the code
to testpypi and pypi. Make sure it succeeds !