Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Ramose to 1.0.5 - corrected bugs, dependency problems, added tests #11

Merged
merged 55 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c6a6b83
start
dbrembilla Jun 3, 2022
5356a48
Merge pull request #1 from dbrembilla/updating_tests
dbrembilla Jun 3, 2022
3809cda
gitignore
dbrembilla Jun 3, 2022
b1b5370
up
dbrembilla Jun 3, 2022
610693a
up
dbrembilla Jun 4, 2022
d0bb029
tests
dbrembilla Jun 4, 2022
66ee2f4
testing
dbrembilla Jun 4, 2022
32cf526
req
dbrembilla Jun 4, 2022
fa77306
Merge pull request #2 from dbrembilla/updating_tests
dbrembilla Jun 4, 2022
ef87a17
update workflow
dbrembilla Jun 4, 2022
4936a8a
Update python-package.yml
dbrembilla Jun 4, 2022
15e3a5e
dependencies
dbrembilla Jun 4, 2022
1420358
Merge pull request #3 from dbrembilla/updating_tests
dbrembilla Jun 4, 2022
faed0be
Update python-package.yml
dbrembilla Jun 4, 2022
be1c106
up
dbrembilla Jun 4, 2022
5a36a21
Merge pull request #4 from dbrembilla/updating_tests
dbrembilla Jun 4, 2022
adeecbb
up
dbrembilla Jun 4, 2022
98113b7
Merge pull request #5 from dbrembilla/updating_tests
dbrembilla Jun 4, 2022
be6af63
UP
dbrembilla Jun 4, 2022
04710fb
Merge pull request #6 from dbrembilla:updating_tests
dbrembilla Jun 4, 2022
1251fb4
up
dbrembilla Jun 5, 2022
519e268
Update python-package.yml
dbrembilla Jun 5, 2022
9825eb3
updated tests and correction of small bugs
dbrembilla Jun 10, 2022
a6e3aa6
Merge remote-tracking branch 'upstream/master' into updating_tests
dbrembilla Jun 10, 2022
fdb20cd
updated lock
dbrembilla Jun 10, 2022
26f18c3
solved errors in tests
dbrembilla Jun 10, 2022
ac2e204
encoding problems
dbrembilla Jun 10, 2022
c5b486d
encoding error -2
dbrembilla Jun 10, 2022
d6a4522
encoding error - 3
dbrembilla Jun 10, 2022
90f1f88
solved encoding problems
dbrembilla Jun 10, 2022
308765f
up
dbrembilla Jun 10, 2022
b73c1f9
Update README.md
dbrembilla Jun 10, 2022
d6ab93d
Update README.md
dbrembilla Jun 10, 2022
36c4d9d
Update README.md
dbrembilla Jun 10, 2022
331eeeb
Update README.md
dbrembilla Jun 10, 2022
eeafe0d
coverage
dbrembilla Jun 10, 2022
ebb7235
Update README.md
dbrembilla Jun 10, 2022
fac4ebd
Update README.md
dbrembilla Jun 10, 2022
44b52fd
Update README.md
dbrembilla Jun 10, 2022
9010317
coverage
dbrembilla Jun 10, 2022
5da298a
Merge branch 'updating_tests' of https://github.com/dbrembilla/ramose…
dbrembilla Jun 10, 2022
c323835
finally added coverage badge
dbrembilla Jun 10, 2022
6e7e990
Merge pull request #7 from dbrembilla/updating_tests
dbrembilla Jun 10, 2022
6e589b3
debug test calls
dbrembilla Jun 10, 2022
127fc0f
Merge pull request #8 from dbrembilla/updating_tests
dbrembilla Jun 10, 2022
b21ccc5
debug test_calls_2
dbrembilla Jun 10, 2022
c04a9c0
Merge pull request #9 from dbrembilla/updating_tests
dbrembilla Jun 10, 2022
dea48ce
added sleep
dbrembilla Jun 10, 2022
ac63c91
Merge pull request #10 from dbrembilla/updating_tests
dbrembilla Jun 10, 2022
62c053b
changes to avoid blocking from APIs
dbrembilla Jun 10, 2022
e481b3f
Merge pull request #11 from dbrembilla/updating_tests
dbrembilla Jun 10, 2022
60d095b
Update python-package.yml
dbrembilla Jun 10, 2022
289db68
solved 3.10 bug
dbrembilla Jun 11, 2022
67e7465
Merge pull request #12 from dbrembilla/updating_tests
dbrembilla Jun 11, 2022
2f9a5c0
Update python-package.yml
dbrembilla Jun 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9","3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Test with pytest
run: |
poetry run python -u -m unittest discover
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
ramose.log*
__pycache__/
__pycache__/
test/Scripts/
test/Include/
test/Lib/
test/__pycache__
Include/
Scripts/
Lib/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Python package](https://github.com/dbrembilla/ramose/actions/workflows/python-package.yml/badge.svg)](https://github.com/dbrembilla/ramose/actions/workflows/python-package.yml)
[![Coverage](./test/coverage/coverage.svg)](https://github.com/dbrembilla/ramose/actions/workflows/python-package.yml)
# Restful API Manager Over SPARQL Endpoints (RAMOSE)

Restful API Manager Over SPARQL Endpoints (RAMOSE) is an application that allows agile development and publication of documented RESTful APIs for querying SPARQL endpoints, according to a particular specification document.
Expand Down
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
383 changes: 383 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tool.poetry]
name = "ramose"
version = "1.0.5"
description = "Restful API Manager Over SPARQL Endpoints (RAMOSE) is an application that allows agile development and publication of documented RESTful APIs for querying SPARQL endpoints, according to a particular specification document."
authors = ["essepuntato <[email protected]>"]
license = "ISC"
repository = "https://github.com/opencitations/ramose/"

[tool.poetry.dependencies]
python="^3.7"
certifi="2019.11.28"
chardet="3.0.4"
Click="7.0"
Flask="1.1.1"
idna="2.8"
isodate="0.6.1"
itsdangerous="1.1.0"
Jinja2="2.11.3"
Markdown="3.1.1"
MarkupSafe="1.1.1"
python-dateutil="2.8.1"
requests="^2.22.0"
six="1.13.0"
urllib3="1.26.5"
Werkzeug="0.16.0"
rdflib= "6.1.1"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
3 changes: 3 additions & 0 deletions pyvenv.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
home = C:\Users\david\AppData\Local\Programs\Python\Python39
include-system-site-packages = false
version = 3.9.9
35 changes: 21 additions & 14 deletions ramose.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.

Expand All @@ -36,8 +36,11 @@
from argparse import ArgumentParser
from os.path import abspath, dirname, basename
from os import path as pt
import logging
from os import sep, getcwd

import logging
from flask import Flask, request , make_response, send_from_directory
from werkzeug.exceptions import HTTPException

FIELD_TYPE_RE = "([^\(\s]+)\(([^\)]+)\)"
PARAM_NAME = "{([^{}\(\)]+)}"
Expand All @@ -61,7 +64,7 @@ def read(self, file_path):
Hash Format, and returns its representation as list of dictionaries."""
result = []

with open(file_path, "r", newline=None) as f:
with open(file_path, "r", newline=None, encoding = 'utf8') as f:
first_field_name = None
cur_object = None
cur_field_name = None
Expand Down Expand Up @@ -592,7 +595,7 @@ def __css(self):
padding: 0.2em 0.5em;
border-top: solid 1px #F8F8F8;
}
}


.date_log , .method_log {
color: grey;
Expand Down Expand Up @@ -751,8 +754,8 @@ def get_index(self, css_path=None):

def store_documentation(self, file_path, css_path=None):
"""This method stores the HTML documentation of an API in a file."""
html = self.get_documentation(css_path)
with open(file_path, "w") as f:
html = self.get_documentation(css_path)[1]
with open(file_path, "w+", encoding='utf8') as f:
f.write(html)

def clean_log(self, l, api_url):
Expand Down Expand Up @@ -1248,21 +1251,27 @@ def type_fields(self, res, op_item):
header = res[0]
for heading in header:
cast_func[heading] = DataType.str


if "field_type" in op_item:
for f, p in findall(FIELD_TYPE_RE, op_item["field_type"]):
cast_func[p] = self.dt.get_func(f)

first = True
for row in res[1:]:
new_row = []
for idx in range(len(header)):

heading = header[idx]
cur_value = row[idx]
if type(cur_value) is tuple:
cur_value = cur_value[1]
if heading == 'timespan' and first:
first = False
new_row.append((cast_func[heading](cur_value), cur_value))
result.append(new_row)


result.append(new_row)

return [header] + result

def remove_types(self, res):
Expand Down Expand Up @@ -1457,7 +1466,7 @@ def nor_api_url(i, b=""):
def best_match(self, u):
"""This method takes an URL of an API call in input and find the API operation URL and the related
configuration that best match with the API call, if any."""
#u = u.decode('UTF8') if isinstance(u, (bytes, bytearray)) else u
u = u.decode('UTF8') if isinstance(u, (bytes, bytearray)) else u
cur_u = sub("\?.*$", "", u)
result = None, None
for base_url in self.all_conf:
Expand Down Expand Up @@ -1493,7 +1502,7 @@ def get_op(self, op_complete_url):
# END: Processing methods


if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
arg_parser = ArgumentParser("ramose.py", description="The 'Restful API Manager Over SPARQL Endpoints' (a.k.a. "
"'RAMOSE') is an application that allows one to expose a "
"Restful API interface, according to a particular "
Expand Down Expand Up @@ -1525,9 +1534,7 @@ def get_op(self, op_complete_url):

if args.webserver:
try:
import logging
from flask import Flask, request , make_response, send_from_directory
from werkzeug.exceptions import HTTPException


# logs
dh.logger_ramose()
Expand Down Expand Up @@ -1616,5 +1623,5 @@ def doc(api_url):
if args.output is None:
print("# Response HTTP code: %s\n# Body:\n%s\n# Content-type: %s" % res)
else:
with open(args.output, "w") as f:
with open(args.output, "w", encoding='utf8') as f:
f.write(res[1])
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ chardet==3.0.4
Click==7.0
Flask==1.1.1
idna==2.8
isodate==0.6.0
isodate==0.6.1
itsdangerous==1.1.0
Jinja2==2.11.3
Markdown==3.1.1
MarkupSafe==1.1.1
python-dateutil==2.8.1
requests==2.22.0
requests>=2.22.0, <3.0.0
six==1.13.0
urllib3==1.26.5
Werkzeug==0.16.0
rdflib==6.1.1
Empty file added test/__init__.py
Empty file.
Binary file added test/coverage/.coverage
Binary file not shown.
21 changes: 21 additions & 0 deletions test/coverage/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/pyvenv.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
home = C:\Users\david\AppData\Local\Programs\Python\Python39
include-system-site-packages = false
version = 3.9.9
Loading