Skip to content

Commit

Permalink
Merge pull request #11 from dbrembilla/master
Browse files Browse the repository at this point in the history
Updated Ramose to 1.0.5 - corrected bugs, dependency problems, added tests
  • Loading branch information
dbrembilla authored Jun 11, 2022
2 parents ea64a24 + 2f9a5c0 commit 81788b9
Show file tree
Hide file tree
Showing 37 changed files with 1,828 additions and 71 deletions.
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

0 comments on commit 81788b9

Please sign in to comment.