Skip to content

Commit

Permalink
chore(setup): Added additional metainfo
Browse files Browse the repository at this point in the history
1. Added metainfo like license and platform to setup.py.
2. Added MANIFEST.in to remove test data from package.
3. New exception NotSupportedExtension to handle files with unknown
   extensions.
4. Remove `cwd` infront of filename.

Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
  • Loading branch information
GMishx committed Jul 29, 2020
1 parent 1c3d5aa commit 064fc58
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 53 deletions.
14 changes: 14 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Manifest syntax https://docs.python.org/3/distutils/sourcedist.html
recursive-exclude __pycache__ *.pyc *.pyo *.orig

exclude *.git*
exclude *.sh
exclude extractor/languages/tests*

include LICENSE

prune .git
prune venv
prune .venv
prune extractor/languages/tests

2 changes: 1 addition & 1 deletion extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
def extract(file):
return file_runner(file)

__all__ = ['file_runner','extract', 'langIdentifier']
__all__ = ['file_runner', 'extract', 'langIdentifier']
74 changes: 37 additions & 37 deletions extractor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@
from extractor.languages import *


class NotSupportedExtension(Exception):
'''
Exception if file extension is not recognized
'''
def __str__(self):
return "extension '" + self.args[0] + "' not supported"


class CommentExtractor:
def __init__(self):
pass

@staticmethod
def langIdentifier(file):
extension = os.path.splitext(file)[1]



langMap = {
'.py': 'python',
'.m4': 'python',
Expand Down Expand Up @@ -75,63 +81,57 @@ def langIdentifier(file):
'.gl': 'text'
}

if extension not in langMap:
raise NotSupportedExtension(extension)
return langMap[extension]


def main():
parser = argparse.ArgumentParser()
parser.add_argument("-p","--path", help="Specify the input file/directory path to scan")
parser.add_argument("-i","--inputFile", help="Specify the input file with the source code")
parser.add_argument("-s","--string",help= "The name of file you want the code in",default="source.txt")
parser.add_argument("-p", "--path", help="Specify the input file/directory path to scan")
parser.add_argument("-i", "--inputFile", help="Specify the input file with the source code")
parser.add_argument("-s", "--string", help="The name of file you want the code in", default="source.txt")
args = parser.parse_args()
file = args.path
inputfile = args.inputFile
string_name = args.string
if file:
file_runner(file)
else:
inputfile_runner(inputfile,string_name)
try:
if file:
return file_runner(file)
else:
return inputfile_runner(inputfile, string_name)
except NotSupportedExtension as e:
print(e, file=os.sys.stderr)




def file_runner(file):
result = []
if os.path.basename(file):
file_name = os.path.basename(file)
current_path = os.getcwd()+'/'+file
langname = CommentExtractor.langIdentifier(file_name)
func = langname+'.'+langname+'Extractor'
output = eval(func)(current_path)
if os.path.isfile(file):
langname = CommentExtractor.langIdentifier(file)
func = langname + '.' + langname + 'Extractor'
output = eval(func)(file)
result.append(output)

elif os.path.dirname(file):
for root,dirs,files in os.walk(file,topdown=True):
elif os.path.isdir(file):
for root, dirs, files in os.walk(file, topdown=True):
for file in files:
current_path = os.path.join(os.path.join(os.getcwd(),root),file)
try:

if os.path.isfile(current_path):
if os.path.isfile(file):
langname = CommentExtractor.langIdentifier(file)
func = langname+'.'+langname+'Extractor'
output = eval(func)(current_path)
func = langname + '.' + langname + 'Extractor'
output = eval(func)(file)
result.append(output)
except Exception:
continue
result = json.dumps(result, sort_keys=False, indent=4)
print(result)
return result



def inputfile_runner(inputfile,string_name):
def inputfile_runner(inputfile, string_name):
langname = CommentExtractor.langIdentifier(inputfile)
func = langname+'.'+langname+'Source'
eval(func)(inputfile,string_name)
# python.pythonSource(inputfile,string_name)

# result = json.dumps(result, sort_keys=False, indent=4)
# print(result)

func = langname + '.' + langname + 'Source'
return eval(func)(inputfile, string_name)


if __name__ == "__main__":
main()
main()
34 changes: 19 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

'''
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com), Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
SPDX-License-Identifier: LGPL-2.1
Expand Down Expand Up @@ -37,22 +39,24 @@


setup(
name='Nirjas',
version='0.0.2',
description='A Python library to extract comments and source code out of your file(s)',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/fossology/nirjas',
author='Ayush Bhardwaj, Kaushlendra Pratap',
author_email='classicayush@gmail.com, kaushlendrapratap.9837@gmail.com',
name='Nirjas',
version='0.0.4',
description='A Python library to extract comments and source code out of your file(s)',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/fossology/nirjas',
author='Ayush Bhardwaj, Kaushlendra Pratap',
author_email='classicayush@gmail.com, kaushlendrapratap.9837@gmail.com',

classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
keywords='Comment Extractor, Code Comment Extractor, Source Code Extractor, Source Extractor',
packages=find_packages(),
keywords='Comment Extractor, Code Comment Extractor, Source Code Extractor, Source Extractor',
packages=find_packages(),
python_requires = ">=3",
entry_points = {
'console_scripts': [
'nirjas = extractor.main:main'
]
},
)
'console_scripts': [
'nirjas = extractor.main:main'
]
},
license = "LGPL-2.1-or-later",
platforms = ['any']
)

0 comments on commit 064fc58

Please sign in to comment.