Skip to content

Commit

Permalink
Merge branch 'release/v0.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed Feb 2, 2022
2 parents 522111f + d78e2a1 commit 4a67f87
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Install is either via pip or cloning the repository.

From pip:
```sh
python3 -m pip install thothlibrary==0.9.1
python3 -m pip install thothlibrary==0.10.0
```

Or from the repo:
Expand All @@ -23,7 +23,7 @@ pip3 install -r ./requirements.txt
```python
from thothlibrary import ThothClient

thoth = ThothClient(version="0.6.0")
thoth = ThothClient()
print(thoth.works())
```

Expand Down Expand Up @@ -90,7 +90,7 @@ python3 -m thothrest.cli work onix_3.0::project_muse e0f748b2-984f-45cc-8b9e-139
```

## Thoth Django
The thothdjango folder includes models, an import routine, subject-code support, and admin procedures to use Thoth in a django app. The import provides unidirectional synchronization from remote Thoth imports to a local database for use in a Django app.
The thothdjango folder includes models, an import routine, subject-code support, and admin procedures to use Thoth in a django app. The import provides unidirectional synchronization from remote Thoth imports to a local database for use in a Django app.

## Test Suite
Tests for GraphQL queries are versioned in the thoth-[ver] folder of thothlibrary.
Expand All @@ -106,4 +106,6 @@ The Thoth API is not yet considered stable and functionality changes between ver
4. Run genjson.sh _only_ from inside the tests directory of the new version. This will fetch the latest server JSON responses and store it inside the fixtures directory for these tests. If there are any errors, then the command line CLI has encountered a breaking change that must first be fixed.
5. Run the test suite for the latest version and examine breakages. It is possible that breakages are not actually full breakdown, but merely a change in the serialized object. Nonetheless, fix these by subclassing the previous versions of the API and overriding broken methods. In the cases of total breakage, a non-subclassed rewrite may be more appropriate. (May also apply at major version breaks.)
6. When the test suite passes, or a new object format has been decided and tests rewritten, run genfixtures.sh to freeze the current test suite.
7. Include the new version directory in the list of packages in `setup.py`
8. Update `THOTH_VERSION` in `thothlibrary/client.py`

2 changes: 1 addition & 1 deletion thothlibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""GraphQL client for Thoth"""

__version__ = "0.9.1"
__version__ = "0.10.0"
__author__ = "Javier Arias <[email protected]>"
__copyright__ = "Copyright (c) 2020 Open Book Publishers"
__license__ = "Apache 2.0"
Expand Down
18 changes: 11 additions & 7 deletions thothlibrary/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
import importlib
import pkgutil

import re
import thothlibrary
from .auth import ThothAuthenticator
from .graphql import GraphQLClientRequests as GraphQLClient
from .mutation import ThothMutation
from .query import ThothQuery
import re

THOTH_ENDPOINT = "https://api.thoth.pub"
THOTH_VERSION = "0.6.0"


class ThothClient:
"""Client to Thoth's GraphQL API"""
QUERIES = {} # populated according to each version's requirements

def __new__(cls, thoth_endpoint="https://api.thoth.pub", version="0.4.2"):
def __new__(cls, thoth_endpoint=THOTH_ENDPOINT, version=THOTH_VERSION):
# this new call is the only bit of "magic"
# it basically subs in the sub-class of the correct version and returns
# an instance of that, instead of the generic class
Expand All @@ -30,9 +34,10 @@ def __new__(cls, thoth_endpoint="https://api.thoth.pub", version="0.4.2"):
version_endpoints = getattr(
endpoints, 'ThothClient{0}'.format(version_replaced))

return version_endpoints(thoth_endpoint=thoth_endpoint, version=version)
return version_endpoints(thoth_endpoint=thoth_endpoint,
version=version)

def __init__(self, thoth_endpoint="https://api.thoth.pub", version="0.4.2"):
def __init__(self, thoth_endpoint=THOTH_ENDPOINT, version=THOTH_VERSION):
"""Returns new ThothClient object at the specified GraphQL endpoint
thoth_endpoint: Must be the full URL (eg. 'http://localhost').
Expand Down Expand Up @@ -142,16 +147,15 @@ def _api_request(self, endpoint_name: str, parameters,
"""
Makes a request to the API
@param endpoint_name: the name of the endpoint
@param return_raw: whether to return the raw data or an object (default)
@param return_raw: whether to return raw data or an object (default)
@param parameters: the parameters to pass to GraphQL
@return: an object or JSON of the request
"""
response = self.query(endpoint_name, parameters, raw=return_raw)

if return_raw:
return response
else:
return self._build_structure(endpoint_name, response)
return self._build_structure(endpoint_name, response)

def _build_structure(self, endpoint_name, data):
"""
Expand Down

0 comments on commit 4a67f87

Please sign in to comment.