Skip to content

Commit

Permalink
feat: fixed ruff suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
bagjohn committed Oct 30, 2024
1 parent 469f90c commit 02f572c
Show file tree
Hide file tree
Showing 143 changed files with 999 additions and 1,272 deletions.
2 changes: 1 addition & 1 deletion docs/readme_link.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.. include:: ../../README.md
.. include:: ../README.md
6 changes: 2 additions & 4 deletions docs/tutorials/CONFTYPES.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"metadata": {},
"outputs": [],
"source": [
"import larvaworld\n",
"\n",
"from larvaworld.lib import util, reg, process, sim"
"from larvaworld.lib import reg, sim, util"
]
},
{
Expand Down Expand Up @@ -106,7 +104,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(f\"The number of stored configurations per conftype & some example IDs:\")\n",
"print(\"The number of stored configurations per conftype & some example IDs:\")\n",
"print()\n",
"for k in reg.CONFTYPES:\n",
" ct = reg.conf[k]\n",
Expand Down
3 changes: 1 addition & 2 deletions docs/tutorials/LabFormat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"outputs": [],
"source": [
"%load_ext param.ipython\n",
"from param.ipython import ParamPager\n",
"import panel as pn"
]
},
Expand All @@ -35,7 +34,7 @@
"metadata": {},
"outputs": [],
"source": [
"from larvaworld.lib import reg, process\n",
"from larvaworld.lib import reg\n",
"\n",
"reg.VERBOSE = 1"
]
Expand Down
420 changes: 5 additions & 415 deletions docs/tutorials/environment_configuration.ipynb

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions docs/tutorials/replay.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from larvaworld.lib import util, reg, process\n",
"from larvaworld.lib import reg, util\n",
"from larvaworld.lib.sim.dataset_replay import ReplayRun\n",
"\n",
"reg.VERBOSE = 1"
Expand Down
3 changes: 1 addition & 2 deletions docs/tutorials/sensorscapes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"source": [
"import numpy as np\n",
"\n",
"from larvaworld.lib import util, reg, process, sim\n",
"from larvaworld.lib.sim.single_run import ExpRun\n",
"from larvaworld.lib import reg, sim, util\n",
"# reg.VERBOSE=1"
]
},
Expand Down
1 change: 0 additions & 1 deletion src/larvaworld/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

from .argparser import SimModeParser


__displayname__ = "CLI"
29 changes: 22 additions & 7 deletions src/larvaworld/cli/argparser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import List
from argparse import ArgumentParser
from typing import List

import param
from ..lib import reg, util, sim, screen
from ..lib.param import SimOps, RuntimeOps

from ..lib import reg, screen, sim, util
from ..lib.param import RuntimeOps, SimOps

# from ..lib.param.custom import ClassAttr, ClassDict

Expand Down Expand Up @@ -39,6 +41,7 @@ class SingleParserArgument:
A list containing the short and long argument names.
kwargs : dict
Additional keyword arguments.
"""

def __init__(self, short, key, **kwargs):
Expand All @@ -59,6 +62,7 @@ def add(self, p):
-------
argparse.ArgumentParser
The modified parser.
"""
p.add_argument(*self.args, **self.kwargs)
return p
Expand All @@ -76,6 +80,7 @@ def get(self, input):
-------
Any
The value of the argument.
"""
return getattr(input, self.key)

Expand All @@ -95,6 +100,7 @@ def from_dict(cls, name, **kwargs):
-------
SingleParserArgument
A SingleParserArgument instance.
"""
return cls(**parser_entry_from_dict(name, **kwargs))

Expand All @@ -114,6 +120,7 @@ def from_param(cls, k, p):
-------
SingleParserArgument
A SingleParserArgument instance.
"""
return cls(**parser_entry_from_param(k, p))

Expand All @@ -133,6 +140,7 @@ def parser_entry_from_param(k, p):
-------
dict
A dictionary entry for the parser argument.
"""
c = p.__class__
v = p.default
Expand Down Expand Up @@ -191,6 +199,7 @@ def parser_entry_from_dict(name, k=None, h="", dtype=float, v=None, vs=None, **k
-------
dict
A dictionary entry for the parser argument.
"""
if k is None:
k = name
Expand Down Expand Up @@ -238,6 +247,7 @@ def __init__(self, parsargs):
----------
parsargs : dict
A dictionary of parser arguments.
"""
self.parsargs = parsargs

Expand All @@ -255,6 +265,7 @@ def from_param(cls, d0):
-------
ParserArgumentDict
A ParserArgumentDict instance.
"""
return cls(parser_dict_from_param(d0))

Expand All @@ -272,6 +283,7 @@ def from_dict(cls, d0):
-------
ParserArgumentDict
A ParserArgumentDict instance.
"""
return cls(parser_dict_from_dict(d0))

Expand All @@ -288,6 +300,7 @@ def add(self, parser=None):
-------
argparse.ArgumentParser
The modified ArgumentParser.
"""
if parser is None:
parser = ArgumentParser()
Expand All @@ -308,6 +321,7 @@ def get(self, input):
-------
dict
A dictionary of argument values.
"""
dic = util.AttrDict({k: v.get(input) for k, v in self.parsargs.items()})
return dic.unflatten()
Expand All @@ -326,8 +340,8 @@ def parser_dict_from_param(d0):
-------
dict
A dictionary of parser arguments.
"""
"""
# dv0 = aux.AttrDict(d0.param.values())

d = util.AttrDict()
Expand Down Expand Up @@ -360,6 +374,7 @@ def parser_dict_from_dict(d0):
-------
dict
A dictionary of parser arguments.
"""
p = util.AttrDict()
for n, v in d0.items():
Expand Down Expand Up @@ -585,13 +600,13 @@ def show_args(self, nested=True, flat_nested=False, input=False, run_args=True):
"""
print(f"Simulation mode : {self.mode}")
if nested:
print(f"Simulation args as nested dictionary: ")
print("Simulation args as nested dictionary: ")
self.run_kws.print(flat=False)
if flat_nested:
print(f"Simulation args as flattened nested dictionary: ")
print("Simulation args as flattened nested dictionary: ")
self.run_kws.print(flat=True)
if input:
print(f"Input args : ")
print("Input args : ")
self.args.print(flat=True)
if run_args:
if hasattr(self.run, "configuration_text"):
Expand Down
1 change: 0 additions & 1 deletion src/larvaworld/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ..lib import reg, util
from .argparser import SimModeParser


Expand Down
2 changes: 1 addition & 1 deletion src/larvaworld/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The larvaworld Graphical User Interface (GUI)
"""

from . import gui_aux, tabs, panel
from . import gui_aux, panel, tabs

# print('jj')
__displayname__ = "GUI"
2 changes: 1 addition & 1 deletion src/larvaworld/gui/gui_aux/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import PySimpleGUI as sg

from ...lib import reg
from ...gui import gui_aux
from ...lib import reg

__all__ = [
"b_kws",
Expand Down
3 changes: 2 additions & 1 deletion src/larvaworld/gui/gui_aux/dtypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import typing

import numpy as np

from ...lib import reg

__all__ = [
Expand Down
21 changes: 10 additions & 11 deletions src/larvaworld/gui/gui_aux/elements.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import copy
import inspect
import os
from typing import Tuple, List
import sys

from typing import List, Tuple

if sys.version_info >= (3, 8):
from typing import TypedDict # pylint: disable=no-name-in-module
else:
from typing_extensions import TypedDict
import matplotlib.pyplot as plt
import numpy as np
import PySimpleGUI as sg
import matplotlib.pyplot as plt

from ...lib import reg, util
from ...gui import gui_aux
from ...lib import reg, util

__all__ = [
"SYMBOL_UP",
Expand Down Expand Up @@ -1494,7 +1493,7 @@ def build(self, name, **kwargs):
k0,
dict_name=args["entry"],
disp_name=args["disp"],
index=f"ID",
index="ID",
**subkws,
)
ii = self.subdicts[k0].get_layout()[0]
Expand Down Expand Up @@ -2042,18 +2041,18 @@ def evaluate(self):
w.close()
return False
elif e == "Choose":
w[f"-COL2-"].update(visible=False)
w[f"-COL1-"].update(visible=True)
w["-COL2-"].update(visible=False)
w["-COL1-"].update(visible=True)
self.cur_layout = 1
elif e == "Ok":
w[f"-COL1-"].update(visible=False)
w[f"-COL2-"].update(visible=True)
w["-COL1-"].update(visible=False)
w["-COL2-"].update(visible=True)
self.pars = [p for p in self.available_pars if v[f"k_{p}"]]
self.update_pars()
self.cur_layout = 2
elif e == "Cancel":
w[f"-COL1-"].update(visible=False)
w[f"-COL2-"].update(visible=True)
w["-COL1-"].update(visible=False)
w["-COL2-"].update(visible=True)
self.cur_layout = 2
if self.cur_layout == 2 and self.Npars > 0:
secs = v["-SLIDER-TIME-"]
Expand Down
2 changes: 1 addition & 1 deletion src/larvaworld/gui/gui_aux/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_disp_name(name) -> str:


def retrieve_value(v, t):
from typing import List, Tuple, Union, Type
from typing import List, Tuple, Type, Union

if v in ["", "None", None, ("", ""), ("", "")]:
vv = None
Expand Down
3 changes: 1 addition & 2 deletions src/larvaworld/gui/gui_aux/par_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from ...lib import reg


__all__ = [
"tree_dict",
"pars_to_tree",
Expand All @@ -18,7 +17,7 @@ def tree_dict(d, parent_key="", sep="."):

def add(item):
entry = dict(zip(cols, item))
if not entry["key"] in keys:
if entry["key"] not in keys:
entries.append(entry)
keys.append(entry["key"])

Expand Down
7 changes: 3 additions & 4 deletions src/larvaworld/gui/gui_aux/png_to_b64.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import PySimpleGUI as sg
import os
import base64
from PIL import Image
import os
from io import BytesIO

import PySimpleGUI as sg
from PIL import Image

__all__ = ["png_to_b64", "bs64_to_png"]


def png_to_b64():
# Base64 Encoder - encodes a folder of PNG files and creates a .py file with definitions

"""
Make base64 images
input: folder with .png .ico .gif 'sigma
Expand Down
8 changes: 4 additions & 4 deletions src/larvaworld/gui/gui_aux/windows.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import PySimpleGUI as sg

import PySimpleGUI as sg

from ...gui import gui_aux
from ...lib import reg, util
Expand Down Expand Up @@ -222,7 +222,7 @@ def delete_conf_window(id, conftype, disp=None):
)
]
]
e, v = sg.Window(f"Delete configuration", l, size=(500, 250)).read(close=True)
e, v = sg.Window("Delete configuration", l, size=(500, 250)).read(close=True)
if e == "Ok":
# reg.stored.delete(id=id, conftype=conftype)
reg.conf[conftype].delete(id)
Expand Down Expand Up @@ -437,7 +437,7 @@ def import_window(labID, raw_dic):
del proc_dir[target_id]

else:
print(f"------ Building a single merged dataset ------")
print("------ Building a single merged dataset ------")
target_id0 = v[f"new_{raw_ids[0]}"]

if labID in ["Berni", "Arguello"]:
Expand All @@ -464,7 +464,7 @@ def import_window(labID, raw_dic):
**kws,
}
elif labID in ["Jovanic"]:
raise NotImplemented
raise NotImplementedError
dd = g.import_dataset(**kws0)
proc_dir[dd.id] = dd
break
Expand Down
1 change: 1 addition & 0 deletions src/larvaworld/gui/panel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from . import track_viewer

# from .track_viewer import TrackViewer

__displayname__ = "Dashboards"
Loading

0 comments on commit 02f572c

Please sign in to comment.