Skip to content

Commit

Permalink
style(*): fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mostaphaRoudsari committed Jul 4, 2020
1 parent f1c6529 commit babf240
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 120 deletions.
2 changes: 1 addition & 1 deletion honeybee_radiance_command/cutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def parse_radiance_options(string):
elif count == 1:
values = values[0]
options[k[1:]] = values

return options


Expand Down
19 changes: 8 additions & 11 deletions honeybee_radiance_command/options/_optutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _gen_opt_file(command, folder='.'):
imports = \
'from .optionbase import OptionCollection, BoolOption, NumericOption,' \
' StringOption,\\\n StringOptionJoined, IntegerOption, TupleOption'


HEADER = '{0}\n\nclass {1}Options(OptionCollection):\n' \
' """{2} command options."""\n\n' \
Expand All @@ -32,13 +32,12 @@ def _gen_opt_file(command, folder='.'):
' """{2} command options."""\n'
' OptionCollection.__init__(self)\n' \

# run the command a parse the output
# run the command and parse the output
def get_defaults(command):
data = subprocess.check_output([command, '-defaults'])
# only works in python 3
return "".join(chr(x) for x in data).split('\r\n')


def get_set_property(parameter: str, comment: str) -> str:
"""Create @property setter and getter string."""
base_get = '\t@property\n\tdef {0}(self):\n\t\t"""{1}"""\n\t\treturn self._{0}'
Expand Down Expand Up @@ -68,19 +67,17 @@ def bool_option(parameter: str, value: str, raw_comment: str) -> Tuple[str]:
slot.replace("'", ''), parameter, comment)

init_line = init_line.replace('\t', ' ')
return slot, init_line, get_set_property(parameter, comment)

return slot, init_line, get_set_property(parameter, comment)

def string_option(parameter: str, value: str, raw_comment: str) -> Tuple[str]:
"""Parse a Radiance string option documentation."""
"""Parse a Radiance string option documentation."""
slot = "'_%s'" % parameter
comment = raw_comment + ' - default: %s%s' % (parameter, value)
init_line = "\t\tself.%s = StringOptionJoined('%s', '%s')" % (
slot.replace("'", ''), parameter, comment)

init_line = init_line.replace('\t', ' ')
return slot, init_line, get_set_property(parameter, comment)

return slot, init_line, get_set_property(parameter, comment)

def numeric_option(parameter: str, value: str, raw_comment: str) -> Tuple[str]:
"""Parse a Radiance numeric option documentation."""
Expand All @@ -98,7 +95,7 @@ def numeric_option(parameter: str, value: str, raw_comment: str) -> Tuple[str]:
slot.replace("'", ''), parameter, comment)

init_line = init_line.replace('\t', ' ')
return slot, init_line, get_set_property(parameter, comment)
return slot, init_line, get_set_property(parameter, comment)

def tuple_option(parameter: str, values: List[str], raw_comment: str) -> Tuple[str]:
"""Parse a Radiance tuple option documentation."""
Expand All @@ -116,7 +113,7 @@ def tuple_option(parameter: str, values: List[str], raw_comment: str) -> Tuple[s
)

init_line = init_line.replace('\t', ' ')
return slot, init_line, get_set_property(parameter, comment)
return slot, init_line, get_set_property(parameter, comment)

def parse_line(line: str):
"""Parse input line."""
Expand Down Expand Up @@ -161,7 +158,7 @@ def parse_line(line: str):
fdir = os.path.dirname(__file__)
os.chdir(fdir)
file_path = os.path.join(folder, '%s.py' % command)

with open(file_path, 'w') as output:
output.write(header)
output.write('\n'.join(inits))
Expand Down
6 changes: 3 additions & 3 deletions honeybee_radiance_command/options/oconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def i(self, value):
@property
def b(self):
"""Scene bounding cube.
The -b option allows the user to give a bounding cube for the scene, starting at
xmin ymin zmin and having a side length size. If the cube does not contain all of
the surfaces, an error results.
The -b and -i options are mutually exclusive.
"""
return self._b
Expand All @@ -82,7 +82,7 @@ def n(self, value):
@property
def r(self):
"""Maximum octree resolution - default: 16384.
The -r option specifies the maximum octree resolution. This should be greater
than or equal to the ratio of the largest and smallest dimensions in the scene
(ie. surface size or distance between surfaces). The default is 16384.
Expand Down
15 changes: 7 additions & 8 deletions honeybee_radiance_command/options/optionbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import honeybee_radiance_command.cutil as cutil
import honeybee_radiance_command._exception as exceptions
import honeybee_radiance_command.cutil as futil
import os
import warnings
from itertools import chain
import re


Expand Down Expand Up @@ -125,11 +123,12 @@ def __len__(self):
else:
return 0


class StringOption(FileOption):
__slots__ = ('valid_values', 'whole', 'pattern_in', 'pattern_out')

def __init__(self, name, description, value=None, valid_values=None, whole=True,
pattern_in=None, pattern_out=None):
pattern_in=None, pattern_out=None):
"""A string Radiance option.
Args:
Expand Down Expand Up @@ -173,12 +172,12 @@ def value(self, value):
if self.whole:
if value not in self.valid_values:
raise exceptions.InvalidValueError(self.name, value,
self.valid_values)
self.valid_values)
else:
for v in value:
if v not in self.valid_values:
raise exceptions.InvalidValueError(self.name, v,
self.valid_values)
self.valid_values)

self._value = value if not self.pattern_out else self.pattern_out % value

Expand Down Expand Up @@ -321,7 +320,7 @@ def value(self, value):
if value is not None:
# this is a special case to handle read from string when + is not used
# in Radiance -I means -I+ and -h means -h+ and so on.
value = True if value == '' else value
value = True if value == '' else value
self._value = False if value == '-' else bool(value)
else:
self._value = None
Expand Down Expand Up @@ -391,7 +390,7 @@ class OptionCollection(object):
def __init__(self):
# run on_setattr method on every attribute assignment
# set to False if you are assigning several attributes all together when
# initiating a new instance.
# initiating a new instance.
object.__setattr__(self, '_on_setattr_check', False)
self.additional_options = {}
# collection of protected options that cannot be set by user. This is necessary
Expand Down Expand Up @@ -452,7 +451,7 @@ def update_from_string(self, string):
else:
setattr(self, p[1], p[1:])
except AttributeError:
# fall back to unknown item
# fall back to unknown item
pass
else:
# it is assigned - go for the next one
Expand Down
45 changes: 23 additions & 22 deletions honeybee_radiance_command/options/rcalc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Rcalc parameters."""
from .optionbase import OptionCollection, FileOption, TupleOption, IntegerOption, \
BoolOption, StringOption, StringOptionJoined
from .optionbase import OptionCollection, BoolOption, StringOption, StringOptionJoined
import warnings


Expand All @@ -18,10 +17,12 @@ def __init__(self):
"""rcalc command options."""
OptionCollection.__init__(self)
self._tS = StringOption('ts', 'alternative tab character')
self._i = StringOptionJoined('i', 'alternative input format',
valid_values=['d', 'f', 'D', 'F'])
self._o = StringOptionJoined('o', 'alternative output format',
valid_values=['d', 'f', 'D', 'F'])
self._i = StringOptionJoined(
'i', 'alternative input format', valid_values=['d', 'f', 'D', 'F']
)
self._o = StringOptionJoined(
'o', 'alternative output format', valid_values=['d', 'f', 'D', 'F']
)
self._p = BoolOption('p', 'alternative / passive mode for input format')
self._b = BoolOption('b', 'accept exact matches')
self._l = BoolOption('l', 'ignore newlines in the input')
Expand All @@ -39,7 +40,7 @@ def _on_setattr(self):
Use this method to add checks that are necessary for OptionCollection. For
instance in rtrace option collection -ti and -te are exclusive. You can include a
check to ensure this is always correct.
"""
"""
if self.p.is_set and not self.i.is_set:
warnings.warn('rcalc: -p has no effect unless -i is also specified.')

Expand All @@ -55,7 +56,7 @@ def tS(self, value):
@property
def i(self):
"""Alternative input format.
A -i format option specifies a template for an alternate input record format.
Format is interpreted as a specification string if it contains a dollar sign `$`.
Otherwise, it is interpreted as the name of the file containing the format
Expand All @@ -64,7 +65,7 @@ def i(self):
immediately by a `d` or an `f` and an optional count, which defaults to 1,
indicating the number of double or float binary values to read per record on the
input file. If the input is byte-swapped, the -iD or -iF options may be
substituted. If binary input is specified, no format string or file is needed.
substituted. If binary input is specified, no format string or file is needed.
"""
return self._i

Expand All @@ -75,12 +76,12 @@ def i(self, value):
@property
def o(self):
"""Alternative output format.
A -o format option specifies an alternate output record format. It is interpreted
the same as an input specification, except that the special -od or -of options do
not require a count, as this will be determined by the number of output channels
in the given expressions. If byte-swapped output is desired, the -oD or -oF
options may be substituted.
options may be substituted.
"""
return self._o

Expand All @@ -91,7 +92,7 @@ def o(self, value):
@property
def p(self):
"""Alternative / passive mode for input format.
The -p option specifies "passive mode," where characters that do not match the
input format are passed unaltered to the output. This option has no effect unless
-i is also specified, and does not make much sense unless -o is also given. With
Expand All @@ -108,9 +109,9 @@ def p(self, value):
@property
def b(self):
"""Accept exact matches.
The -b option instructs the program to accept only exact matches. By default,
tabs and spaces are ignored except as field separators.
tabs and spaces are ignored except as field separators.
"""
return self._b

Expand All @@ -121,11 +122,11 @@ def b(self, value):
@property
def l(self):
"""Ignore newlines in the input.
The -l option instructs the program to ignore newlines in the input, basically
treating them the same as tabs and spaces. Normally, the beginning of the input
format matches the beginning of a line, and the end of the format matches the end
of a line. With the -l option, the input format can match anywhere on a line.
of a line. With the -l option, the input format can match anywhere on a line.
"""
return self._l

Expand Down Expand Up @@ -154,7 +155,7 @@ def u(self, value):
@property
def n(self):
"""Produce single output record.
The -n option tells the program not to get any input, but to produce a single
output record. Otherwise, if no files are given, the standard input is read.
"""
Expand All @@ -167,7 +168,7 @@ def n(self, value):
@property
def f(self):
"""Source file.
The variable and function definitions in each -f source file are read and
compiled.
"""
Expand All @@ -180,10 +181,10 @@ def f(self, value):
@property
def s(self):
"""Assign a string variable a string value.
The -s svar=sval option can be used to assign a string variable a string value.
If this string variable appears in an input format, only records with the
specified value will be processed.
specified value will be processed.
"""
return self._s

Expand All @@ -194,10 +195,10 @@ def s(self, value):
@property
def e(self):
"""Expression.
The -e expr option can be used to define variables on the command line. Since
many of the characters in an expression have special meaning to the shell, it
should usually be enclosed in single quotes.
should usually be enclosed in single quotes.
"""
return self._e

Expand Down
Loading

0 comments on commit babf240

Please sign in to comment.