From b6b7636fe7fc4008f79e566611b78f54f7358f73 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Fri, 27 Feb 2015 14:08:39 -0600 Subject: [PATCH] Allow building stand-alone validation script --- .gitignore | 2 ++ build-validator-pyz.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ course/content.py | 18 ++++++++++++------ course/page/text.py | 6 ++++++ 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100755 build-validator-pyz.sh diff --git a/.gitignore b/.gitignore index c740c145..72cffcc6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ components *.egg-info build + +*.pyz diff --git a/build-validator-pyz.sh b/build-validator-pyz.sh new file mode 100755 index 00000000..dacfb67e --- /dev/null +++ b/build-validator-pyz.sh @@ -0,0 +1,42 @@ +#! /bin/bash + +set -e + +rm -Rf pyz-build +mkdir pyz-build + +function pywhichmod() +{ + python -c "import $1; import os.path; print($1.__file__.replace('pyc', 'py'))" +} + +function pywhichpkg() +{ + python -c "import $1; import os.path; print(os.path.dirname($1.__file__))" +} + +pyzzer.pyz course relate -r \ + $(pywhichmod six) \ + $(pywhichpkg markdown) \ + $(pywhichpkg django) \ + $(pywhichpkg yaml) \ + -s '#! /usr/bin/env python2.7' \ + -o relate-validate.pyz \ + -x migrations \ + -x templates \ + -x 'static/' \ + -x '\..*\.sw[op]' \ + -x 'django/db' \ + -x 'django/contrib' \ + -x 'django/core/management' \ + -x 'django/conf/locale' \ + -x 'django/test' \ + -x 'django/template' \ + -x 'django/middleware' \ + -x 'django/views' \ + -x 'django/http' \ + -x 'django/core/serial' \ + -x 'django/core/mail' \ + -x '_doctest' \ + -x '.*~' \ + -m course.validation:validate_course_on_filesystem_script_entrypoint diff --git a/course/content.py b/course/content.py index 9015681e..8e020196 100644 --- a/course/content.py +++ b/course/content.py @@ -32,7 +32,6 @@ import six from django.utils.timezone import now from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured -from django.db import transaction from markdown.extensions import Extension from markdown.treeprocessors import Treeprocessor @@ -730,15 +729,14 @@ def instantiate_flow_page(location, repo, page_desc, commit_sha): return class_(None, location, page_desc) -@transaction.atomic -def adjust_flow_session_page_data(repo, flow_session, +def _adjust_flow_session_page_data_inner(repo, flow_session, course_identifier, flow_desc, commit_sha): from course.models import FlowPageData - id_to_existing_page = { - (data.group_id, data.page_id): data + id_to_existing_page = dict( + ((data.group_id, data.page_id), data) for data in FlowPageData.objects.filter(flow_session=flow_session) - } + ) data = None @@ -779,6 +777,14 @@ def adjust_flow_session_page_data(repo, flow_session, flow_session.save() +def adjust_flow_session_page_data(repo, flow_session, + course_identifier, flow_desc, commit_sha): + from django.db import transaction + with transaction.atomic(): + return _adjust_flow_session_page_data_inner( + repo, flow_session, course_identifier, flow_desc, commit_sha) + + def get_course_commit_sha(course, participation): sha = course.active_git_commit_sha diff --git a/course/page/text.py b/course/page/text.py index f66bef98..b3d84da3 100644 --- a/course/page/text.py +++ b/course/page/text.py @@ -286,6 +286,12 @@ class SymbolicExpressionMatcher(TextAnswerMatcher): try: self.pattern_sym = parse_sympy(pattern) + except ImportError: + tp, e, _ = sys.exc_info() + vctx.add_warning(location, "%s: unable to check " + "symbolic expression (%s: %s)" + % (location, tp.__name__, str(e))) + except: tp, e, _ = sys.exc_info() raise ValidationError("%s: %s: %s" -- GitLab