Skip to content

Commit

Permalink
Merge pull request #349 from OpenDataServices/black-isort
Browse files Browse the repository at this point in the history
black-isort: Apply
  • Loading branch information
Bjwebb authored Apr 15, 2020
2 parents da3f714 + a094fea commit ba3d46a
Show file tree
Hide file tree
Showing 35 changed files with 5,865 additions and 4,824 deletions.
7 changes: 7 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# From https://black.readthedocs.io/en/stable/the_black_code_style.html?highlight=isort#how-black-wraps-lines
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ python:
- "3.8"
install:
- pip install --upgrade -r requirements_dev.txt
script: py.test --cov .
# Black only runs under Python >= 3.6
- if [[ $TRAVIS_PYTHON_VERSION != 3.5 ]]; then pip install black==19.10b0; fi
script:
- if [[ $TRAVIS_PYTHON_VERSION != 3.5 ]]; then black --check *.py */; fi
- isort --check-only --recursive *.py */
- flake8
- py.test --cov .
after_success: coveralls
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]


### Changed

- All code has had black and isort applied. These have been added to Travis.

## [0.11.0] - 2020-02-21

### Added
Expand Down
87 changes: 46 additions & 41 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,42 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
#
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'Flatten Tool'
copyright = '2016-2020, Open Data Services'
author = 'Open Data Services'
project = "Flatten Tool"
copyright = "2016-2020, Open Data Services"
author = "Open Data Services"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.0.0'
version = "0.0.0"
# The full version, including alpha/beta/rc tags.
release = '0.0.0'
release = "0.0.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -89,7 +89,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The reST default role (used for this markup: `text`) to use for all
# documents.
Expand All @@ -111,7 +111,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand Down Expand Up @@ -165,7 +165,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down Expand Up @@ -245,34 +245,36 @@
# html_search_scorer = 'scorer.js'

# Output file base name for HTML help builder.
htmlhelp_basename = 'FlattenTooldoc'
htmlhelp_basename = "FlattenTooldoc"

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'FlattenTool.tex', 'Flatten Tool Documentation',
'Open Data Services', 'manual'),
(
master_doc,
"FlattenTool.tex",
"Flatten Tool Documentation",
"Open Data Services",
"manual",
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -306,10 +308,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'flattentool', 'Flatten Tool Documentation',
[author], 1)
]
man_pages = [(master_doc, "flattentool", "Flatten Tool Documentation", [author], 1)]

# If true, show URL addresses after external links.
#
Expand All @@ -322,9 +321,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'FlattenTool', 'Flatten Tool Documentation',
author, 'FlattenTool', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"FlattenTool",
"Flatten Tool Documentation",
author,
"FlattenTool",
"One line description of project.",
"Miscellaneous",
),
]

# Documents to append as an appendix to all manuals.
Expand Down
42 changes: 27 additions & 15 deletions flattentool/ODSReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
# Thanks to grt for the fixes
# https://github.com/marcoconti83/read-ods-with-odfpy

import odf.opendocument
from odf.table import Table, TableRow, TableCell
from odf.text import P
from collections import OrderedDict
import re
from collections import OrderedDict

import odf.opendocument
from odf.table import Table, TableCell, TableRow


# http://stackoverflow.com/a/4544699/1846474
class GrowingList(list):
def __setitem__(self, index, value):
if index >= len(self):
self.extend([None]*(index + 1 - len(self)))
self.extend([None] * (index + 1 - len(self)))
list.__setitem__(self, index, value)


Expand All @@ -49,7 +49,7 @@ def readSheet(self, sheet):

# for each row
for row in rows:
row_comment = ""
row_comment = "" # noqa
arrCells = GrowingList()
cells = row.getElementsByType(TableCell)

Expand All @@ -58,26 +58,38 @@ def readSheet(self, sheet):
for cell in cells:
# repeated value?
repeat = cell.getAttribute("numbercolumnsrepeated")
if(not repeat):
if not repeat:
repeat = 1
spanned = int(cell.getAttribute('numbercolumnsspanned') or 0)
spanned = int(cell.getAttribute("numbercolumnsspanned") or 0)
# clone spanned cells
if self.clonespannedcolumns is not None and spanned > 1:
repeat = spanned

for rr in range(int(repeat)): # repeated?
if str(cell):
value_type = cell.attributes.get(('urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value-type'))
if value_type == 'float':
if '.' in str(cell):
value_type = cell.attributes.get(
(
"urn:oasis:names:tc:opendocument:xmlns:office:1.0",
"value-type",
)
)
if value_type == "float":
if "." in str(cell):
arrCells[count] = float(str(cell))
else:
arrCells[count] = int(str(cell))
elif value_type == 'date':
date_value = cell.attributes.get(('urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'date-value'))
elif value_type == "date":
date_value = cell.attributes.get(
(
"urn:oasis:names:tc:opendocument:xmlns:office:1.0",
"date-value",
)
)
# Add UTC timezone to naive datetime strings
if re.match(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d$', date_value):
date_value += 'Z'
if re.match(
r"^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d$", date_value
):
date_value += "Z"
arrCells[count] = date_value
else:
arrCells[count] = str(cell)
Expand Down
Loading

0 comments on commit ba3d46a

Please sign in to comment.