Skip to content

Commit

Permalink
Drop Python 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jun 9, 2023
1 parent 7091f4b commit 035fb9e
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 225 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ jobs:
include:
- ckan-version: "2.10"
solr-image: "2.10-spatial"
requirements-file: 'requirements.txt'
- ckan-version: 2.9
solr-image: 2.9-solr8-spatial
requirements-file: 'requirements.txt'
- ckan-version: 2.9-py2
solr-image: 2.9-py2-solr8-spatial
requirements-file: 'requirements-py2.txt'
fail-fast: false

name: CKAN ${{ matrix.ckan-version }}, Solr ${{ matrix.solr-image }}
Expand Down Expand Up @@ -89,10 +84,10 @@ jobs:
restore-keys: |
${{ runner.os }}-spatial-ckan-${{ matrix.ckan-version }}-${{ hashFiles('*requirements*.txt') }}
- name: Install dependencies from ${{ matrix.requirements-file }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install -r ${{ matrix.requirements-file }}
pip install -r requirements.txt
- name: Install harvester
if: steps.cache.outputs.cache-hit != 'true'
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Supported Versions
------------------

ckanext-spatial >= 2.0.0 supports CKAN 2.9 and CKAN 2.10.
ckanext-spatial >= 2.1.0 supports Python 3 only.

Check the
[tested enviroments](https://github.com/ckan/ckanext-spatial/blob/master/.github/workflows/test.yml)
for more details.
Expand Down
2 changes: 1 addition & 1 deletion bin/ckan_pycsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io
import os
import argparse
from six.moves.configparser import SafeConfigParser
from configparser import SafeConfigParser

import requests
from lxml import etree
Expand Down
6 changes: 3 additions & 3 deletions ckanext/spatial/harvested_metadata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from lxml import etree
import six

import logging
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -38,7 +38,7 @@ def read_value(self, name):
def get_xml_tree(self):
if self.xml_tree is None:
parser = etree.XMLParser(remove_blank_text=True)
xml_str = six.ensure_str(self.xml_str)
xml_str = str(self.xml_str)
self.xml_tree = etree.fromstring(xml_str, parser=parser)
return self.xml_tree

Expand Down
28 changes: 14 additions & 14 deletions ckanext/spatial/harvesters/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import six
from six.moves.urllib.parse import urlparse
from six.moves.urllib.request import urlopen

from urllib.parse import urlparse
from urllib.request import urlopen

import re
import cgitb
Expand Down Expand Up @@ -300,7 +300,7 @@ def get_package_dict(self, context, data_dict):
if package is None or package.title != iso_values['title']:
name = self._gen_new_name(iso_values['title'])
if not name:
name = self._gen_new_name(six.text_type(iso_values['guid']))
name = self._gen_new_name(str(iso_values['guid']))
if not name:
raise Exception('Could not generate a unique name from the title or the GUID. Please choose a more unique title.')
package_dict['name'] = name
Expand Down Expand Up @@ -414,7 +414,7 @@ def _extract_first_license_url(licences):
ymin = float(bbox['south'])
ymax = float(bbox['north'])
except ValueError as e:
self._save_object_error('Error parsing bounding box value: {0}'.format(six.text_type(e)),
self._save_object_error('Error parsing bounding box value: {0}'.format(str(e)),
harvest_object, 'Import')
else:
# Construct a GeoJSON extent so ckanext-spatial can register the extent geometry
Expand Down Expand Up @@ -472,7 +472,7 @@ def _extract_first_license_url(licences):
log.debug('Processing extra %s', key)
if not key in extras or override_extras:
# Look for replacement strings
if isinstance(value,six.string_types):
if isinstance(value, str):
value = value.format(harvest_source_id=harvest_object.job.source.id,
harvest_source_url=harvest_object.job.source.url.strip('/'),
harvest_source_title=harvest_object.job.source.title,
Expand Down Expand Up @@ -576,7 +576,7 @@ def import_stage(self, harvest_object):
iso_parser = ISODocument(harvest_object.content)
iso_values = iso_parser.read_values()
except Exception as e:
self._save_object_error('Error parsing ISO document for object {0}: {1}'.format(harvest_object.id, six.text_type(e)),
self._save_object_error('Error parsing ISO document for object {0}: {1}'.format(harvest_object.id, str(e)),
harvest_object, 'Import')
return False

Expand Down Expand Up @@ -646,7 +646,7 @@ def import_stage(self, harvest_object):

# The default package schema does not like Upper case tags
tag_schema = logic.schema.default_tags_schema()
tag_schema['name'] = [not_empty, six.text_type]
tag_schema['name'] = [not_empty, str]

# Flag this object as the current one
harvest_object.current = True
Expand All @@ -659,8 +659,8 @@ def import_stage(self, harvest_object):

# We need to explicitly provide a package ID, otherwise ckanext-spatial
# won't be be able to link the extent to the package.
package_dict['id'] = six.text_type(uuid.uuid4())
package_schema['id'] = [six.text_type]
package_dict['id'] = str(uuid.uuid4())
package_schema['id'] = [str]

# Save reference to the package on the object
harvest_object.package_id = package_dict['id']
Expand All @@ -675,7 +675,7 @@ def import_stage(self, harvest_object):
package_id = p.toolkit.get_action('package_create')(context, package_dict)
log.info('Created new package %s with guid %s', package_id, harvest_object.guid)
except p.toolkit.ValidationError as e:
self._save_object_error('Validation Error: %s' % six.text_type(e.error_summary), harvest_object, 'Import')
self._save_object_error('Validation Error: %s' % str(e.error_summary), harvest_object, 'Import')
return False

elif status == 'change':
Expand Down Expand Up @@ -721,7 +721,7 @@ def import_stage(self, harvest_object):
package_id = p.toolkit.get_action('package_update')(context, package_dict)
log.info('Updated package %s with guid %s', package_id, harvest_object.guid)
except p.toolkit.ValidationError as e:
self._save_object_error('Validation Error: %s' % six.text_type(e.error_summary), harvest_object, 'Import')
self._save_object_error('Validation Error: %s' % str(e.error_summary), harvest_object, 'Import')
return False

model.Session.commit()
Expand All @@ -738,7 +738,7 @@ def _is_wms(self, url):
s = wms.WebMapService(url)
return isinstance(s.contents, dict) and s.contents != {}
except Exception as e:
log.error('WMS check for %s failed with exception: %s' % (url, six.text_type(e)))
log.error('WMS check for %s failed with exception: %s' % (url, str(e)))
return False

def _get_object_extra(self, harvest_object, key):
Expand Down Expand Up @@ -881,7 +881,7 @@ def _validate_document(self, document_string, harvest_object, validator=None):
try:
xml = etree.fromstring(document_string)
except etree.XMLSyntaxError as e:
self._save_object_error('Could not parse XML file: {0}'.format(six.text_type(e)), harvest_object, 'Import')
self._save_object_error('Could not parse XML file: {0}'.format(str(e)), harvest_object, 'Import')
return False, None, []

valid, profile, errors = validator.is_valid(xml)
Expand Down
Loading

0 comments on commit 035fb9e

Please sign in to comment.