Skip to content

Commit

Permalink
Merge pull request #11 from fossology/chore/setup/metainfo
Browse files Browse the repository at this point in the history
chore(setup): Added additional metainfo
  • Loading branch information
hastagAB authored Jul 29, 2020
2 parents 6b44d10 + a260cae commit c6a1a99
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 52 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 nirjas/languages/tests*

include LICENSE

prune .git
prune venv
prune .venv
prune nirjas/languages/tests

74 changes: 37 additions & 37 deletions nirjas/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@
from nirjas.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.3',
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.3',
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='Nirjas,Code Comment, Comment Extractor, Code Comment Extractor, Source Code Extractor, Source Extractor',
packages=find_packages(),
keywords='Nirjas,Code Comment, Comment Extractor, Code Comment Extractor, Source Code Extractor, Source Extractor',
packages=find_packages(),
python_requires = ">=3",
entry_points = {
'console_scripts': [
'nirjas = nirjas.main:main'
]
},
)
'console_scripts': [
'nirjas = nirjas.main:main'
]
},
license = "LGPL-2.1-or-later",
platforms = ['any']
)

0 comments on commit c6a1a99

Please sign in to comment.