Skip to content

Commit

Permalink
style: reformat python code
Browse files Browse the repository at this point in the history
  • Loading branch information
d-biehl committed Jan 4, 2024
1 parent 77db502 commit e79804c
Show file tree
Hide file tree
Showing 136 changed files with 4,229 additions and 1,664 deletions.
2 changes: 1 addition & 1 deletion cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ commit_parsers = [
{ message = "^doc", group = "Documentation" },
{ message = "^perf", group = "Performance" },
{ message = "^refactor", group = "Refactor" },
{ message = "^style", group = "Styling" },
{ message = "^style", group = "Styling", skip = true },
{ message = "^test", group = "Testing" },
{ message = "^chore\\(release\\): prepare for", skip = true },
{ message = "^chore\\(deps\\)", skip = true },
Expand Down
1 change: 1 addition & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ matrix.rf.dependencies = [
]

[envs.lint]
python = "3.8"
#skip-install = true
#extra-dependencies = ["tomli>=2.0.0"]
extra-dependencies = [
Expand Down
7 changes: 6 additions & 1 deletion packages/analyze/src/robotcode/analyze/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@


class Analyzer:
def __init__(self, config: AnalyzerConfig, robot_config: RobotConfig, root_folder: Path):
def __init__(
self,
config: AnalyzerConfig,
robot_config: RobotConfig,
root_folder: Path,
):
self.config = config
self.robot_config = robot_config
self.root_folder = root_folder
Expand Down
20 changes: 10 additions & 10 deletions packages/analyze/src/robotcode/analyze/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import click
from robotcode.analyze.config import AnalyzerConfig
from robotcode.plugin import Application, pass_application
from robotcode.robot.config.loader import load_config_from_path, load_robot_config_from_path
from robotcode.robot.config.loader import (
load_config_from_path,
load_robot_config_from_path,
)
from robotcode.robot.config.utils import get_config_files

from .__version__ import __version__


@click.command(
context_settings={
"allow_extra_args": True,
"ignore_unknown_options": True,
},
context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
add_help_option=True,
)
@click.version_option(
Expand All @@ -23,17 +23,17 @@
)
@click.argument("paths", nargs=-1, type=click.Path(exists=True, dir_okay=True))
@pass_application
def analyze(
app: Application,
paths: Tuple[str],
) -> Union[str, int, None]:
def analyze(app: Application, paths: Tuple[str]) -> Union[str, int, None]:
"""TODO: Analyzes a Robot Framework project."""

config_files, root_folder, _ = get_config_files(paths, app.config.config_files, verbose_callback=app.verbose)

try:
analizer_config = load_config_from_path(
AnalyzerConfig, *config_files, tool_name="robotcode-analyze", robot_toml_tool_name="robotcode-analyze"
AnalyzerConfig,
*config_files,
tool_name="robotcode-analyze",
robot_toml_tool_name="robotcode-analyze",
).evaluated()

robot_config = (
Expand Down
49 changes: 39 additions & 10 deletions packages/core/src/robotcode/core/async_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ async def __aiter__(self) -> AsyncIterator[_TCallable]:
yield r

async def _notify(
self, *args: Any, callback_filter: Optional[Callable[[_TCallable], bool]] = None, **kwargs: Any
self,
*args: Any,
callback_filter: Optional[Callable[[_TCallable], bool]] = None,
**kwargs: Any,
) -> AsyncIterator[_TResult]:
for method in filter(
lambda x: callback_filter(x) if callback_filter is not None else True,
Expand Down Expand Up @@ -118,7 +121,11 @@ async def __call__(self, *args: Any, **kwargs: Any) -> List[_TResult]:

class AsyncEventDescriptorBase(Generic[_TCallable, _TResult, _TEvent]):
def __init__(
self, _func: _TCallable, factory: Callable[..., _TEvent], *factory_args: Any, **factory_kwargs: Any
self,
_func: _TCallable,
factory: Callable[..., _TEvent],
*factory_args: Any,
**factory_kwargs: Any,
) -> None:
self._func = _func
self.__factory = factory
Expand All @@ -137,7 +144,11 @@ def __get__(self, obj: Any, objtype: Type[Any]) -> _TEvent:

name = f"__async_event_{self._func.__name__}__"
if not hasattr(obj, name):
setattr(obj, name, self.__factory(*self.__factory_args, **self.__factory_kwargs))
setattr(
obj,
name,
self.__factory(*self.__factory_args, **self.__factory_kwargs),
)

return cast("_TEvent", getattr(obj, name))

Expand Down Expand Up @@ -210,7 +221,9 @@ def __call__(self, *args: Any, **kwargs: Any) -> AsyncIterator[Union[_TResult, B
return self._notify(*args, **kwargs)


def _get_name_prefix(descriptor: AsyncEventDescriptorBase[Any, Any, Any]) -> str:
def _get_name_prefix(
descriptor: AsyncEventDescriptorBase[Any, Any, Any],
) -> str:
if descriptor._owner is None:
return type(descriptor).__qualname__

Expand All @@ -227,13 +240,19 @@ class async_tasking_event_iterator( # noqa: N801
):
def __init__(self, _func: _TCallable) -> None:
super().__init__(
_func, AsyncTaskingEventIterator[_TCallable, Any], task_name_prefix=lambda: _get_name_prefix(self)
_func,
AsyncTaskingEventIterator[_TCallable, Any],
task_name_prefix=lambda: _get_name_prefix(self),
)


class async_tasking_event(AsyncEventDescriptorBase[_TCallable, Any, AsyncTaskingEvent[_TCallable, Any]]): # noqa: N801
def __init__(self, _func: _TCallable) -> None:
super().__init__(_func, AsyncTaskingEvent[_TCallable, Any], task_name_prefix=lambda: _get_name_prefix(self))
super().__init__(
_func,
AsyncTaskingEvent[_TCallable, Any],
task_name_prefix=lambda: _get_name_prefix(self),
)


async def check_canceled() -> bool:
Expand Down Expand Up @@ -418,7 +437,10 @@ async def __aenter__(self) -> None:
await self.acquire()

async def __aexit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> None:
self.release()

Expand Down Expand Up @@ -568,7 +590,10 @@ def get_current_future_info() -> Optional[FutureInfo]:


def create_sub_task(
coro: Coroutine[Any, Any, _T], *, name: Optional[str] = None, loop: Optional[asyncio.AbstractEventLoop] = None
coro: Coroutine[Any, Any, _T],
*,
name: Optional[str] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
) -> asyncio.Task[_T]:
ct = get_current_future_info()

Expand All @@ -578,7 +603,9 @@ def create_sub_task(
else:

async def create_task(
lo: asyncio.AbstractEventLoop, c: Coroutine[Any, Any, _T], n: Optional[str]
lo: asyncio.AbstractEventLoop,
c: Coroutine[Any, Any, _T],
n: Optional[str],
) -> asyncio.Task[_T]:
return create_sub_task(c, name=n, loop=lo)

Expand All @@ -593,7 +620,9 @@ async def create_task(
return result


def create_sub_future(loop: Optional[asyncio.AbstractEventLoop] = None) -> asyncio.Future[Any]:
def create_sub_future(
loop: Optional[asyncio.AbstractEventLoop] = None,
) -> asyncio.Future[Any]:
ct = get_current_future_info()

if loop is None:
Expand Down
24 changes: 20 additions & 4 deletions packages/core/src/robotcode/core/concurrent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import inspect
from concurrent.futures import CancelledError, Future
from threading import Event, RLock, Thread, current_thread, local
from typing import Any, Callable, Dict, Generic, List, Optional, Tuple, TypeVar, cast, overload
from typing import (
Any,
Callable,
Dict,
Generic,
List,
Optional,
Tuple,
TypeVar,
cast,
overload,
)

from typing_extensions import ParamSpec

Expand Down Expand Up @@ -70,7 +81,10 @@ def __init__(self) -> None:


def _run_callable_in_thread_handler(
future: FutureEx[_TResult], callable: Callable[..., _TResult], args: Tuple[Any, ...], kwargs: Dict[str, Any]
future: FutureEx[_TResult],
callable: Callable[..., _TResult],
args: Tuple[Any, ...],
kwargs: Dict[str, Any],
) -> None:
if not future.set_running_or_notify_cancel():
return
Expand Down Expand Up @@ -106,7 +120,7 @@ def check_current_thread_canceled(at_least_seconds: Optional[float] = None, rais

if raise_exception:
name = current_thread().name
raise CancelledError(f"Thread {name+' ' if name else ' '}cancelled")
raise CancelledError(f"Thread {name + ' ' if name else ' '}cancelled")

return True

Expand All @@ -127,7 +141,9 @@ def run_in_thread(callable: Callable[_P, _TResult], *args: _P.args, **kwargs: _P
future: FutureEx[_TResult] = FutureEx()
with _running_callables_lock:
thread = Thread(
target=_run_callable_in_thread_handler, args=(future, callable, args, kwargs), name=str(callable)
target=_run_callable_in_thread_handler,
args=(future, callable, args, kwargs),
name=str(callable),
)
_running_callables[future] = thread
future.add_done_callback(_remove_future_from_running_callables)
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/robotcode/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ def __get__(self, obj: Any, objtype: Type[Any]) -> _TEvent:

name = f"__event_{self._func.__name__}__"
if not hasattr(obj, name):
setattr(obj, name, self.__factory(*self.__factory_args, **self.__factory_kwargs))
setattr(
obj,
name,
self.__factory(*self.__factory_args, **self.__factory_kwargs),
)

return cast("_TEvent", getattr(obj, name))

Expand Down
37 changes: 17 additions & 20 deletions packages/core/src/robotcode/core/lsp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3453,7 +3453,8 @@ class CodeLens(CamelSnakeMixin):
source text, like the number of references, a way to run tests, etc.
A code lens is _unresolved_ when no command is associated to it. For performance
reasons the creation of a code lens and resolving should be done in two stages."""
reasons the creation of a code lens and resolving should be done in two stages.
"""

range: Range
"""The range in which this code lens is valid. Should only span a single line."""
Expand Down Expand Up @@ -3944,27 +3945,15 @@ def __iter__(self) -> Iterator[Position]:
@staticmethod
def zero() -> Range:
return Range(
start=Position(
line=0,
character=0,
),
end=Position(
line=0,
character=0,
),
start=Position(line=0, character=0),
end=Position(line=0, character=0),
)

@staticmethod
def invalid() -> Range:
return Range(
start=Position(
line=-1,
character=-1,
),
end=Position(
line=-1,
character=-1,
),
start=Position(line=-1, character=-1),
end=Position(line=-1, character=-1),
)

def extend(
Expand Down Expand Up @@ -4835,7 +4824,11 @@ class ServerCapabilities(CamelSnakeMixin):
# Since: 3.16.0

linked_editing_range_provider: Optional[
Union[bool, LinkedEditingRangeOptions, LinkedEditingRangeRegistrationOptions]
Union[
bool,
LinkedEditingRangeOptions,
LinkedEditingRangeRegistrationOptions,
]
] = None
"""The server provides linked editing range support.
Expand Down Expand Up @@ -7164,7 +7157,10 @@ class TextDocumentColorPresentationOptions(CamelSnakeMixin):
# Since: 3.17.0


DocumentDiagnosticReport = Union[RelatedFullDocumentDiagnosticReport, RelatedUnchangedDocumentDiagnosticReport]
DocumentDiagnosticReport = Union[
RelatedFullDocumentDiagnosticReport,
RelatedUnchangedDocumentDiagnosticReport,
]
"""The result of a document diagnostic pull request. A report can
either be a full report containing all diagnostics for the
requested document or an unchanged report indicating that nothing
Expand Down Expand Up @@ -7198,7 +7194,8 @@ class PrepareRenameResultType2(CamelSnakeMixin):


WorkspaceDocumentDiagnosticReport = Union[
WorkspaceFullDocumentDiagnosticReport, WorkspaceUnchangedDocumentDiagnosticReport
WorkspaceFullDocumentDiagnosticReport,
WorkspaceUnchangedDocumentDiagnosticReport,
]
"""A workspace diagnostic document report.
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/robotcode/core/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ def __iter__(self) -> Iterator[str]:
yield from astuple(self)

def __hash__(self) -> int:
return hash((self.scheme, self.netloc, self.path, self.params, self.query, self.fragment))
return hash(
(
self.scheme,
self.netloc,
self.path,
self.params,
self.query,
self.fragment,
)
)


class Uri(Mapping[str, str]):
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/robotcode/core/utils/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def get(self, func: Callable[..., _T], *args: Any, **kwargs: Any) -> _T:

@staticmethod
def _make_key(*args: Any, **kwargs: Any) -> Tuple[Any, ...]:
return (tuple(_freeze(v) for v in args), hash(frozenset({k: _freeze(v) for k, v in kwargs.items()})))
return (
tuple(_freeze(v) for v in args),
hash(frozenset({k: _freeze(v) for k, v in kwargs.items()})),
)

def clear(self) -> None:
with self._lock:
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/robotcode/core/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@


def show_hidden_arguments() -> bool:
return os.environ.get("ROBOTCODE_SHOW_HIDDEN_ARGS", "").lower() not in ["true", "1"]
return os.environ.get("ROBOTCODE_SHOW_HIDDEN_ARGS", "").lower() not in [
"true",
"1",
]
Loading

0 comments on commit e79804c

Please sign in to comment.