Skip to content

Commit 11f5da0

Browse files
authored
ruffs Dxxx checks (#62)
Added checks: - D101 _Missing docstring in public class_ - D209 _Multi-line docstring closing quotes should be on a separate line_ - D210 _No whitespaces allowed surrounding docstring text_ - D404 _First word of the docstring should not be "This"_ --------- Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent 9862eb0 commit 11f5da0

24 files changed

+144
-99
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ All notable changes to this project will be documented in this file.
1212

1313
- Switched to `hatching` as a build system, now correct install optional dependencies.
1414
- Renamed methods, attributes that was `shadowing a Python builtins`. Enabled additional `Ruff` linters checks.
15-
- Regroup APIs, now Users related stuff starts with `user`, file related stuff with `file`.
15+
- Regroup APIs, now Users related stuff starts with `user`, file related stuff with `file`, UI stuff with `gui`.
1616

1717
## [0.0.26 - 2023-07-29]
1818

nc_py_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
ShareStatus,
1212
ShareType,
1313
)
14+
from .gui_defs import GuiActionFileInfo, GuiFileActionHandlerInfo
1415
from .integration_fastapi import (
1516
enable_heartbeat,
1617
nc_app,
1718
set_enabled_handler,
1819
set_scopes,
1920
)
2021
from .nextcloud import Nextcloud, NextcloudApp
21-
from .ui_files_actions_menu import UiActionFileInfo, UiFileActionHandlerInfo

nc_py_api/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
""" Version of nc_py_api."""
1+
"""Version of nc_py_api."""
22

33
__version__ = "0.0.27.dev2"

nc_py_api/appconfig_preferences_ex.py renamed to nc_py_api/appcfg_prefs_ex.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
@dataclass
1212
class CfgRecord:
13+
"""A representation of a single key-value pair returned from the `get_values` method."""
14+
1315
key: str
1416
value: str
1517

@@ -18,8 +20,8 @@ def __init__(self, raw_data: dict):
1820
self.value = raw_data["configvalue"]
1921

2022

21-
class BasicAppCfgPref:
22-
url_suffix: str
23+
class _BasicAppCfgPref:
24+
_url_suffix: str
2325

2426
def __init__(self, session: NcSessionBasic):
2527
self._session = session
@@ -40,7 +42,7 @@ def get_values(self, keys: list[str]) -> list[CfgRecord]:
4042
raise ValueError("`key` parameter can not be empty")
4143
require_capabilities("app_ecosystem_v2", self._session.capabilities)
4244
data = {"configKeys": keys}
43-
results = self._session.ocs(method="POST", path=f"{APP_V2_BASIC_URL}/{self.url_suffix}/get-values", json=data)
45+
results = self._session.ocs(method="POST", path=f"{APP_V2_BASIC_URL}/{self._url_suffix}/get-values", json=data)
4446
return [CfgRecord(i) for i in results]
4547

4648
def delete(self, keys: Union[str, list[str]], not_fail=True) -> None:
@@ -52,25 +54,29 @@ def delete(self, keys: Union[str, list[str]], not_fail=True) -> None:
5254
raise ValueError("`key` parameter can not be empty")
5355
require_capabilities("app_ecosystem_v2", self._session.capabilities)
5456
try:
55-
self._session.ocs(method="DELETE", path=f"{APP_V2_BASIC_URL}/{self.url_suffix}", json={"configKeys": keys})
57+
self._session.ocs(method="DELETE", path=f"{APP_V2_BASIC_URL}/{self._url_suffix}", json={"configKeys": keys})
5658
except NextcloudExceptionNotFound as e:
5759
if not not_fail:
5860
raise e from None
5961

6062

61-
class PreferencesExAPI(BasicAppCfgPref):
62-
url_suffix = "ex-app/preference"
63+
class PreferencesExAPI(_BasicAppCfgPref):
64+
"""User specific preferences API."""
65+
66+
_url_suffix = "ex-app/preference"
6367

6468
def set_value(self, key: str, value: str) -> None:
6569
if not key:
6670
raise ValueError("`key` parameter can not be empty")
6771
require_capabilities("app_ecosystem_v2", self._session.capabilities)
6872
params = {"configKey": key, "configValue": value}
69-
self._session.ocs(method="POST", path=f"{APP_V2_BASIC_URL}/{self.url_suffix}", json=params)
73+
self._session.ocs(method="POST", path=f"{APP_V2_BASIC_URL}/{self._url_suffix}", json=params)
74+
7075

76+
class AppConfigExAPI(_BasicAppCfgPref):
77+
"""Non-user(App) specific preferences API."""
7178

72-
class AppConfigExAPI(BasicAppCfgPref):
73-
url_suffix = "ex-app/config"
79+
_url_suffix = "ex-app/config"
7480

7581
def set_value(self, key: str, value: str, sensitive: bool = False) -> None:
7682
if not key:
@@ -79,4 +85,4 @@ def set_value(self, key: str, value: str, sensitive: bool = False) -> None:
7985
params: dict = {"configKey": key, "configValue": value}
8086
if sensitive:
8187
params["sensitive"] = True
82-
self._session.ocs(method="POST", path=f"{APP_V2_BASIC_URL}/{self.url_suffix}", json=params)
88+
self._session.ocs(method="POST", path=f"{APP_V2_BASIC_URL}/{self._url_suffix}", json=params)

nc_py_api/apps.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def disable(self, app_name: str) -> None:
3737
3838
:param app_name: id of the application.
3939
40-
.. note:: Does not work in NextcloudApp mode, only for Nextcloud client mode."""
40+
.. note:: Does not work in NextcloudApp mode, only for Nextcloud client mode.
41+
"""
4142
if not app_name:
4243
raise ValueError("`app_name` parameter can not be empty")
4344
self._session.ocs(method="DELETE", path=f"{ENDPOINT}/{app_name}")
@@ -47,7 +48,8 @@ def enable(self, app_name: str) -> None:
4748
4849
:param app_name: id of the application.
4950
50-
.. note:: Does not work in NextcloudApp mode, only for Nextcloud client mode."""
51+
.. note:: Does not work in NextcloudApp mode, only for Nextcloud client mode.
52+
"""
5153
if not app_name:
5254
raise ValueError("`app_name` parameter can not be empty")
5355
self._session.ocs(method="POST", path=f"{ENDPOINT}/{app_name}")

nc_py_api/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ class ApiScope(IntEnum):
4242

4343

4444
class ApiScopesStruct(TypedDict):
45+
"""Reply of the Nextcloud App with the desired scopes."""
46+
4547
required: list[int]
4648
optional: list[int]
4749

4850

4951
class OCSRespond(IntEnum):
52+
"""Special Nextcloud respond statuses for OCS calls."""
53+
5054
RESPOND_SERVER_ERROR = 996
5155
RESPOND_UNAUTHORISED = 997
5256
RESPOND_NOT_FOUND = 998

nc_py_api/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555

5656
class FilesAPI:
57-
"""This class provides all File System functionality and File Sharing abilities."""
57+
"""Class that encapsulates the file system and file sharing functionality."""
5858

5959
sharing: FilesSharingAPI
6060
"""API for managing Files Shares"""

nc_py_api/files_defs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def __init__(self, **kwargs):
3838
def last_modified(self) -> datetime:
3939
"""Time when the object was last modified.
4040
41-
.. note:: ETag if more preferable way to check if the object was changed."""
41+
.. note:: ETag if more preferable way to check if the object was changed.
42+
"""
4243
return self._last_modified
4344

4445
@last_modified.setter
@@ -53,7 +54,8 @@ def last_modified(self, value: Union[str, datetime]):
5354
class FsNode:
5455
"""A class that represents a Nextcloud file object.
5556
56-
Acceptable itself as a ``path`` parameter for the most file APIs."""
57+
Acceptable itself as a ``path`` parameter for the most file APIs.
58+
"""
5759

5860
full_path: str
5961
"""Path to the object, including the username. Does not include `dav` prefix"""
@@ -92,7 +94,8 @@ def __eq__(self, other):
9294
@property
9395
def has_extra(self) -> bool:
9496
"""Flag indicating whether this ``FsNode`` was obtained by the `mkdir` or `upload`
95-
methods and does not contain extended information."""
97+
methods and does not contain extended information.
98+
"""
9699
return bool(self.info.permissions)
97100

98101
@property

nc_py_api/files_sharing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class FilesSharingAPI:
13-
"""This class provides all File Sharing functionality."""
13+
"""Class provides all File Sharing functionality."""
1414

1515
def __init__(self, session: NcSessionBasic):
1616
self._session = session

nc_py_api/gui.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Nextcloud API for User Interface."""
2+
3+
from dataclasses import dataclass
4+
5+
from ._session import NcSessionApp
6+
from .gui_files import GuiFilesActionsAPI
7+
8+
9+
@dataclass
10+
class GuiApi:
11+
"""Class that encapsulates all UI functionality."""
12+
13+
files_dropdown_menu: GuiFilesActionsAPI
14+
15+
def __init__(self, session: NcSessionApp):
16+
self.files_dropdown_menu = GuiFilesActionsAPI(session)

0 commit comments

Comments
 (0)