Skip to content

Commit 3ebada5

Browse files
authored
Merge pull request #342 from mpsonntag/refactor
Refactor package structure LGTM
2 parents db48012 + 33e1d21 commit 3ebada5

21 files changed

+623
-587
lines changed

appveyor.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1+
version: 1.4.{build}
2+
3+
image: Visual Studio 2017
4+
15
environment:
26
matrix:
37
- PYTHON: "C:\\Python27"
4-
PYVER: "2.7"
5-
- PYTHON: "C:\\Python35"
6-
PYVER: "3.5"
8+
PYVER: 2
9+
BITS: 32
710
- PYTHON: "C:\\Python36"
8-
PYVER: "3.6"
11+
PYVER: 3
12+
BITS: 32
913
- PYTHON: "C:\\Python37"
10-
PYVER: "3.7"
14+
PYVER: 3
15+
BITS: 32
1116
- PYTHON: "C:\\Python27-x64"
12-
PYVER: "2.7"
13-
- PYTHON: "C:\\Python35-x64"
14-
PYVER: "3.5"
17+
PYVER: 2
18+
BITS: 64
1519
- PYTHON: "C:\\Python36-x64"
16-
PYVER: "3.6"
20+
PYVER: 3
21+
BITS: 64
1722
- PYTHON: "C:\\Python37-x64"
18-
PYVER: "3.7"
23+
PYVER: 3
24+
BITS: 64
25+
26+
init:
27+
- "ECHO %PYTHON% %vcvars% (%bits%)"
28+
- ps: $env:PATH = "$env:PYTHON;$env:PATH;"
29+
- python -c "import sys;print('Python version is {}'.format(sys.version))"
1930

2031
build: false
2132

doc/tools.rst

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,50 @@ Tools
1414
=====
1515
Several tools are provided with the :py:mod:`odml.tools` package.
1616

17-
ODMLParser
17+
DictParser
1818
----------
19-
.. automodule:: odml.tools.odmlparser
19+
.. automodule:: odml.tools.dict_parser
2020
:members:
2121
:inherited-members:
2222
:undoc-members:
2323

24-
XMLParser
25-
---------
26-
.. automodule:: odml.tools.xmlparser
24+
ODMLParser
25+
----------
26+
.. automodule:: odml.tools.odmlparser
2727
:members:
2828
:inherited-members:
2929
:undoc-members:
3030

31-
DictParser
32-
----------
33-
.. automodule:: odml.tools.dict_parser
31+
RDFConverter
32+
----------------
33+
.. automodule:: odml.tools.rdf_converter
3434
:members:
3535
:inherited-members:
3636
:undoc-members:
3737

38-
FormatConverter
39-
----------------
40-
.. automodule:: odml.tools.format_converter
38+
XMLParser
39+
---------
40+
.. automodule:: odml.tools.xmlparser
4141
:members:
4242
:inherited-members:
4343
:undoc-members:
4444

45-
VersionConverter
45+
.. _converters:
46+
47+
Convenience converters
48+
======================
49+
Several convenience converters are provided with the :py:mod:`odml.tools.converters` package.
50+
51+
FormatConverter
4652
----------------
47-
.. automodule:: odml.tools.version_converter
53+
.. automodule:: odml.tools.converters.format_converter
4854
:members:
4955
:inherited-members:
5056
:undoc-members:
5157

52-
RDFConverter
58+
VersionConverter
5359
----------------
54-
.. automodule:: odml.tools.rdf_converter
60+
.. automodule:: odml.tools.converters.version_converter
5561
:members:
5662
:inherited-members:
5763
:undoc-members:

odml/rdf/__init__.py

Whitespace-only changes.

odml/tools/fuzzy_finder.py renamed to odml/rdf/fuzzy_finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odml.tools.query_creator import QueryCreator, QueryParser, QueryParserFuzzy
1+
from .query_creator import QueryCreator, QueryParser, QueryParserFuzzy
22

33

44
class FuzzyFinder(object):
File renamed without changes.

odml/scripts/odml_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import odml
3737

38-
from odml.tools.version_converter import VersionConverter as VerConf
38+
from odml.tools.converters import VersionConverter as VerConf
3939

4040
try:
4141
unicode = unicode

odml/scripts/odml_to_rdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import odml
3838

3939
from odml.tools.odmlparser import ODMLReader, ODMLWriter
40-
from odml.tools.version_converter import VersionConverter as VerConf
40+
from odml.tools.converters import VersionConverter as VerConf
4141

4242
try:
4343
unicode = unicode

odml/tools/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .dict_parser import DictReader, DictWriter
2+
from .odmlparser import ODMLReader, ODMLWriter
3+
from .rdf_converter import RDFReader, RDFWriter
4+
from .xmlparser import XMLReader, XMLWriter

odml/tools/converters/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .version_converter import VersionConverter
2+
# FormatConverter depends on VersionConverter
3+
from .format_converter import FormatConverter

odml/tools/format_converter.py renamed to odml/tools/converters/format_converter.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
11
import argparse
2+
import copy
23
import os
34
import re
45
import sys
56

67
import odml
7-
from .rdf_converter import RDFWriter
8-
from .version_converter import VersionConverter
9-
from .utils import ConversionFormats
8+
9+
from .. import RDFWriter
10+
from . import VersionConverter
11+
from ..parser_utils import RDF_CONVERSION_FORMATS
1012

1113
try:
1214
unicode = unicode
1315
except NameError:
1416
unicode = str
1517

1618

19+
CONVERSION_FORMATS = copy.deepcopy(RDF_CONVERSION_FORMATS)
20+
CONVERSION_FORMATS.update({
21+
'v1_1': '.xml',
22+
'odml': '.odml'
23+
})
24+
25+
1726
class FormatConverter(object):
1827

1928
@classmethod
2029
def convert(cls, args=None):
2130
"""
2231
Enable usage of the argparse for calling convert_dir(...)
2332
Example:
24-
1) >> python format_converter.py ./..path../input_dir v1_1 -out ./..path../output_dir -r
33+
1) >> python -m odml.tools.converters.format_converter ./..path../input_dir v1_1 -out ./..path../output_dir -r
2534
2635
Convert files from the path <./..path../input_dir> to .xml odml version 1.1,
2736
writes them into <./..path../output_dir> including subdirectories
2837
and its files from the input path.
2938
30-
2) >> python format_converter.py ./..path../input_dir odml
39+
2) >> python -m odml.tools.converters.format_converter ./..path../input_dir odml
3140
3241
Converts files from path <./..path../input_dir> to .odml,
3342
writes them into <./..path../input_dir_odml> not including subdirectories.
3443
"""
3544
parser = argparse.ArgumentParser(description="Convert directory with odml files to another format")
3645
parser.add_argument("input_dir", help="Path to input directory")
37-
parser.add_argument("result_format", choices=list(ConversionFormats),
46+
parser.add_argument("result_format", choices=list(CONVERSION_FORMATS),
3847
help="Format of output files")
3948
parser.add_argument("-out", "--output_dir", help="Path for output directory")
4049
parser.add_argument("-r", "--recursive", action="store_true",
@@ -54,11 +63,11 @@ def convert_dir(cls, input_dir, output_dir, parse_subdirs, res_format):
5463
Possible choices: "v1_1" (converts to version 1.1 from version 1 xml)
5564
"odml" (converts to .odml from version 1.1 .xml files)
5665
"turtle", "nt" etc. (converts to rdf formats from version 1.1 .odml files)
57-
(see full list of rdf serializers in utils.ConversionFormats)
66+
(see full list of rdf serializers in CONVERSION_FORMATS)
5867
"""
59-
if res_format not in ConversionFormats:
68+
if res_format not in CONVERSION_FORMATS:
6069
raise ValueError("Format for output files is incorrect. "
61-
"Please choose from the list: {}".format(list(ConversionFormats)))
70+
"Please choose from the list: {}".format(list(CONVERSION_FORMATS)))
6271

6372
cls._check_input_output_directory(input_dir, output_dir)
6473
input_dir = os.path.join(input_dir, '')
@@ -98,14 +107,14 @@ def _convert_file(cls, input_path, output_path, res_format):
98107
p, _ = os.path.splitext(output_path)
99108
output_path = p + ".odml"
100109
odml.save(odml.load(input_path), output_path)
101-
elif res_format in ConversionFormats:
102-
if not output_path.endswith(ConversionFormats[res_format]):
110+
elif res_format in CONVERSION_FORMATS:
111+
if not output_path.endswith(CONVERSION_FORMATS[res_format]):
103112
p, _ = os.path.splitext(output_path)
104-
output_path = p + ConversionFormats[res_format]
113+
output_path = p + CONVERSION_FORMATS[res_format]
105114
RDFWriter(odml.load(input_path)).write_file(output_path, res_format)
106115
else:
107116
raise ValueError("Format for output files is incorrect. "
108-
"Please choose from the list: {}".format(list(ConversionFormats)))
117+
"Please choose from the list: {}".format(list(CONVERSION_FORMATS)))
109118

110119
@staticmethod
111120
def _create_sub_directory(dir_path):

0 commit comments

Comments
 (0)