Skip to content

Commit efd37e4

Browse files
authored
Merge pull request #35 from unlv-evol/dev
PATCH-001: Major updates
2 parents 0231f4e + 27a6a09 commit efd37e4

27 files changed

+405
-98
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ count = True
44
statistics = True
55
; max-line-length = 150
66
ignore = E501
7-
exclude = .github,venv,build,dist,docs,.venv,src/tests,src/PyReprism/languages/__init__.py
7+
exclude = .github,venv,build,dist,docs,.venv,src/tests,src/PyReprism/languages/__init__.py,__test__.py

.github/workflows/publish.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish Python 🐍 distributions 📦 to PyPI
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
branches:
7+
- main
8+
- stable
9+
10+
jobs:
11+
publish:
12+
name: "Build and upload to pypi"
13+
runs-on: "ubuntu-latest"
14+
# environment:
15+
# name: pypi
16+
# url: https://pypi.org/project/PyReprism/
17+
# permissions:
18+
# id-token: write
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Install python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: '3.11'
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install hatchling twine
30+
- name: Build app
31+
run: |
32+
hatch build
33+
- name: Publish distribution 📦 to PyPI
34+
if: startsWith(github.ref, 'refs/tags')
35+
uses: pypa/gh-action-pypi-publish@release/v1
36+
with:
37+
password: ${{ secrets.PYPI_API_TOKEN }}
38+
# run: twine upload dist/*

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B46484%2Fgithub.com%2Funlv-evol%2FPyReprism.svg?type=shield&issueType=security)](https://app.fossa.com/projects/custom%2B46484%2Fgithub.com%2Funlv-evol%2FPyReprism?ref=badge_shield&issueType=security)
55
[![Documentation Status](https://readthedocs.org/projects/pyreprism/badge/?version=latest)](https://pyreprism.readthedocs.io/en/latest/?badge=latest)
66
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/PyReprism)
7-
[![codecov](https://codecov.io/gh/unlv-evol/PyReprism/graph/badge.svg?token=J2JV31837H)](https://codecov.io/gh/unlv-evol/PyReprism)
7+
<!-- [![codecov](https://codecov.io/gh/unlv-evol/PyReprism/graph/badge.svg?token=J2JV31837H)](https://codecov.io/gh/unlv-evol/PyReprism) -->
88

99
# PyReprism
1010

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "PyReprism"
7-
version = "0.0.2"
87
authors = [
98
{ name= "UNLV EVOL LAB", email="[email protected]" },
109
]
@@ -25,6 +24,9 @@ classifiers = [
2524
"Operating System :: OS Independent",
2625
]
2726

27+
[tool.hatch.version.sources.git]
28+
tag-pattern = "v*"
29+
2830
[tool.hatch.build.targets.wheel]
2931
packages = ["src/PyReprism"]
3032

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ pytest
22
flake8
33
pytest-cov
44
build
5-
twine
5+
twine
6+
hatchling

src/PyReprism/languages/_base.py

-29
This file was deleted.

src/PyReprism/languages/abap.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class Abap:
6-
def __init__():
6+
def __init__(self):
77
pass
88

99
@staticmethod
@@ -36,14 +36,14 @@ def keywords_regex():
3636
return re.compile(r'\b(' + '|'.join(Abap.keywords()) + r')\b')
3737

3838
@staticmethod
39-
def remove_comments(source_code: str, isList: bool = False) -> str:
39+
def remove_comments(source_code: str) -> str:
4040
result = []
4141
for match in Abap.comment_regex().finditer(source_code):
4242
if match.group('noncomment'):
4343
result.append(match.group('noncomment'))
44-
if isList:
45-
return result
46-
return ''.join(result)
44+
# if isList:
45+
# return result
46+
return ''.join(result).strip()
4747

4848
@staticmethod
4949
def remove_keywords(source: str):

src/PyReprism/languages/actionscript.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class ActionScript:
6-
def __init__():
6+
def __init__(self):
77
pass
88

99
@staticmethod
@@ -17,7 +17,7 @@ def keywords() -> list:
1717

1818
@staticmethod
1919
def comment_regex():
20-
pattern = re.compile(r'(?P<comment>^\*.*?$|".*?$|\(\*[\s\S]*?\*\)|\(\*.*?$|^.*?\*\))|(?P<noncomment>\'(\\.|[^\\\'])*\'|"(\\.|[^\\"])*"|.[^*"\'"]*)', re.DOTALL | re.MULTILINE)
20+
pattern = re.compile(r'(?P<comment>//.*?$|/\*[^*]*\*+(?:[^/*][^*]*\*+)*?/)|(?P<noncomment>[^/]+)', re.DOTALL | re.MULTILINE)
2121
return pattern
2222

2323
@staticmethod
@@ -35,14 +35,8 @@ def keywords_regex():
3535
return re.compile(r'\b(' + '|'.join(ActionScript.keywords()) + r')\b')
3636

3737
@staticmethod
38-
def remove_comments(source_code: str, isList: bool = False) -> str:
39-
result = []
40-
for match in ActionScript.comment_regex().finditer(source_code):
41-
if match.group('noncomment'):
42-
result.append(match.group('noncomment'))
43-
if isList:
44-
return result
45-
return ''.join(result)
38+
def remove_comments(source_code: str) -> str:
39+
return ActionScript.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
4640

4741
@staticmethod
4842
def remove_keywords(source: str):

src/PyReprism/languages/c.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def keywords() -> list:
1717

1818
@staticmethod
1919
def comment_regex():
20-
pattern = re.compile(r'(?P<comment>//.*?$|/\*.*?\*/|/\*.*?$|^.*?\*/|[{}]+)|(?P<noncomment>\'(\\.|[^\\\'])*\'|"(\\.|[^\\"])*"|.[^/\'"{}]*)', re.DOTALL | re.MULTILINE)
20+
pattern = re.compile(r'(?P<comment>//.*?$|/\*[^*]*\*+(?:[^/*][^*]*\*+)*?/)|(?P<noncomment>[^/]+)', re.DOTALL | re.MULTILINE)
2121
return pattern
2222

2323
@staticmethod
@@ -35,14 +35,8 @@ def keywords_regex():
3535
return re.compile(r'\b(' + '|'.join(C.keywords()) + r')\b')
3636

3737
@staticmethod
38-
def remove_comments(source_code: str, isList: bool = False) -> str:
39-
result = []
40-
for match in C.comment_regex().finditer(source_code):
41-
if match.group('noncomment'):
42-
result.append(match.group('noncomment'))
43-
if isList:
44-
return result
45-
return ''.join(result)
38+
def remove_comments(source_code: str) -> str:
39+
return C.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
4640

4741
@staticmethod
4842
def remove_keywords(source: str):

src/PyReprism/languages/cpp.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class CPP:
6-
def __init__():
6+
def __init__(self):
77
pass
88

99
@staticmethod
@@ -17,7 +17,7 @@ def keywords() -> list:
1717

1818
@staticmethod
1919
def comment_regex():
20-
pattern = re.compile(r'(?P<comment>//.*?$|/\*.*?\*/|/\*.*?$|^.*?\*/|[{}]+)|(?P<noncomment>\'(\\.|[^\\\'])*\'|"(\\.|[^\\"])*"|.[^/\'"{}]*)', re.DOTALL | re.MULTILINE)
20+
pattern = re.compile(r'(?P<comment>//.*?$|/\*[^*]*\*+(?:[^/*][^*]*\*+)*?/)|(?P<noncomment>[^/]+)', re.DOTALL | re.MULTILINE)
2121
return pattern
2222

2323
@staticmethod
@@ -35,14 +35,8 @@ def keywords_regex():
3535
return re.compile(r'\b(' + '|'.join(CPP.keywords()) + r')\b')
3636

3737
@staticmethod
38-
def remove_comments(source_code: str, isList: bool = False) -> str:
39-
result = []
40-
for match in CPP.comment_regex().finditer(source_code):
41-
if match.group('noncomment'):
42-
result.append(match.group('noncomment'))
43-
if isList:
44-
return result
45-
return ''.join(result)
38+
def remove_comments(source_code: str) -> str:
39+
return CPP.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
4640

4741
@staticmethod
4842
def remove_keywords(source: str):

src/PyReprism/languages/django.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class Django:
6-
def __init__():
6+
def __init__(self):
77
pass
88

99
@staticmethod
@@ -22,7 +22,7 @@ def functions() -> list:
2222

2323
@staticmethod
2424
def comment_regex():
25-
pattern = re.compile(r'(?P<comment>\{#.*?#\})|(?P<noncomment>[^{]*[^\n]*)', re.DOTALL | re.MULTILINE)
25+
pattern = re.compile(r'(?P<comment>#.*?$)|'r'(?P<multilinecomment1>""".*?""")|'r'(?P<multilinecomment2>\'\'\'.*?\'\'\')|'r'(?P<noncomment>\'(\\.|[^\\\'])*\'|"(\\.|[^\\"])*"|.[^#\'"]*)', re.DOTALL | re.MULTILINE)
2626
return pattern
2727

2828
@staticmethod
@@ -40,14 +40,8 @@ def keywords_regex():
4040
return re.compile(r'\b(' + '|'.join(Django.keywords()) + r')\b')
4141

4242
@staticmethod
43-
def remove_comments(source_code: str, isList: bool = False) -> str:
44-
result = []
45-
for match in Django.comment_regex().finditer(source_code):
46-
if match.group('noncomment'):
47-
result.append(match.group('noncomment'))
48-
if isList:
49-
return result
50-
return ''.join(result)
43+
def remove_comments(source_code: str) -> str:
44+
return Django.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
5145

5246
@staticmethod
5347
def remove_keywords(source: str):

src/PyReprism/languages/html.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,11 @@ def operator_regex():
3232

3333
@staticmethod
3434
def keywords_regex():
35-
return re.compile(r'\b(' + '|'.HTMLoin(HTML.keywords()) + r')\b')
35+
return re.compile(r'\b(' + '|'.join(HTML.keywords()) + r')\b')
3636

3737
@staticmethod
38-
def remove_comments(source_code: str, isList: bool = False) -> str:
39-
result = []
40-
for match in HTML.comment_regex().finditer(source_code):
41-
if match.group('noncomment'):
42-
result.append(match.group('noncomment'))
43-
if isList:
44-
return result
45-
return ''.HTMLoin(result)
38+
def remove_comments(source_code: str) -> str:
39+
return HTML.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
4640

4741
@staticmethod
4842
def remove_keywords(source: str):

src/PyReprism/languages/java.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class Java:
6-
def __init__():
6+
def __init__(self):
77
pass
88

99
@staticmethod
@@ -17,7 +17,7 @@ def keywords() -> list:
1717

1818
@staticmethod
1919
def comment_regex():
20-
pattern = re.compile(r'(?P<comment>//.*?$|/\*.*?\*/|/\*.*?$|^.*?\*/|[{}]+)|(?P<noncomment>\'(\\.|[^\\\'])*\'|"(\\.|[^\\"])*"|.[^/\'"{}]*)', re.DOTALL | re.MULTILINE)
20+
pattern = re.compile(r'(?P<comment>//.*?$|/\*[^*]*\*+(?:[^/*][^*]*\*+)*?/)|(?P<noncomment>[^/]+)', re.DOTALL | re.MULTILINE)
2121
return pattern
2222

2323
@staticmethod
@@ -35,15 +35,9 @@ def keywords_regex():
3535
return re.compile(r'\b(' + '|'.join(Java.keywords()) + r')\b')
3636

3737
@staticmethod
38-
def remove_comments(source_code: str, isList: bool = False) -> str:
39-
result = []
40-
for match in Java.comment_regex().finditer(source_code):
41-
if match.group('noncomment'):
42-
result.append(match.group('noncomment'))
43-
if isList:
44-
return result
45-
return ''.join(result)
38+
def remove_comments(source_code: str) -> str:
39+
return Java.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
4640

4741
@staticmethod
4842
def remove_keywords(source: str):
49-
return re.sub(re.compile(Java.keywords_regex()), '', source)
43+
return re.sub(re.compile(Java.keywords_regex()), '', source).strip()

src/PyReprism/languages/python.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class Python:
6-
def __init__():
6+
def __init__(self):
77
pass
88

99
@staticmethod

src/tests/languages/test_abap.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from PyReprism.languages.abap import Abap
2+
import pytest
3+
4+
class TestAbap:
5+
@staticmethod
6+
def test_instance_creation():
7+
try:
8+
instance = Abap()
9+
except Exception as e:
10+
pytest.fail(f"Instance creation failed with exception: {e}")
11+
assert isinstance(instance, Abap)
12+
13+
@staticmethod
14+
def test_extension():
15+
ext = Abap.file_extension()
16+
assert ext == ".abap"
17+
18+
@staticmethod
19+
def test_remove_comments():
20+
source_code = '''
21+
* This is a full line comment
22+
DATA: lv_value TYPE i.
23+
" This is an inline comment
24+
lv_value = 42. " Inline comment at the end of a line
25+
WRITE: / 'This is not a comment'.
26+
(* This is a multi-line comment
27+
that spans multiple lines
28+
*)
29+
WRITE: / 'This is also not a comment'.
30+
'''
31+
expected_output = '''
32+
WRITE: / 'This is also not a comment'.
33+
'''
34+
output = Abap.remove_comments(source_code)
35+
36+
assert output == expected_output.strip()
37+
print("Test remove_comments passed!")

0 commit comments

Comments
 (0)