Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Add support for python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mraarif committed Jun 21, 2020
1 parent 0ae0b7d commit 7f90a31
Show file tree
Hide file tree
Showing 28 changed files with 247 additions and 51 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Config file for automatic testing at travis-ci.org

language: python

matrix:
include:
- python: 2.7
env: TOXENV=py27
- python: 3.5
env: TOXENV=py35

cache:
- pip
Expand All @@ -13,7 +16,7 @@ before_install:
- pip install --upgrade pip

install:
- pip install -r test_requirements.txt
- pip install -r requirements/tox.txt

script:
- tox
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ clean:

test:
py.test


upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade
upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
pip install -qr requirements/pip-tools.txt
pip-compile --upgrade -o requirements/pip-tools.txt requirements/pip-tools.in
pip-compile --upgrade -o requirements/base.txt requirements/base.in
pip-compile --upgrade -o requirements/test.txt requirements/test.in
pip-compile --upgrade -o requirements/github.txt requirements/github.in
pip-compile --upgrade -o requirements/tox.txt requirements/tox.in
1 change: 1 addition & 0 deletions exporter/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
--window=<days> Fail if the most recent file is older than this many days. [default: 6]
"""

from __future__ import absolute_import
import datetime
import logging
import os
Expand Down
8 changes: 5 additions & 3 deletions exporter/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pylint: disable=missing-docstring

from __future__ import absolute_import
import json
import logging
import logging.config
Expand All @@ -10,6 +11,7 @@
import yaml

from exporter.util import merge, filter_keys
import six


WORK_SUBDIR = 'course-data'
Expand Down Expand Up @@ -59,7 +61,7 @@ def update_config(config, program_options):
def merge_program_options(config, program_options):
# get program options, removing '--' and replacing '-' with '_'
options = {k[2:].replace('-', '_'): v for k, v
in program_options.iteritems()
in six.iteritems(program_options)
if k.startswith('--')}

config['options'] = options
Expand Down Expand Up @@ -104,7 +106,7 @@ def update_environments(config):
for env in ['prod', 'edge']:
if env in environments:
data = environments.get(env, {})
for config_name, token_name in field_map.iteritems():
for config_name, token_name in six.iteritems(field_map):
data[config_name] = tokens.get(token_name)

# different settings for edge
Expand All @@ -123,7 +125,7 @@ def update_organizations(config):

# lowercase orgs before selection
organizations = {org.lower(): values for org, values
in config['organizations'].iteritems()}
in six.iteritems(config['organizations'])}

# select only organizations in arguments
organizations = filter_keys(organizations, values.get('org'))
Expand Down
6 changes: 4 additions & 2 deletions exporter/course_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"""


from __future__ import absolute_import
from contextlib import contextmanager
import datetime
import os
Expand All @@ -49,6 +50,7 @@
from exporter.main import run_tasks, archive_directory, upload_data, get_all_courses, _get_selected_tasks
from exporter.config import setup, get_config_for_env, get_config_for_course
from exporter.util import make_temp_directory, with_temp_directory, merge
import six

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -150,12 +152,12 @@ def get_filename_safe_course_id(course_id, replacement_char='_'):
"""
try:
course_key = CourseKey.from_string(course_id)
filename = unicode(replacement_char).join([course_key.org, course_key.course, course_key.run])
filename = six.text_type(replacement_char).join([course_key.org, course_key.course, course_key.run])
except InvalidKeyError:
# If the course_id doesn't parse, we will still return a value here.
filename = course_id

# The safest characters are A-Z, a-z, 0-9, <underscore>, <period> and <hyphen>.
# We represent the first four with \w.
# TODO: Once we support courses with unicode characters, we will need to revisit this.
return re.sub(r'[^\w\.\-]', unicode(replacement_char), filename)
return re.sub(r'[^\w\.\-]', six.text_type(replacement_char), filename)
4 changes: 3 additions & 1 deletion exporter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
--django-pythonpath=<path> The django python path
"""

from __future__ import absolute_import
from contextlib import contextmanager
from copy import copy
import datetime
Expand All @@ -63,6 +64,7 @@
from exporter.util import make_temp_directory, with_temp_directory
from exporter.util import filter_keys, memoize, execute_shell
from exporter.util import logging_streams_on_failure
import six


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -307,7 +309,7 @@ def get_all_courses(**kwargs):
log.info('Retrieving all courses')

# make a set of fixed arguments, so we can memoize
kwargs = {k: v for k, v in kwargs.iteritems() if k.startswith('django')}
kwargs = {k: v for k, v in six.iteritems(kwargs) if k.startswith('django')}
kwargs['dry_run'] = False # always query for course names
kwargs['limit'] = False # don't limit number of courses

Expand Down
1 change: 1 addition & 0 deletions exporter/metrics.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import calendar
from contextlib import contextmanager
from datetime import datetime
Expand Down
4 changes: 3 additions & 1 deletion exporter/mysql_query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import absolute_import
from contextlib import closing
import json
import csv
import mysql.connector
import six

MAX_FETCH_SIZE = 10000

Expand Down Expand Up @@ -59,4 +61,4 @@ def _write_results_to_tsv(self, cursor, output_file):

def _normalize_value(self, value):
if value is None: value='NULL'
return unicode(value).encode('utf-8').replace('\\', '\\\\').replace('\r', '\\r').replace('\t','\\t').replace('\n', '\\n')
return six.text_type(value).encode('utf-8').replace('\\', '\\\\').replace('\r', '\\r').replace('\t','\\t').replace('\n', '\\n')
4 changes: 3 additions & 1 deletion exporter/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
Can use wildcards.
"""

from __future__ import absolute_import
from __future__ import print_function
import os.path
import shutil
import sys
Expand Down Expand Up @@ -55,7 +57,7 @@ def export_properties(config, directory, files=None, orgs=None, prefix=''):
recreate_directory(directory)

orgs = [o.lower() for o in orgs.split()] if orgs else ['*']
print orgs
print(orgs)

files_data = load_files(files)

Expand Down
Loading

0 comments on commit 7f90a31

Please sign in to comment.