Skip to content

Commit

Permalink
Fixed lints
Browse files Browse the repository at this point in the history
  • Loading branch information
susuhahnml committed Aug 5, 2024
1 parent e94bc27 commit 49ea9cf
Show file tree
Hide file tree
Showing 36 changed files with 109 additions and 157 deletions.
1 change: 1 addition & 0 deletions clinguin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Clinguin package - package entry point
"""

import copy
import sys
import threading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This package contains all tkinter_elements that are provided in clinguin.
"""

from .button import Button
from .canvas import Canvas
from .container import Container
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Contains the canvas class.
"""

import base64
import io
import tkinter as tk
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module features the MenuBar class.
"""

import tkinter as tk

from .root_cmp import RootCmp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module contains the menu bar section class.
"""

import tkinter as tk

from clinguin.utils.attribute_types import StringType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Contains the Message class.
"""

import tkinter as tk
from tkinter import messagebox

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module contains various utils for tkinter-elements, which reduce code size, etc.
"""

from .attribute_names import AttributeNames
from .call_back_definition import CallBackDefinition
from .callback_names import CallbackNames
Expand Down
1 change: 1 addition & 0 deletions clinguin/client_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Helper for the client-startup-process
"""

from clinguin.client import ClientBase
from clinguin.utils import Logger

Expand Down
1 change: 1 addition & 0 deletions clinguin/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Server module, contains core-program classes.
"""

from .application.standard_json_encoder import StandardJsonEncoder
from .data.ui_state import UIState
from .presentation.endpoints import Endpoints
Expand Down
1 change: 1 addition & 0 deletions clinguin/server/application/attribute.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module contains the AttributeDto class.
"""

import json


Expand Down
37 changes: 22 additions & 15 deletions clinguin/server/application/backends/clingo_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"""
Module that contains the ClingoMultishotBackend.
"""
import functools
import logging
import time
import textwrap
import time
from functools import cached_property
from pathlib import Path
import functools
from typing import Any

from clingo import Control, parse_term
Expand Down Expand Up @@ -118,7 +118,8 @@ def register_options(cls, parser):
help=textwrap.dedent(
"""\
Optional timeout for searching for optimal models.
The timeout is not exactly enforced (might take longer) but only checked after each solution is found.
The timeout is not exactly enforced (might take longer)
but only checked after each solution is found.
"""
),
type=int,
Expand Down Expand Up @@ -172,7 +173,8 @@ def _restart(self):
It is automatically called when the server starts.
See Also:
:func:`~_init_command_line`, :func:`~_init_interactive`, :func:`~_outdate`, :func:`~_init_ctl`, :func:`~_ground`
:func:`~_init_command_line`, :func:`~_init_interactive`,
:func:`~_outdate`, :func:`~_init_ctl`, :func:`~_ground`
"""
self._init_command_line()
self._init_interactive()
Expand Down Expand Up @@ -232,7 +234,8 @@ def _init_command_line(self):
_constants (dict): The dictionary of constants provided via command line.
_clingo_ctl_arg (list): The list of clingo control arguments provided via command line.
If any command line arguments are added in :meth:`~ClingoBackend.register_options`, they should be initialized here.
If any command line arguments are added in :meth:`~ClingoBackend.register_options`,
they should be initialized here.
Example:
Expand Down Expand Up @@ -275,16 +278,19 @@ def _init_interactive(self):
_handler (clingo.SolveHandle): The handler set while browsing in the `next_solution` operation.
_iterator (iter): The iterator set while browsing in the `next_solution` operation.
_ctl (clingo.Control): The domain control set in `_init_ctl`.
_ui_state (:class:`UIState`): A UIState object used to handle the UI construction, set in every call to `_update_ui_state`.
_ui_state (:class:`UIState`): A UIState object used to handle the UI construction,
set in every call to `_update_ui_state`.
_atoms (set[str]): A set to store the atoms set dynamically in operations during the interaction.
_assumptions (set[str]): A set to store the assumptions set dynamically in operations during the interaction.
_assumptions (set[str]): A set to store the assumptions set dynamically in operations during the
interaction.
_externals (dict): A dictionary with true, false and released sets of external atoms
_model (list[clingo.Symbol]): The model set in `on_model`.
_unsat_core (list[int]): The unsatisfiable core set in `on_model`.
_cost (list): A list to store the cost set in `on_model`.
_optimal (bool): A boolean indicating if the solution is optimal, set in `on_model`.
_optimizing (bool): A boolean indicating if the solver is currently optimizing, set in `on_model`.
_messages (list[tuple[str,str,str]]): A list to store the messages (title, content, type) to be shown in the UI, set dynamically in operations during the interaction.
_messages (list[tuple[str,str,str]]): A list to store the messages (title, content, type) to be shown in
the UI, set dynamically in operations during the interaction.
"""
# Context: Set by the general handler of requests
self._context = []
Expand Down Expand Up @@ -431,7 +437,7 @@ def _set_constant(self, name: str, value: Any) -> None:
name = name.strip('"')
value = str(value).strip('"')
self._constants[name] = value
self._logger.debug(f"Constant {name} updated successfully to {value}")
self._logger.debug("Constant %s updated successfully to %s", name, value)

def _add_atom(self, predicate_symbol):
"""
Expand Down Expand Up @@ -461,7 +467,6 @@ def _prepare(self):
"""
Does any preparation before a solve call.
"""
pass

def _on_model(self, model):
"""
Expand Down Expand Up @@ -529,7 +534,7 @@ def _call_solver_with_cache(
The program tagged
"""
if self._is_browsing:
self._logger.debug(f"Returning cache for {ds_id}")
self._logger.debug("Returning cache for %s", ds_id)
return (
self._backup_ds_cache[ds_id] if ds_id in self._backup_ds_cache else ""
)
Expand Down Expand Up @@ -562,7 +567,7 @@ def _call_solver_with_cache(
)
return " ".join([str(s) + "." for s in list(tag(symbols, ds_tag))]) + "\n"

@functools.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None) # pylint: disable=[method-cache-max-size-none]
def _ui_uses_predicate(self, name: str, arity: int):
"""
Returns a truth value of weather the ui_files contain the given signature.
Expand All @@ -572,7 +577,7 @@ def _ui_uses_predicate(self, name: str, arity: int):
arity (int): Predicate arity
"""
transformer = UsesSignatureTransformer(name, arity)
self._logger.debug(f"Transformer parsing UI files to find {name}/{arity}")
self._logger.debug("Transformer parsing UI files to find %s/%s", name, arity)
transformer.parse_files(self._ui_files)
if not transformer.contained:
self._logger.debug(
Expand Down Expand Up @@ -768,7 +773,8 @@ def _ds_constants(self):
"""
Adds constants values.
Includes predicate ``_clinguin_const/2`` for each constant provided in the command line and used in the domain files.
Includes predicate ``_clinguin_const/2`` for each constant provided
in the command line and used in the domain files.
"""
prg = "#defined _clinguin_const/2. "
for k, v in self._constants.items():
Expand Down Expand Up @@ -926,7 +932,8 @@ def next_solution(self, opt_mode="ignore"):
)
)
self._logger.warning(
"No optimization statement provided in encoding but optimization condition provided in 'next_solution' operation. Exiting browsing."
"No optimization statement provided in encoding but optimization condition provided\
in 'next_solution' operation. Exiting browsing."
)
break
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
Module that contains the ClingoMultishotBackend.
"""

from clingo import parse_term, Control
from clingo import Control, parse_term
from clingo.script import enable_python

from clinguin.utils.annotations import overwrites, extends
from clinguin.server.application.backends import ClingoBackend
from clinguin.utils.annotations import extends, overwrites

from ....utils.logger import domctl_log

Expand Down
2 changes: 0 additions & 2 deletions clinguin/server/application/backends/clingodl_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
Module that contains the ClingoDL Backend.
"""

from pathlib import Path
import textwrap

from clingo import Control
from clingo.ast import ProgramBuilder, parse_files
from clingo.script import enable_python
from clingodl import ClingoDLTheory
Expand Down
10 changes: 6 additions & 4 deletions clinguin/server/application/backends/clingraph_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"""
Module that contains the ClingraphBackend.
"""
import functools
import textwrap
from pathlib import Path
import functools

from clingo import Control
from clingo.symbol import Function, String
Expand All @@ -19,9 +19,10 @@

# Self defined
from clinguin.utils import StandardTextProcessing, image_to_b64
from ....utils.transformer import UsesSignatureTransformer
from clinguin.utils.annotations import extends, overwrites

from ....utils.transformer import UsesSignatureTransformer


class ClingraphBackend(ClingoMultishotBackend):
"""
Expand All @@ -36,6 +37,7 @@ def _init_command_line(self):
Sets the arguments for computing clingraph images.
"""
super()._init_command_line()
# pylint: disable= attribute-defined-outside-init
self._clingraph_files = self._args.clingraph_files
self._select_model = self._args.select_model
self._type = self._args.type
Expand Down Expand Up @@ -199,7 +201,7 @@ def register_options(cls, parser):
help="Intermediate format. Use 'svg' for angular fronted and 'png' tkinter. (default: %(default)s)",
)

@functools.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None) # pylint: disable=[method-cache-max-size-none]
@overwrites(ClingoMultishotBackend)
def _ui_uses_predicate(self, name: str, arity: int):
"""
Expand All @@ -210,7 +212,7 @@ def _ui_uses_predicate(self, name: str, arity: int):
arity (int): Predicate arity
"""
transformer = UsesSignatureTransformer(name, arity)
self._logger.debug(f"Transformer parsing UI files to find {name}/{arity}")
self._logger.debug("Transformer parsing UI files to find %s/%s", name, arity)
transformer.parse_files(self._ui_files + self._clingraph_files)
return transformer.contained

Expand Down
20 changes: 12 additions & 8 deletions clinguin/server/application/backends/explanation_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import textwrap
from functools import cached_property

from clingo.script import enable_python
from clingexplaid.transformers import AssumptionTransformer
from clingexplaid.mus import CoreComputer

from ....utils.logger import domctl_log
from clingexplaid.transformers import AssumptionTransformer
from clingo.script import enable_python

from clinguin.server.application.backends.clingo_multishot_backend import (
ClingoMultishotBackend,
)
from clinguin.utils.annotations import extends

from ....utils.logger import domctl_log

enable_python()


Expand All @@ -33,7 +33,8 @@ class ExplanationBackend(ClingoMultishotBackend):
@property
def _assumption_list(self):
"""
Gets the set of assumptions used for solving. It includes the assumptions from the assumption signatures provided.
Gets the set of assumptions used for solving.
It includes the assumptions from the assumption signatures provided.
Warning:
Expand All @@ -56,6 +57,7 @@ def _init_interactive(self):
_mus (str): The list of assumptions in the MUS property
"""
super()._init_interactive()
# pylint: disable= attribute-defined-outside-init
self._mus = None

@extends(ClingoMultishotBackend)
Expand All @@ -68,6 +70,7 @@ def _init_command_line(self):
_assumption_transformer (clingexplaid.AssumptionTransformer): The transformer used for the input files
"""
super()._init_command_line()
# pylint: disable= attribute-defined-outside-init
self._assumption_sig = []
for a in self._args.assumption_signature or []:
try:
Expand Down Expand Up @@ -103,14 +106,15 @@ def _load_file(self, f):
# Solving
# ---------------------------------------------
@extends(ClingoMultishotBackend)
def _ground(self):
def _ground(self, program="base"):
"""
Sets the list of assumptions that were taken from the input files using the assumption_signature.
Attributes:
_assumptions_from_signature (Set[clingo.Symbol]): The set of assumptions from the assumption signatures
"""
super()._ground()
super()._ground(program)
# pylint: disable= attribute-defined-outside-init
self._assumptions_from_signature = (
self._assumption_transformer.get_assumption_symbols(
self._ctl, arguments=self._ctl_arguments_list
Expand Down Expand Up @@ -167,6 +171,6 @@ def _ds_mus(self):
cc = CoreComputer(self._ctl, self._assumption_list)
cc.shrink()
mus_core = cc.minimal
for s, v in mus_core:
for s, _ in mus_core:
prg = prg + f"_clinguin_mus({str(s)}).\n"
return prg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Clingo logger.
TODO
"""

from clingo import MessageCode


Expand Down
1 change: 1 addition & 0 deletions clinguin/server/application/element.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module that contains the ElementDto class.
"""

import json


Expand Down
2 changes: 2 additions & 0 deletions clinguin/server/data/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class AttributeDao(Predicate):
- value: The value of the attribute.
"""

# pylint: disable=abstract-method

id = RawField
key = RawField
value = RawField
Expand Down
Loading

0 comments on commit 49ea9cf

Please sign in to comment.