Skip to content

Commit

Permalink
New black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Helveg committed Oct 5, 2020
1 parent 237f294 commit 317596b
Show file tree
Hide file tree
Showing 57 changed files with 890 additions and 813 deletions.
18 changes: 9 additions & 9 deletions bsb/blender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def create_collection(name, parent=None):
"""
Create a collection in the blender scene.
Create a collection in the blender scene.
"""
coll_diff = _diffkey(bpy.data.collections)
bpy.ops.collection.create(name=name)
Expand All @@ -29,8 +29,8 @@ def __init__(self, collection, cells):

def create_population(name, material, cells, parent=None, scene=None, radius=3.0):
"""
Create a cell population where each cell is represented by a sphere in 3D space.
Each cell population will have a matte material associated with it.
Create a cell population where each cell is represented by a sphere in 3D space.
Each cell population will have a matte material associated with it.
"""
if scene is None:
scene = bpy.context.scene
Expand All @@ -50,8 +50,8 @@ def create_population(name, material, cells, parent=None, scene=None, radius=3.0

def create_material(name, color=(0.8, 0.8, 0.8, 1.0)):
"""
Create a material with a certain base color. The 4th float of the color is the
opacity.
Create a material with a certain base color. The 4th float of the color is the
opacity.
"""
mat = bpy.data.materials.new(name=name)
mat.use_nodes = True
Expand All @@ -66,7 +66,7 @@ def create_material(name, color=(0.8, 0.8, 0.8, 1.0)):

def create_pulsar_material(name, color, max_intensity=1.0):
"""
Create a material capable of lighting up.
Create a material capable of lighting up.
"""
mat = bpy.data.materials.new(name=name)
mat["pulsar"] = True
Expand Down Expand Up @@ -109,7 +109,7 @@ def create_pulsar_material(name, color, max_intensity=1.0):

def get_population(collection, cells, partial=False):
"""
Load or create a collection from a certain collection. Returns the loaded objects.
Load or create a collection from a certain collection. Returns the loaded objects.
"""
index = {int(c["cell_id"]): c for c in collection.objects.values()}
if partial:
Expand All @@ -134,8 +134,8 @@ def get_population(collection, cells, partial=False):

def get_populations(collections, cells, partial=False):
"""
Zips a list of collections and a list of cell lists and passes them to
`get_population`. Returns the results as a list.
Zips a list of collections and a list of cell lists and passes them to
`get_population`. Returns the results as a list.
"""
return [get_population(c, p) for c, p in zip(collections, cells, partial=partial)]

Expand Down
18 changes: 9 additions & 9 deletions bsb/blender/_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

def create_network(self, scene, name):
"""
Creates the root collection that will contain all the blender components of this
network and a child collection for the cell populations. Fills the scene with a
default camera and light if they are missing.
Creates the root collection that will contain all the blender components of this
network and a child collection for the cell populations. Fills the scene with a
default camera and light if they are missing.
"""
self._blender_scene = scene
self._blender_collection = coll = _main.create_collection(name)
Expand All @@ -33,7 +33,7 @@ def _load_blender_network(self, scene, root_collection):

def blend(self, scene, name):
"""
Create or load the network from the given scene.
Create or load the network from the given scene.
"""
if name in scene.collection.children:
_load_blender_network(self, scene, scene.collection.children[name])
Expand Down Expand Up @@ -68,8 +68,8 @@ def create_population(self, tag, material=None, color=None):

def ensure_population(self, tag):
"""
Load a cell population onto the scene, does nothing if it already exists. Entities
are also ignored.
Load a cell population onto the scene, does nothing if it already exists. Entities
are also ignored.
"""
ps = self.get_placement_set(tag)
if not ps.type.entity and not self.has_population(tag):
Expand All @@ -78,15 +78,15 @@ def ensure_population(self, tag):

def ensure_populations(self):
"""
Load all cell populations from the scene, skipping relays.
Load all cell populations from the scene, skipping relays.
"""
for tag in self.configuration.cell_types:
self.load_population(tag)


def get_population(self, tag, partial=False):
"""
Get a cell population from the scene or create them.
Get a cell population from the scene or create them.
"""
type = self.get_cell_type(tag)
if type.entity:
Expand All @@ -110,7 +110,7 @@ def get_populations(self, partial=False):

def has_population(self, tag):
"""
Check whether a given population of the network already exists in the scene.
Check whether a given population of the network already exists in the scene.
"""
return tag in self._blender_cells_collection.children

Expand Down
97 changes: 50 additions & 47 deletions bsb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def scaffold_cli():
"""
console_scripts entry point for the scaffold package. Will start the CLI handler or REPL handler.
console_scripts entry point for the scaffold package. Will start the CLI handler or REPL handler.
"""
args = sys.argv[1:]
if len(args) == 0: # Start the REPL?
Expand All @@ -28,8 +28,8 @@ def scaffold_cli():

def check_positive_factory(name):
"""
Return a function to report whether a certain value is a positive integer.
If it isn't, raise an ArgumentTypeError.
Return a function to report whether a certain value is a positive integer.
If it isn't, raise an ArgumentTypeError.
"""
# Define factory product function.
def f(x):
Expand All @@ -50,7 +50,7 @@ def f(x):

def start_repl():
"""
Scaffold package REPL handler. Will parse user commands.
Scaffold package REPL handler. Will parse user commands.
"""
# TODO: Add a python environment with access to globals like a scaffold or morphology repository
state = ReplState()
Expand All @@ -63,7 +63,7 @@ def start_repl():

def start_cli():
"""
Scaffold package CLI handler
Scaffold package CLI handler
"""
# Parser
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -264,7 +264,7 @@ def create_config(args):

class ReplState:
"""
Stores the REPL state and executes each step of the REPL.
Stores the REPL state and executes each step of the REPL.
"""

def __init__(self):
Expand All @@ -280,7 +280,7 @@ def __init__(self):

def repl(self):
"""
Execute the next repl step.
Execute the next repl step.
"""
# Ask for user input
self.command = input(
Expand Down Expand Up @@ -318,9 +318,9 @@ def repl(self):

def update_parser(self):
"""
Creates a new parser for the next REPL step. Tries to add
subparsers and arguments if the method "set_parser_``state``_state"
is callable.
Creates a new parser for the next REPL step. Tries to add
subparsers and arguments if the method "set_parser_``state``_state"
is callable.
"""
self.parser = StateParser(add_help=False)
self.subparsers = self.parser.add_subparsers()
Expand All @@ -334,7 +334,7 @@ def update_parser(self):

def set_parser_base_state(self):
"""
Adds the initial subparsers and arguments to the REPL parser.
Adds the initial subparsers and arguments to the REPL parser.
"""
parser_open = self.add_subparser(
"open",
Expand All @@ -361,8 +361,8 @@ def set_parser_base_state(self):

def set_parser_base_mr_state(self):
"""
Adds the morphology repository state subparsers and arguments to
the REPL parser.
Adds the morphology repository state subparsers and arguments to
the REPL parser.
"""
mr = self.globals["mr"]

Expand Down Expand Up @@ -412,7 +412,10 @@ def set_parser_base_mr_state(self):
"model", action="store", help="Importable class of the model"
)
arbz_parser.add_argument(
"name", action="store", help="Unique name of the morphology.", nargs="?",
"name",
action="store",
help="Unique name of the morphology.",
nargs="?",
)
arbz_parser.set_defaults(func=lambda args: repl_import_arbz(mr, args))

Expand Down Expand Up @@ -450,7 +453,7 @@ def set_parser_base_mr_state(self):

def set_parser_base_hdf5_state(self):
"""
Adds the HDF5 state subparsers and arguments to the REPL parser.
Adds the HDF5 state subparsers and arguments to the REPL parser.
"""
h = self.globals["hdf5"]

Expand Down Expand Up @@ -478,55 +481,55 @@ def plot_handler(args):

def add_parser_globals(self):
"""
Adds subparsers and arguments that should be there in any state.
Adds subparsers and arguments that should be there in any state.
"""
exit_parser = self.add_subparser("exit")
exit_parser.set_defaults(func=self.exit_repl)

def add_subparser(self, *args, **kwargs):
"""
Add a top level subparser to the current REPL parser.
Add a top level subparser to the current REPL parser.
"""
return self.subparsers.add_parser(*args, **kwargs)

def exit_repl(self, args):
"""
Exit the REPL.
Exit the REPL.
"""
self.exit = True

def clear_prefix(self):
"""
Clear the REPL prefix.
Clear the REPL prefix.
"""
self.prefix = None

def set_next_state(self, state):
"""
Set the next REPL state.
Set the next REPL state.
:param state: The next state. For each state there should be a set_parser_``state``_state function (e.g. :func:`set_parser_base_state`).
:type state: string
:rtype: None
:param state: The next state. For each state there should be a set_parser_``state``_state function (e.g. :func:`set_parser_base_state`).
:type state: string
:rtype: None
"""
self.next = state

def set_reply(self, message):
"""
Set the REPL reply, to be printed to the user at the end of this step.
Set the REPL reply, to be printed to the user at the end of this step.
:param message: The reply to print.
:type message: string
:rtype: None
:param message: The reply to print.
:type message: string
:rtype: None
"""
self.reply = str(message)

def close_hdf5(self):
"""
Closes the currently open HDF5 file.
Closes the currently open HDF5 file.
:raises ParseError: Raised if there's no open HDF5 file.
:rtype: None
:raises ParseError: Raised if there's no open HDF5 file.
:rtype: None
"""
if self.globals["hdf5"] is None:
raise ParseError("No HDF5 file is currently opened.")
Expand All @@ -535,18 +538,18 @@ def close_hdf5(self):

def destroy_globals(self):
"""
Always called before the REPL exits to clean up open resources.
Always called before the REPL exits to clean up open resources.
"""
if "hdf5" in self.globals and not self.globals["hdf5"] is None:
self.close_hdf5()

def open_morphology_repository(self, args):
"""
Callback function that handles the ``open mr`` command.
Callback function that handles the ``open mr`` command.
:param args: Result of ArgumentParser.parse_args()
:type args: Namespace
:rtype: None
:param args: Result of ArgumentParser.parse_args()
:type args: Namespace
:rtype: None
"""
from .output import MorphologyRepository

Expand All @@ -568,11 +571,11 @@ def open_morphology_repository(self, args):

def open_hdf5(self, args):
"""
Callback function that handles the ``open hdf5`` command.
Callback function that handles the ``open hdf5`` command.
:param args: Result of ArgumentParser.parse_args()
:type args: Namespace
:rtype: None
:param args: Result of ArgumentParser.parse_args()
:type args: Namespace
:rtype: None
"""
# Import the HDF5 library.
import h5py
Expand All @@ -587,29 +590,29 @@ def open_hdf5(self, args):

class ParseError(Exception):
"""
Thrown when the parsing of a command string fails.
Thrown when the parsing of a command string fails.
"""

pass


class StateParser(argparse.ArgumentParser):
"""
Inherits from argparse.ArgumentParser and overloads the ``error``
method so that when an error occurs, instead of exiting and exception
is thrown.
Inherits from argparse.ArgumentParser and overloads the ``error``
method so that when an error occurs, instead of exiting and exception
is thrown.
"""

def error(self, message):
"""
Overloads default exit behavior with throwing ParseError.
Overloads default exit behavior with throwing ParseError.
"""
raise ParseError(message)


def repl_plot_morphology(morphology_repository, args):
"""
Callback function that handles ``plot`` command in the *base_mr* state.
Callback function that handles ``plot`` command in the *base_mr* state.
"""
m = morphology_repository.get_morphology(args.name)
from .plotting import plot_morphology
Expand All @@ -619,7 +622,7 @@ def repl_plot_morphology(morphology_repository, args):

def repl_voxelize(morphology_repository, args):
"""
Callback function that handles ``voxelize`` command in the *base_mr* state.
Callback function that handles ``voxelize`` command in the *base_mr* state.
"""
m = morphology_repository.get_morphology(args.name)
m.voxelize(args.voxels)
Expand All @@ -628,7 +631,7 @@ def repl_voxelize(morphology_repository, args):

def repl_view_hdf5(handle, args):
"""
Callback function that handles ``view`` command in the *base_hdf5* state.
Callback function that handles ``view`` command in the *base_hdf5* state.
"""
df = chr(172)

Expand Down

0 comments on commit 317596b

Please sign in to comment.