Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Merge to master (#542)
* Tutorials folder with a markdown document (#516)

* Added a workflow.md file for tutorials

* Made fixes to WORKFLOW.MD

* Moved the markdown document to docs folder and renamed it to TUTORIALS.md

* Fixed prop_uri typo for dummyProp in doc_writer_sample.py (#524)

* Add missing Drone Collection in the sample APIDOC (#511)

* Added the collections key in the context of sample apidoc

* Added Drone collection in hydra_doc_sample.py

* Added dronecollection in doc_gen.py

* Revert "Add missing Drone Collection in the sample APIDOC (#511)" (#513)

This reverts commit 27b0c36.

* fixed prop_uri in samples

* fixed prop_uri in doc_writer_sample

Co-authored-by: Chris Andrew <chrisandrew119@gmail.com>
Co-authored-by: Samesh Lakhotia <43701530+sameshl@users.noreply.github.com>
Co-authored-by: Ashish Rao <54390491+raoashish10@users.noreply.github.com>
Co-authored-by: Priyanshu Nayan <priyanshunayan456@gmail.com>

* Update ISSUE_TEMPLATE.md (#529)

* Update ISSUE_TEMPLATE.md

* typo fixed.

* typo fixed.

* Configurations renamed to Environment.

* Python 3.8 support  (#531)

* update psycopg2 in requirements.txt
psycopg2 2.8.6 is compatible with python3.8 and below
* update only psycopg2 for poetry
poetry lock updated to use psycopg2~=2.8.6

* Bump gevent version (#537)

* fix: py3.8 gevent greenlet issue

mem size issue in py3.8 resolved requirements.txt

* fix: py3.8 greenlet gevent issue

poetry lock and pyproject update for mem size issue

* added required imports (#541)

* chore: docker file deprecation (#539)

maintainer depreacted for LABEL

* Snapshot field added. (#538)

* Fix issues detected with Static Analyzer (#528)

* Add DeepSource configuration
* Remove unused imports
* Refactor to use empty literals instead of dict, list calls
* Use in to check inclusion

Co-authored-by: Ashish Rao <54390491+raoashish10@users.noreply.github.com>
Co-authored-by: Faraz Khan <farazkhan138@gmail.com>
Co-authored-by: Chris Andrew <chrisandrew119@gmail.com>
Co-authored-by: Samesh Lakhotia <43701530+sameshl@users.noreply.github.com>
Co-authored-by: Priyanshu Nayan <priyanshunayan456@gmail.com>
Co-authored-by: Purvansh Singh <49719371+Purvanshsingh@users.noreply.github.com>
Co-authored-by: Lakshya Singh <lakshay.singh1108@gmail.com>
Co-authored-by: Devdutt Shenoi <devdutt@outlook.in>
  • Loading branch information
9 people authored Jan 10, 2021
commit e15d18e9f7b535814ef3a2f981be443896206adb
13 changes: 13 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version = 1

test_patterns = ["tests/**"]

[[analyzers]]
name = "python"
enabled = true
dependency_file_paths = ["requirements.txt"]

[analyzers.meta]
runtime_version = "3.x.x"
type_checker = "mypy"
max_line_length = 100
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@
### Steps to reproduce:
<!-- If you can then please provide the steps to reproduce the bug -->

### Snapshot:
<!-- If you can then please provide the screenshot of the issue you are facing -->

### Environment:
<!-- Please provide the following environment details -->
* python version
* pip version
* OS details

### Do you want to work on this issue?
<!-- yes/no -->
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ FROM tiangolo/uwsgi-nginx-flask:python3.7
# maybe we want to move to:
# FROM tiangolo/meinheld-gunicorn-flask:python3.6

MAINTAINER Akshay Dahiya <xadahiya@gmail.com>
LABEL maintainer="Akshay Dahiya <xadahiya@gmail.com>"

COPY ./requirements.txt requirements.txt
# install certificates which were not installed in the base image
RUN apt-get update && apt-get install -y ca-certificates
RUN pip install -U pip && pip install --upgrade pip setuptools \
RUN pip install -U pip && pip install --upgrade pip setuptools \
&& pip install -r requirements.txt && rm -rf *

COPY . /app
Expand Down
35 changes: 35 additions & 0 deletions docs/TUTORIALS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# hydrus Workflow

This document can be used to understand how hydrus works. <br>
To understand the concepts related to hydrus:<br>
https://www.hydraecosystem.org/Starting-Material

### How is an ```ApiDoc``` defined:
- There are two ways of defining an ApiDoc:
1. Writing a Hydra-compliant JSON-LD like [here]( https://github.com/HTTP-APIs/hydrus/blob/master/hydrus/samples/doc_writer_sample_output.py)
1. Defining the ApiDoc programmatically using the code like in [here](https://github.com/HTTP-APIs/hydrus/blob/master/hydrus/samples/doc_writer_sample.py)
- Any valid ApiDoc can be passed to the server so that it can parse the doc, generate a database and start the server.
- The document containing the context is generated by the doc_maker file in the hydra_python_core repo. hydrus provides the link in its response for the context.


### Points :
#### Description of some files:
1. hydrus/app.py
1. Used for logging. (Line 22)
1. Starts the SQLAlchemy engine and creates a session (Line 25-26)
1. Creates an Api Documentation using the doc_maker() of hydra_python_core
1. Gets the parsed classes from hydrus/data/doc_parse.py
1. Creates database tables and its metadata Line 34-36
1. Checks if Authentication is True, adds user to the session.Check: https://www.hydraecosystem.org/Auth
1. Calls app_factory class' constructor
1.Sets authentication,api_name,session etc. which can be later retrieved using the corresponding get functions.
1. Runs the API on the Port mentioned.
1. hydrus/app_factory.py
1. Used to add resources to the API from resources.py.
1. Configures properties of API.
1. Enables CORS
1. hydrus/resources.py
1. Contains classes which are added as resources to the API.

1. hydrus/samples/hydra_doc_sample.py
1. This file contains the sample ApiDoc that is displayed when the demo for hydrus is run. It contains the JSON-LD document that is displayed.
4 changes: 4 additions & 0 deletions hydrus/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
FOUND_DOC
"""
import os
import json
import yaml
import logging
from os.path import abspath, dirname
from pathlib import Path
from importlib.machinery import SourceFileLoader
from hydra_openapi_parser.openapi_parser import parse

logger = logging.getLogger(__file__)

try:
Expand Down
4 changes: 2 additions & 2 deletions hydrus/data/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def insert_multiple(objects_: List[Dict[str,
id_list = id_.split(',')

# list to hold all the ids of inserted objects
instance_id_list = list()
instance_id_list = []

for index in range(len(objects_)):
id_of_object_ = None
Expand Down Expand Up @@ -433,7 +433,7 @@ def pagination(filtered_instances, path, type_, API_NAME,
"@id": f"/{API_NAME}/{path}/",
"@context": None,
"@type": f"{path}",
"members": list()
"members": []
} # type: Dict[str, Any]
result_length = len(filtered_instances)
try:
Expand Down
8 changes: 2 additions & 6 deletions hydrus/data/crud_helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# from sqlalchemy.orm.session import Session
from sqlalchemy.orm.scoping import scoped_session

from typing import Dict, Any, Tuple

from sqlalchemy.orm.exc import NoResultFound
from hydrus.data.exceptions import (
PageNotFound,
InvalidSearchParameter,
IncompatibleParameters,
OffsetOutOfRange,
)
Expand All @@ -23,7 +19,7 @@ def recreate_iri(API_NAME: str, path: str, search_params: Dict[str, Any]) -> str
for param in search_params:
# Skip page, pageIndex or offset parameters as they will be updated to point to
# next, previous and last page
if param == "page" or param == "pageIndex" or param == "offset":
if param in ["page", "pageIndex", "offset"]:
continue
iri += f"{param}={search_params[param]}&"
return iri
Expand All @@ -42,7 +38,7 @@ def parse_search_params(search_params: Dict[str, Any]) -> Dict[str, Any]:
prop_name = split_param_list[0]
nested_prop_name = split_param_list[1].split(']')[0]
if prop_name not in search_params:
search_params[prop_name] = dict()
search_params[prop_name] = {}
search_params[prop_name][nested_prop_name] = value
search_params.pop(param)
# For normal parameters
Expand Down
5 changes: 1 addition & 4 deletions hydrus/data/doc_parse.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Parser for Hydra APIDocumentation creates Classes and Properties."""
from sqlalchemy import exists

from typing import Any, Dict, List, Set, Optional
from sqlalchemy.orm.session import Session
from sqlalchemy.orm import scoped_session
from hydra_python_core.doc_writer import HydraDoc


Expand All @@ -12,7 +9,7 @@ def get_classes(apidoc: HydraDoc) -> List[Dict[str, Any]]:
COLLECTION_ID = "http://www.w3.org/ns/hydra/core#Collection"
RESOURCE_ID = "http://www.w3.org/ns/hydra/core#Resource"
ENTRYPOINT_ID = apidoc.entrypoint.entrypoint.id_
classes = list()
classes = []
for class_ in apidoc.generate()["supportedClass"]:
if class_["@id"] not in [COLLECTION_ID, RESOURCE_ID, ENTRYPOINT_ID]:
classes.append(class_)
Expand Down
2 changes: 1 addition & 1 deletion hydrus/data/resource_based_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_object(
)
if len(objects) == 0:
raise InstanceNotFound(type_=type_, id_=id_)
object_template = dict()
object_template = {}
object_template["@type"] = query_info["@type"]
object_template["members"] = objects
return object_template
Expand Down
5 changes: 0 additions & 5 deletions hydrus/item_collection_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
ClassNotFound,
InstanceExists,
PropertyNotFound,
InstanceNotFound,
PageNotFound,
InvalidSearchParameter,
OffsetOutOfRange,
Expand All @@ -22,12 +21,8 @@
set_response_headers,
getType,
hydrafy,
check_writeable_props,
add_iri_template,
finalize_response,
get_link_props,
error_response,
send_update,
validate_object,
parse_collection_members,
)
Expand Down
2 changes: 0 additions & 2 deletions hydrus/itemhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
finalize_response,
hydrafy,
getType,
validObject,
check_required_props,
send_sync_update,
get_link_props,
error_response,
Expand Down
3 changes: 1 addition & 2 deletions hydrus/items_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)
from hydrus.utils import (
get_session,
get_doc,
get_api_name,
get_hydrus_server_url,
get_collections_and_parsed_classes
Expand All @@ -47,7 +46,7 @@ def items_put_response(path: str, int_list="") -> Response:
if path in parsed_classes:
class_path = path
obj_type = getType(path, "PUT")
incomplete_objects = list()
incomplete_objects = []
for obj in object_:
if not check_required_props(class_path, obj):
incomplete_objects.append(obj)
Expand Down
5 changes: 2 additions & 3 deletions hydrus/samples/doc_writer_sample.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Sample to create Hydra APIDocumentation using doc_writer."""

from hydra_python_core.doc_writer import (HydraDoc, HydraClass, HydraClassProp, HydraClassOp,
HydraStatus, HydraError, HydraLink,HydraCollection)
HydraStatus, HydraLink,HydraCollection)
from typing import Any, Dict, Union
from urllib.parse import urljoin

# Creating the HydraDoc object, this is the primary class for the Doc
API_NAME = "api" # Name of the API, will serve as EntryPoint
Expand Down Expand Up @@ -88,7 +87,7 @@
prop2_uri = "http://props.hydrus.com/prop2"
prop2_title = "Prop2"

dummyProp2 = HydraClassProp(prop1_uri, prop2_title,
dummyProp2 = HydraClassProp(prop2_uri, prop2_title,
required=False, read=False, write=True)
# NOTE: Properties that are required=True must be added during class object creation
# Properties that are read=True are read only
Expand Down
6 changes: 3 additions & 3 deletions hydrus/samples/doc_writer_sample_output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Generated API Documentation sample using doc_writer_sample.py."""

doc = {
"@context": {
"ApiDocumentation": "hydra:ApiDocumentation",
Expand Down Expand Up @@ -157,7 +157,7 @@
},
{
"@type": "SupportedProperty",
"property": "http://props.hydrus.com/prop1",
"property": "http://props.hydrus.com/prop2",
"readable": "false",
"required": "false",
"title": "Prop2",
Expand Down Expand Up @@ -263,7 +263,7 @@
},
{
"@type": "SupportedProperty",
"property": "http://props.hydrus.com/prop1",
"property": "http://props.hydrus.com/prop2",
"readable": "false",
"required": "false",
"title": "Prop2",
Expand Down
Loading