Skip to content

Commit

Permalink
small fixes to LOCCounter. Added files needed to make this a package …
Browse files Browse the repository at this point in the history
…on pypi
  • Loading branch information
BryceV committed Nov 7, 2019
1 parent ab0bd93 commit 3d3adc1
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 4 deletions.
17 changes: 17 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MIT License
Copyright (c) 2018 YOUR NAME
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# python-loc-counter

This python-loc-counter module was built to count various LOC metrics:
- source_loc
- single_comment_loc
- single_docstring_loc
- double_docstring_loc
- total_comments_loc
- blank_loc
- total_line_count

### Installation
This package only uses the standard libaries. Pip install instuctions coming...

```sh
$ cd test
```

### Development
See a feature or found a bug? Feel free to make suggestions or (better yet) contributions for future iterations!

### Example Projects
- Originally this module was built for: https://github.com/bcdasilv/code-style-mining/tree/python_analysis.
8 changes: 4 additions & 4 deletions LOCCounter.py → python_loc_counter/LOCCounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LOCCounter:

def __init__(self, file):
self.file = file
__calcLOC()
self.__calcLOC()

__source_loc = 0
__single_comment_loc = 0
Expand Down Expand Up @@ -51,8 +51,8 @@ def getLOC(self):
}
"""

return {"source_loc": self.__source_loc, "single_comments_loc": self.__single_comments_loc,
"single_docstring_loc": single_docstring_loc, "double_docstring_loc": self.__double_docstring_loc,
return {"source_loc": self.__source_loc, "single_comments_loc": self.__single_comment_loc,
"single_docstring_loc": self.__single_docstring_loc, "double_docstring_loc": self.__double_docstring_loc,
"total_comments_loc": self.__total_comments_loc, "blank_loc": self.__blank_loc,
"total_line_count": self.__total_line_count}

Expand Down Expand Up @@ -80,7 +80,7 @@ def __calcLOC(self):
continue

#Remove quotes for some comment analysis
l = re.sub(r"(\"\"\")|(''')|((\"|').*?\4)", __choseRegexGroups, line)
l = re.sub(r"(\"\"\")|(''')|((\"|').*?\4)", self.__choseRegexGroups, line)
#print(repr(l))

inDoubleDoc = inDoubleDoc if (l.count('"""')%2 == 0) else not inDoubleDoc
Expand Down
1 change: 1 addition & 0 deletions python_loc_counter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from python_loc_counter.LOCCounter import LOCCounter
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
21 changes: 21 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from distutils.core import setup
setup(
name = 'python_loc_counter',
packages = ['python_loc_counter'],
version = '0.1',
license='MIT',
description = 'Get LOC metrics for python scripts',
author = 'Bryce Vonilten',
author_email = '[email protected]',
url = 'https://github.com/BryceV/python_loc_counter',
download_url = '',
keywords = ['python', 'lines of code', 'loc'],
install_requires=[ ],
classifiers=[
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.7',
],
)
Empty file added tests/__init__.py
Empty file.
Binary file added tests/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added tests/__pycache__/test.cpython-37.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from python_loc_counter import LOCCounter

def main():
file = "./tests/randomFile.txt"
counter = LOCCounter(file)

print(counter.getLOC())
print(counter.getSourceLOC())
print(counter.getSingleCommentsLOC())
print(counter.getSingleDocstringLOC())
print(counter.getDoubleDocstringLOC())
print(counter.getTotalCommentsLOC())
print(counter.getBlankLinesLOC())
print(counter.getTotalLineCountLOC())

main()

0 comments on commit 3d3adc1

Please sign in to comment.