diff --git a/.dependabot/config.yml b/.dependabot/config.yml new file mode 100644 index 0000000..cc1a4ce --- /dev/null +++ b/.dependabot/config.yml @@ -0,0 +1,10 @@ +version: 1 + +update_configs: + - package_manager: "python" + directory: "/python/helpers" + update_schedule: "monthly" + target_branch: "dev" + default_reviewers: + - "albertmeronyo" + - "c-martinez" diff --git a/.travis/install.sh b/.travis/install.sh index 9e2055c..912db12 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -19,8 +19,5 @@ if [[ $TRAVIS_BUILD_STAGE_NAME == 'Deploy' ]]; then fi pip install --upgrade pip - -# Horrible hack -- but we should remove pythonql functionality soon anyway... -pip install pythonql3 pip install . pip install -r requirements-test.txt diff --git a/src/fileLoaders.py b/src/fileLoaders.py index 21b5e6f..e1af785 100644 --- a/src/fileLoaders.py +++ b/src/fileLoaders.py @@ -34,14 +34,6 @@ def getTextForName(self, query_name): # No query found... return '', None - def getProjectionForQueryName(self, query_name): - """ TODO: DOCUMENT !! - Returns None if no such projection exists - """ - projectionFileName = query_name + '.pyql' - projectionText = self._getText(projectionFileName) - return projectionText - def getLicenceURL(self): for f in self.fetchFiles(): if f['name'].lower() == 'license' or f['name'].lower() == 'licence': diff --git a/src/projection.py b/src/projection.py deleted file mode 100644 index 58653e3..0000000 --- a/src/projection.py +++ /dev/null @@ -1,34 +0,0 @@ -from pythonql.parser.Preprocessor import makeProgramFromString -from six import PY3 - -import grlc.glogging as glogging - -glogger = glogging.getGrlcLogger(__name__) - -def project(dataIn, projectionScript): - '''Programs may make use of data in the `dataIn` variable and should - produce data on the `dataOut` variable.''' - # We don't really need to initialize it, but we do it to avoid linter errors - dataOut = {} - try: - projectionScript = str(projectionScript) - program = makeProgramFromString(projectionScript) - if PY3: - loc = { - 'dataIn': dataIn, - 'dataOut': dataOut - } - exec(program, {}, loc) - dataOut = loc['dataOut'] - else: - exec(program) - except Exception as e: - glogger.error("Error while executing SPARQL projection") - glogger.error(projectionScript) - glogger.error("Encountered exception: ") - glogger.error(e) - dataOut = { - 'status': 'error', - 'message': e.message - } - return dataOut diff --git a/src/swagger.py b/src/swagger.py index 6aea565..faa10e9 100644 --- a/src/swagger.py +++ b/src/swagger.py @@ -68,8 +68,8 @@ def get_path_for_item(item): description = item['description'] description += '\n\n```{}```'.format(query) - description += '\n\nSPARQL projection:\n```pythonql\n{}```'.format( - item['projection']) if 'projection' in item else '' + description += '\n\nSPARQL transformation:\n```json\n{}```'.format( + item['transform']) if 'transform' in item else '' item_path = { item['method']: { @@ -98,8 +98,6 @@ def get_path_for_item(item): } } } - if 'projection' in item: - item_path['projection'] = item['projection'] return item_path @@ -207,9 +205,6 @@ def process_sparql_query_text(query_text, loader, call_name, extraMetadata): endpoint_in_url = query_metadata['endpoint_in_url'] if 'endpoint_in_url' in query_metadata else True - projection = loader.getProjectionForQueryName(call_name) - glogger.debug('Projection: '.format(projection)) - # Processing of the parameters params = [] @@ -294,13 +289,12 @@ def process_sparql_query_text(query_text, loader, call_name, extraMetadata): glogger.warning("Query of type {} is currently unsupported! Skipping".format(query_metadata['type'])) # Finally: main structure of the callname spec - item = packItem('/' + call_name, method, tags, summary, description, params, query_metadata, extraMetadata, - projection) + item = packItem('/' + call_name, method, tags, summary, description, params, query_metadata, extraMetadata) return item -def packItem(call_name, method, tags, summary, description, params, query_metadata, extraMetadata, projection=None): +def packItem(call_name, method, tags, summary, description, params, query_metadata, extraMetadata): item = { 'call_name': call_name, 'method': method, @@ -308,14 +302,11 @@ def packItem(call_name, method, tags, summary, description, params, query_metada 'summary': summary, 'description': description, 'params': params, - 'item_properties': None, # From projection variables, only SelectQuery + 'item_properties': None, 'query': query_metadata['query'], 'original_query': query_metadata.get('original_query', query_metadata['query']) } - if projection: - item['projection'] = projection # SPARQL projection PyQL file is available - for extraField in extraMetadata: if extraField in query_metadata: item[extraField] = query_metadata[extraField] diff --git a/src/utils.py b/src/utils.py index 28e3439..686587b 100644 --- a/src/utils.py +++ b/src/utils.py @@ -5,7 +5,6 @@ from grlc.prov import grlcPROV from grlc.fileLoaders import GithubLoader, LocalLoader, ParamLoader from grlc.queryTypes import qType -from grlc.projection import project from grlc import __version__ as grlc_version import re @@ -90,11 +89,8 @@ def dispatch_query(user, repo, query_name, subdir=None, sha=None, content=None, requestUrl) if acceptHeader == 'application/json': - projection = loader.getProjectionForQueryName(query_name) - if projection: - dataIn = json.loads(resp) - dataOut = project(dataIn, projection) - resp = json.dumps(dataOut) + # TODO: transform JSOn result if suitable + pass return resp, status, headers # Call name implemented with TPF query diff --git a/tests/mock_data.py b/tests/mock_data.py index 3e433d8..59cbfc0 100644 --- a/tests/mock_data.py +++ b/tests/mock_data.py @@ -43,50 +43,3 @@ def mock_requestsGithub(uri, headers={}, params={}): ] } } - -mock_sparqlResponse = { - "head": { - "link": [], - "vars": [ "country_name", "capital_name", "population" ] - }, - "results": { - "distinct": "false", - "ordered": "true", - "bindings": [ - { - "country_name": { - "type": "literal", - "xml:lang": "en", - "value": "Albania" - }, - "capital_name": { - "type": "literal", - "xml:lang": "en", - "value": "Tirana" - }, - "population": { - "type": "typed-literal", - "datatype": "http://www.w3.org/2001/XMLSchema#nonNegativeInteger", - "value": "2886026" - } - }, - { - "country_name": { - "type": "literal", - "xml:lang": "en", - "value": "Algeria" - }, - "capital_name": { - "type": "literal", - "xml:lang": "en", - "value": "Algiers" - }, - "population": { - "type": "typed-literal", - "datatype": "http://www.w3.org/2001/XMLSchema#nonNegativeInteger", - "value": "40400000" - } - } - ] - } -} diff --git a/tests/test_projection.py b/tests/test_projection.py deleted file mode 100644 index af9b06b..0000000 --- a/tests/test_projection.py +++ /dev/null @@ -1,36 +0,0 @@ -import unittest - -from grlc.projection import project - -from tests.mock_data import mock_sparqlResponse - -class TestProjection(unittest.TestCase): - def xtest_project_error(self): - projectionScript = 'This projection script has invalid syntax' - projection = project(mock_sparqlResponse, projectionScript) - self.assertIn('status', projection, 'Should contain a status') - self.assertEqual(projection['status'], 'error', 'Status should be error') - - def test_project_success_simple(self): - projectionScript = 'dataOut = {}\n' - projection = project(mock_sparqlResponse, projectionScript) - self.assertIsInstance(projection, dict) - self.assertEqual(projection, {}) - - def test_project_success_not_so_simple(self): - projectionScript = ''' -from pythonql.Executor import * - -dataOut = [ - select (country, capital) - for item in dataIn['results']['bindings'] - let country = item['country_name']['value'] - let capital = item['capital_name']['value'] -] - ''' - projection = project(mock_sparqlResponse, projectionScript) - self.assertIsInstance(projection, list, 'Projection should be a list') - for item in projection: - itemDict = item.getDict() - self.assertIn('country', itemDict, 'List items should contain a country') - self.assertIn('capital', itemDict, 'List items should contain a capital') diff --git a/tests/test_utils.py b/tests/test_utils.py index 5afff07..04da371 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -87,7 +87,7 @@ def setMockGetResponse(self): @patch('requests.get') - def test_projection(self, mock_get): + def test_dispatch_SPARQL_query(self, mock_get): mock_get.return_value = self.setMockGetResponse() rq, _ = self.loader.getTextForName('test-projection')