mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-16 20:27:05 +03:00
Improve type definitions and styles (#869)
- exclude .reviewdog.yml from source distribution - Add more type hints - protective check for self.config in SettingsClass Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
@@ -19,4 +19,5 @@ recursive-include tools *.py
|
||||
prune .github
|
||||
exclude .gitignore
|
||||
exclude .readthedocs.yml
|
||||
exclude .reviewdog.yml
|
||||
exclude azure-pipelines.yml
|
||||
|
||||
@@ -23,7 +23,7 @@ import posixpath
|
||||
from dataclasses import dataclass, field
|
||||
from itertools import islice, zip_longest
|
||||
from logging import getLogger
|
||||
from typing import Dict, Iterable, List, Optional, Set, Tuple
|
||||
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
|
||||
from xml.etree.ElementTree import Element # noqa
|
||||
|
||||
from defusedxml import ElementTree
|
||||
@@ -450,11 +450,11 @@ class QtArchives:
|
||||
|
||||
self._parse_update_xmls(update_xmls, target_packages)
|
||||
|
||||
def _download_update_xml(self, update_xml_path, silent=False):
|
||||
def _download_update_xml(self, update_xml_path: str, silent: bool = False) -> Optional[str]:
|
||||
"""Hook for unit test."""
|
||||
if not Settings.ignore_hash:
|
||||
try:
|
||||
xml_hash = get_hash(update_xml_path, Settings.hash_algorithm, self.timeout)
|
||||
xml_hash: Optional[bytes] = get_hash(update_xml_path, Settings.hash_algorithm, self.timeout)
|
||||
except ChecksumDownloadFailure:
|
||||
if silent:
|
||||
return None
|
||||
@@ -469,7 +469,9 @@ class QtArchives:
|
||||
xml_hash = None
|
||||
return getUrl(posixpath.join(self.base, update_xml_path), self.timeout, xml_hash)
|
||||
|
||||
def _parse_update_xml(self, os_target_folder, update_xml_text, target_packages: Optional[ModuleToPackage]):
|
||||
def _parse_update_xml(
|
||||
self, os_target_folder: str, update_xml_text: str, target_packages: Optional[ModuleToPackage]
|
||||
) -> None:
|
||||
if not target_packages:
|
||||
target_packages = ModuleToPackage({})
|
||||
update_xml = Updates.fromstring(self.base, update_xml_text)
|
||||
@@ -509,7 +511,7 @@ class QtArchives:
|
||||
)
|
||||
)
|
||||
|
||||
def _parse_update_xmls(self, update_xmls, target_packages: Optional[ModuleToPackage]):
|
||||
def _parse_update_xmls(self, update_xmls: list[UpdateXmls], target_packages: Optional[ModuleToPackage]) -> None:
|
||||
if not target_packages:
|
||||
target_packages = ModuleToPackage({})
|
||||
for update_xml in update_xmls:
|
||||
@@ -700,7 +702,7 @@ class ToolArchives(QtArchives):
|
||||
def _get_archives(self):
|
||||
self._get_archives_base(self.tool_name, None)
|
||||
|
||||
def _parse_update_xml(self, os_target_folder, update_xml_text, *ignored):
|
||||
def _parse_update_xml(self, os_target_folder: str, update_xml_text: str, *ignored: Any) -> None:
|
||||
update_xml = Updates.fromstring(self.base, update_xml_text)
|
||||
self._append_tool_update(os_target_folder, update_xml, self.arch, self.tool_version_str)
|
||||
|
||||
|
||||
@@ -18,13 +18,15 @@
|
||||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Any
|
||||
|
||||
DOCS_CONFIG = "https://aqtinstall.readthedocs.io/en/stable/configuration.html#configuration"
|
||||
|
||||
|
||||
class AqtException(Exception):
|
||||
def __init__(self, *args, suggested_action: Optional[List[str]] = None, should_show_help: bool = False, **kwargs) -> None:
|
||||
def __init__(
|
||||
self, *args, suggested_action: Optional[List[str]] = None, should_show_help: bool = False, **kwargs: Any
|
||||
) -> None:
|
||||
self.suggested_action: List[str] = suggested_action or []
|
||||
self.should_show_help: bool = should_show_help or False
|
||||
super(AqtException, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
import binascii
|
||||
import configparser
|
||||
import hashlib
|
||||
import logging.config
|
||||
import os
|
||||
import posixpath
|
||||
import secrets
|
||||
import sys
|
||||
import threading
|
||||
from configparser import ConfigParser
|
||||
from logging import Handler, getLogger
|
||||
from logging.handlers import QueueListener
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
from typing import Any, Callable, Dict, Generator, List, Optional, TextIO, Tuple, Union
|
||||
from urllib.parse import urlparse
|
||||
from xml.etree.ElementTree import Element
|
||||
@@ -309,7 +309,7 @@ def xml_to_modules(
|
||||
return packages
|
||||
|
||||
|
||||
class MyConfigParser(configparser.ConfigParser):
|
||||
class MyConfigParser(ConfigParser):
|
||||
def getlist(self, section: str, option: str, fallback: List[str] = []) -> List[str]:
|
||||
value = self.get(section, option, fallback=None)
|
||||
if value is None:
|
||||
@@ -339,7 +339,7 @@ class SettingsClass:
|
||||
"config": None,
|
||||
"configfile": None,
|
||||
"loggingconf": None,
|
||||
"_lock": threading.Lock(),
|
||||
"_lock": Lock(),
|
||||
}
|
||||
|
||||
def __new__(cls, *p, **k):
|
||||
@@ -348,6 +348,8 @@ class SettingsClass:
|
||||
return self
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.config: Optional[ConfigParser]
|
||||
self._lock: Lock
|
||||
if self.config is None:
|
||||
with self._lock:
|
||||
if self.config is None:
|
||||
@@ -356,6 +358,8 @@ class SettingsClass:
|
||||
self.loggingconf = os.path.join(os.path.dirname(__file__), "logging.ini")
|
||||
|
||||
def load_settings(self, file: Optional[Union[str, TextIO]] = None) -> None:
|
||||
if self.config is None:
|
||||
return
|
||||
if file is not None:
|
||||
if isinstance(file, str):
|
||||
result = self.config.read(file)
|
||||
|
||||
Reference in New Issue
Block a user