Skip to content

Commit

Permalink
blackify code
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed May 23, 2019
1 parent 9a6ffcc commit 07301f9
Show file tree
Hide file tree
Showing 115 changed files with 5,388 additions and 8,712 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ jobs:
command: |
sudo apt-get install -y openjdk-8-jre-headless
sudo sed -i -e '/^assistive_technologies=/s/^/#/' /etc/java-*-openjdk/accessibility.properties
- run:
name: Test code is well formatted
command: |
if ! type /home/circleci/.local/bin/black > /dev/null; then
echo "Black is not supported in this python version :("
else
/home/circleci/.local/bin/black --target-version=py27 pyxform --check --quiet || (echo 'The source code could use a bit more black.' && exit 1)
fi
- run:
name: Run tests
command: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ env

# ignore pypi manifest
MANIFEST
pyxform/tests/test_output/
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pyxform v0.13.x
.. |codecov| image:: https://codecov.io/github/XLSForm/pyxform/branch/master/graph/badge.svg
:target: https://codecov.io/github/XLSForm/pyxform

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/python/black

pyxform is a Python library that makes writing XForms for ODK Collect and enketo
easy by converting XLS(X) spreadsheets into XForms. It is used as a library in a number of tools including `the ODK online converter <http://opendatakit.org/xiframe/>`_ and `Ona <https://ona.io>`_.

Expand Down
4 changes: 2 additions & 2 deletions pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ if [ -n "$FILES" ]; then
fi

if [ -n "$FILES" ]; then
if black --target-version=py36 $FILES; then
touch .commit
if black --target-version=py27 $FILES; then
touch .commit
fi
fi

Expand Down
27 changes: 16 additions & 11 deletions pyxform/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# -*- coding: utf-8 -*-
"""
pyxform is a Python library designed to make authoring XForms for ODK
Collect easy.
"""

__version__ = '0.13.1'
__version__ = "0.13.1"

from pyxform.builder import (SurveyElementBuilder, create_survey, # noqa
create_survey_element_from_dict,
create_survey_from_path, create_survey_from_xls)
from pyxform.instance import SurveyInstance # noqa
from pyxform.question import (InputQuestion, MultipleChoiceQuestion, # noqa
Question)
from pyxform.question_type_dictionary import QUESTION_TYPE_DICT # noqa
from pyxform.section import Section # noqa
from pyxform.survey import Survey # noqa
from pyxform.xls2json import SurveyReader as ExcelSurveyReader # noqa
from pyxform.builder import (
SurveyElementBuilder,
create_survey,
create_survey_element_from_dict,
create_survey_from_path,
create_survey_from_xls,
)
from pyxform.instance import SurveyInstance
from pyxform.question import InputQuestion, MultipleChoiceQuestion, Question
from pyxform.question_type_dictionary import QUESTION_TYPE_DICT
from pyxform.section import Section
from pyxform.survey import Survey
from pyxform.xls2json import SurveyReader as ExcelSurveyReader

# This is what gets imported when someone imports pyxform
# flake8: noqa
211 changes: 106 additions & 105 deletions pyxform/aliases.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# -*- coding: utf-8 -*-
"""
Aliases for elements which could mean the same element in XForm but is represented
differently on the XLSForm.
"""
from pyxform import constants

# Aliases:
Expand All @@ -7,118 +12,116 @@
# which is why self mapped keys are necessary.

control = {
u"group": constants.GROUP,
u"lgroup": constants.REPEAT,
u"repeat": constants.REPEAT,
u"loop": constants.LOOP,
u"looped group": constants.REPEAT
"group": constants.GROUP,
"lgroup": constants.REPEAT,
"repeat": constants.REPEAT,
"loop": constants.LOOP,
"looped group": constants.REPEAT,
}
select = {
u"add select one prompt using": constants.SELECT_ONE,
u"add select multiple prompt using": constants.SELECT_ALL_THAT_APPLY,
u"select all that apply from": constants.SELECT_ALL_THAT_APPLY,
u"select one from": constants.SELECT_ONE,
u"select1": constants.SELECT_ONE,
u"select_one": constants.SELECT_ONE,
u"select one": constants.SELECT_ONE,
u"select_multiple": constants.SELECT_ALL_THAT_APPLY,
u"select all that apply": constants.SELECT_ALL_THAT_APPLY,
u"select_one_external": u"select one external",
u"select_one_from_file": constants.SELECT_ONE,
u"select_multiple_from_file": constants.SELECT_ALL_THAT_APPLY,
u"select one from file": constants.SELECT_ONE,
u"select multiple from file": constants.SELECT_ALL_THAT_APPLY,
u"rank": constants.RANK,
"add select one prompt using": constants.SELECT_ONE,
"add select multiple prompt using": constants.SELECT_ALL_THAT_APPLY,
"select all that apply from": constants.SELECT_ALL_THAT_APPLY,
"select one from": constants.SELECT_ONE,
"select1": constants.SELECT_ONE,
"select_one": constants.SELECT_ONE,
"select one": constants.SELECT_ONE,
"select_multiple": constants.SELECT_ALL_THAT_APPLY,
"select all that apply": constants.SELECT_ALL_THAT_APPLY,
"select_one_external": "select one external",
"select_one_from_file": constants.SELECT_ONE,
"select_multiple_from_file": constants.SELECT_ALL_THAT_APPLY,
"select one from file": constants.SELECT_ONE,
"select multiple from file": constants.SELECT_ALL_THAT_APPLY,
"rank": constants.RANK,
}
cascading = {
u'cascading select': constants.CASCADING_SELECT,
u'cascading_select': constants.CASCADING_SELECT,
"cascading select": constants.CASCADING_SELECT,
"cascading_select": constants.CASCADING_SELECT,
}
settings_header = {
u"form_title": constants.TITLE,
u"set form title": constants.TITLE,
u"form_id": constants.ID_STRING,
u"sms_keyword": constants.SMS_KEYWORD,
u"sms_separator": constants.SMS_SEPARATOR,
u"sms_allow_media": constants.SMS_ALLOW_MEDIA,
u"sms_date_format": constants.SMS_DATE_FORMAT,
u"sms_datetime_format": constants.SMS_DATETIME_FORMAT,

u"prefix": constants.COMPACT_PREFIX,
u"delimiter": constants.COMPACT_DELIMITER,

u"set form id": constants.ID_STRING,
u"public_key": constants.PUBLIC_KEY,
u"submission_url": constants.SUBMISSION_URL,
u"auto_send": constants.AUTO_SEND,
u"auto_delete": constants.AUTO_DELETE
"form_title": constants.TITLE,
"set form title": constants.TITLE,
"form_id": constants.ID_STRING,
"sms_keyword": constants.SMS_KEYWORD,
"sms_separator": constants.SMS_SEPARATOR,
"sms_allow_media": constants.SMS_ALLOW_MEDIA,
"sms_date_format": constants.SMS_DATE_FORMAT,
"sms_datetime_format": constants.SMS_DATETIME_FORMAT,
"prefix": constants.COMPACT_PREFIX,
"delimiter": constants.COMPACT_DELIMITER,
"set form id": constants.ID_STRING,
"public_key": constants.PUBLIC_KEY,
"submission_url": constants.SUBMISSION_URL,
"auto_send": constants.AUTO_SEND,
"auto_delete": constants.AUTO_DELETE,
}
# TODO: Check on bind prefix approach in json.
# Conversion dictionary from user friendly column names to meaningful values
survey_header = {
u"Label": u"label",
u"Name": u"name",
u"SMS Field": constants.SMS_FIELD,
u"SMS Option": constants.SMS_OPTION,
u"SMS Sepatator": constants.SMS_SEPARATOR,
u"SMS Allow Media": constants.SMS_ALLOW_MEDIA,
u"SMS Date Format": constants.SMS_DATE_FORMAT,
u"SMS DateTime Format": constants.SMS_DATETIME_FORMAT,
u"SMS Response": constants.SMS_RESPONSE,
u"compact_tag": u"instance::odk:tag", # used for compact representation
u"Type": u"type",
u"List_name": u"list_name",
"Label": "label",
"Name": "name",
"SMS Field": constants.SMS_FIELD,
"SMS Option": constants.SMS_OPTION,
"SMS Sepatator": constants.SMS_SEPARATOR,
"SMS Allow Media": constants.SMS_ALLOW_MEDIA,
"SMS Date Format": constants.SMS_DATE_FORMAT,
"SMS DateTime Format": constants.SMS_DATETIME_FORMAT,
"SMS Response": constants.SMS_RESPONSE,
"compact_tag": "instance::odk:tag", # used for compact representation
"Type": "type",
"List_name": "list_name",
# u"repeat_count": u"jr:count", duplicate key
u"read_only": u"bind::readonly",
u"readonly": u"bind::readonly",
u"relevant": u"bind::relevant",
u"caption": constants.LABEL,
u"appearance": u"control::appearance", # TODO: this is also an issue
u"relevance": u"bind::relevant",
u"required": u"bind::required",
u"constraint": u"bind::constraint",
u"constraining message": u"bind::jr:constraintMsg",
u"constraint message": u"bind::jr:constraintMsg",
u"constraint_message": u"bind::jr:constraintMsg",
u"calculation": u"bind::calculate",
u"calculate": u"bind::calculate",
u"command": constants.TYPE,
u"tag": constants.NAME,
u"value": constants.NAME,
u"image": u"media::image",
u"audio": u"media::audio",
u"video": u"media::video",
u"count": u"control::jr:count",
u"repeat_count": u"control::jr:count",
u"jr:count": u"control::jr:count",
u"autoplay": u"control::autoplay",
u"rows": u"control::rows",
"read_only": "bind::readonly",
"readonly": "bind::readonly",
"relevant": "bind::relevant",
"caption": constants.LABEL,
"appearance": "control::appearance", # TODO: this is also an issue
"relevance": "bind::relevant",
"required": "bind::required",
"constraint": "bind::constraint",
"constraining message": "bind::jr:constraintMsg",
"constraint message": "bind::jr:constraintMsg",
"constraint_message": "bind::jr:constraintMsg",
"calculation": "bind::calculate",
"calculate": "bind::calculate",
"command": constants.TYPE,
"tag": constants.NAME,
"value": constants.NAME,
"image": "media::image",
"audio": "media::audio",
"video": "media::video",
"count": "control::jr:count",
"repeat_count": "control::jr:count",
"jr:count": "control::jr:count",
"autoplay": "control::autoplay",
"rows": "control::rows",
# New elements that have to go into itext elements:
u"noAppErrorString": u"bind::jr:noAppErrorString",
u"no_app_error_string": u"bind::jr:noAppErrorString",
u"requiredMsg": u"bind::jr:requiredMsg",
u"required_message": u"bind::jr:requiredMsg",
u"required message": u"bind::jr:requiredMsg",
u"body": u"control",
u"parameters": u"parameters",
"noAppErrorString": "bind::jr:noAppErrorString",
"no_app_error_string": "bind::jr:noAppErrorString",
"requiredMsg": "bind::jr:requiredMsg",
"required_message": "bind::jr:requiredMsg",
"required message": "bind::jr:requiredMsg",
"body": "control",
"parameters": "parameters",
}
list_header = {
u"caption": constants.LABEL,
u"list_name": constants.LIST_NAME,
u"value": constants.NAME,
u"image": u"media::image",
u"audio": u"media::audio",
u"video": u"media::video"
"caption": constants.LABEL,
"list_name": constants.LIST_NAME,
"value": constants.NAME,
"image": "media::image",
"audio": "media::audio",
"video": "media::video",
}
# Note that most of the type aliasing happens in all.xls
_type = {
u"imei": u"deviceid",
u"image": u"photo",
u"add image prompt": u"photo",
u"add photo prompt": u"photo",
u"add audio prompt": u"audio",
u"add video prompt": u"video",
u"add file prompt": u"file"
"imei": "deviceid",
"image": "photo",
"add image prompt": "photo",
"add photo prompt": "photo",
"add audio prompt": "audio",
"add video prompt": "video",
"add file prompt": "file",
}
yes_no = {
"yes": True,
Expand All @@ -137,14 +140,12 @@
"false()": False,
}
label_optional_types = [
u"deviceid",
u"phonenumber",
u"simserial",
u"calculate",
u"start",
u"end",
u"today"
"deviceid",
"phonenumber",
"simserial",
"calculate",
"start",
"end",
"today",
]
osm = {
u"osm": constants.OSM_TYPE
}
osm = {"osm": constants.OSM_TYPE}
Loading

0 comments on commit 07301f9

Please sign in to comment.