Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #47, updated some configs and types from typeshed #173

Merged
merged 6 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ reportMissingSuperCall="none" # False positives on base classes
reportPropertyTypeMismatch="error"
reportUninitializedInstanceVariable="error"
reportUnnecessaryTypeIgnoreComment="error"
reportUnusedCallResult="none"
# Exclude from scanning when running pyright
exclude = [
# Auto generated, produces unecessary `# type: ignore`
Expand All @@ -32,6 +31,7 @@ ignore = [
# We expect stub files to be incomplete or contain useless statements
"**/*.pyi",
]
reportUnusedCallResult="none"
# Type stubs may not be completable
reportMissingTypeStubs = "warning"
# False positives with TYPE_CHECKING
Expand Down
1 change: 0 additions & 1 deletion scripts/build.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
& "$PSScriptRoot/compile_resources.ps1"
pyinstaller `
--onefile `
--windowed `
--additional-hooks-dir=Pyinstaller/hooks `
--icon=res/icon.ico `
--splash=res/splash.png `
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $exitCodes = 0

Write-Host "`nRunning autofixes..."
isort src/ typings/
autopep8 src/ typings/ --in-place
autopep8 $(git ls-files '**.py*') --in-place

Write-Host "`nRunning Pyright..."
$Env:PYRIGHT_PYTHON_FORCE_VERSION = 'latest'
Expand Down
2 changes: 2 additions & 0 deletions scripts/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ pyright
qt6-applications
# Types
pywin32-stubs>=1.0.7 # Added error types
types-keyboard
types-pyautogui
typing-extensions
2 changes: 1 addition & 1 deletion src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(self, parent: QWidget | None = None): # pylint: disable=too-many-s
self.show()

try:
import pyi_splash # type: ignore # pylint: disable=import-outside-toplevel
import pyi_splash # pyright: ignore[reportMissingModuleSource] # pylint: disable=import-outside-toplevel
pyi_splash.close()
except ModuleNotFoundError:
pass
Expand Down
1 change: 1 addition & 0 deletions src/region_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __get_window_from_point(x: int, y: int):
# Want to pull the parent window from the window handle
# By using GetAncestor we are able to get the parent window instead
# of the owner window.
# TODO: Fix stubs, IsChild should return a boolean
while win32gui.IsChild(win32gui.GetParent(hwnd), hwnd):
hwnd = cast(int, user32.GetAncestor(hwnd, GA_ROOT))

Expand Down
3 changes: 2 additions & 1 deletion src/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def __load_settings_from_file(autosplit: AutoSplit, load_settings_file_path: str
set_hotkey(autosplit, hotkey, cast(str, autosplit.settings_dict[hotkey_name]))

change_capture_method(cast(CaptureMethodEnum, autosplit.settings_dict["capture_method"]), autosplit)
autosplit.capture_method.recover_window(autosplit.settings_dict["captured_window_title"], autosplit)
if autosplit.settings_dict["capture_method"] != CaptureMethodEnum.VIDEO_CAPTURE_DEVICE:
autosplit.capture_method.recover_window(autosplit.settings_dict["captured_window_title"], autosplit)
if not autosplit.capture_method.check_selected_region_exists(autosplit):
autosplit.live_image.setText("Reload settings after opening"
+ f'\n"{autosplit.settings_dict["captured_window_title"]}"'
Expand Down
3 changes: 2 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def is_valid_hwnd(hwnd: int):
if not hwnd:
return False
if sys.platform == "win32":
# TODO: Fix stubs, IsWindow should return a boolean
return bool(win32gui.IsWindow(hwnd) and win32gui.GetWindowText(hwnd))
return True

Expand Down Expand Up @@ -104,6 +105,6 @@ def wrapped(*args: Any, **kwargs: Any):
# Shared strings
# Set AUTOSPLIT_BUILD_NUMBER to an empty string to generate a clean version number
# AUTOSPLIT_BUILD_NUMBER = "" # pyright: ignore[reportConstantRedefinition] # noqa: F811
AUTOSPLIT_VERSION = "2.0.0-alpha.5" + (f"-{AUTOSPLIT_BUILD_NUMBER}" if AUTOSPLIT_BUILD_NUMBER else "")
AUTOSPLIT_VERSION = "2.0.0-alpha.6" + (f"-{AUTOSPLIT_BUILD_NUMBER}" if AUTOSPLIT_BUILD_NUMBER else "")
START_AUTO_SPLITTER_TEXT = "Start Auto Splitter"
GITHUB_REPOSITORY = AUTOSPLIT_GITHUB_REPOSITORY
11 changes: 11 additions & 0 deletions typings/PyInstaller/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing_extensions import LiteralString

from PyInstaller import compat as compat

__all__ = ("HOMEPATH", "PLATFORM", "__version__", "DEFAULT_DISTPATH", "DEFAULT_SPECPATH", "DEFAULT_WORKPATH")
__version__: str = ...
HOMEPATH: str = ...
DEFAULT_SPECPATH: str = ...
DEFAULT_DISTPATH: str = ...
DEFAULT_WORKPATH: str = ...
PLATFORM: LiteralString = ...
13 changes: 13 additions & 0 deletions typings/PyInstaller/__main__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://pyinstaller.org/en/stable/usage.html#running-pyinstaller-from-python-code
from collections.abc import Iterable

from _typeshed import SupportsKeysAndGetItem
from typing_extensions import TypeAlias

# Used to update PyInstaller.config.CONF
_PyIConfig: TypeAlias = (
SupportsKeysAndGetItem[str, bool | str | list[str] | None] | Iterable[tuple[str, bool | str | list[str] | None]]
)


def run(pyi_args: Iterable[str] | None = ..., pyi_config: _PyIConfig | None = ...) -> None: ...
32 changes: 32 additions & 0 deletions typings/PyInstaller/building/build_main.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Referenced in: https://pyinstaller.org/en/stable/hooks.html?highlight=get_hook_config#PyInstaller.utils.hooks.get_hook_config
# Not to be imported during runtime, but is the type reference for hooks and analysis configuration

from collections.abc import Iterable

from _typeshed import StrOrBytesPath
from PyInstaller.building.datastruct import Target # type: ignore[import]

#


class Analysis(Target):
# https://pyinstaller.org/en/stable/hooks-config.html#hook-configuration-options
hooksconfig: dict[str, dict[str, object]]

def __init__(
self,
scripts: Iterable[StrOrBytesPath],
pathex=...,
binaries=...,
datas=...,
hiddenimports=...,
hookspath=...,
hooksconfig: dict[str, dict[str, object]] | None = ...,
excludes=...,
runtime_hooks=...,
cipher=...,
win_no_prefer_redirects: bool = ...,
win_private_assemblies: bool = ...,
noarchive: bool = ...,
module_collection_mode=...,
) -> None: ...
36 changes: 36 additions & 0 deletions typings/PyInstaller/building/datastruct.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# https://pyinstaller.org/en/stable/advanced-topics.html#the-toc-and-tree-classes
from collections.abc import Iterable, Sequence
from typing import ClassVar

from typing_extensions import Literal, LiteralString, TypeAlias

_TypeCode: TypeAlias = Literal["DATA", "BINARY", "EXTENSION", "OPTION"]
_TOCTuple: TypeAlias = tuple[str, str | None, _TypeCode | None]


class TOC(list[_TOCTuple]):
filenames: set[str]
def __init__(self, initlist: Iterable[_TOCTuple] | None = ...) -> None: ...


class Target:
invcnum: ClassVar[int]
tocfilename: LiteralString
tocbasename: LiteralString
dependencies: TOC


class Tree(Target, TOC):
root: str | None
prefix: str | None
excludes: list[str] | None
typecode: _TypeCode

def __init__(
self,
root: str | None = ...,
prefix: str | None = ...,
excludes: Sequence[str] | None = ...,
typecode: _TypeCode = ...) -> None: ...

def assemble(self) -> None: ...
91 changes: 91 additions & 0 deletions typings/PyInstaller/compat.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from collections.abc import Iterable
from importlib.abc import _Path
from types import ModuleType
from typing import AnyStr, overload

from _typeshed import GenericPath, StrOrBytesPath
from typing_extensions import Literal, TypeAlias

_OpenFile: TypeAlias = StrOrBytesPath | int

is_64bits: bool
is_py35: bool
is_py36: bool
is_py37: bool
is_py38: bool
is_py39: bool
is_py310: bool
is_win: bool
is_win_10: bool
is_win_wine: bool
is_cygwin: bool
is_darwin: bool
is_linux: bool
is_solar: bool
is_aix: bool
is_freebsd: bool
is_openbsd: bool
is_hpux: bool
is_unix: bool
is_musl: bool
is_macos_11_compat: tuple[int, ...] | bool | None
is_macos_11_native: tuple[int, ...] | bool | None
is_macos_11: tuple[int, ...] | bool | None
PYDYLIB_NAMES: set[str]
base_prefix: str
is_venv: bool
is_conda: bool
is_pure_conda: bool
python_executable: str
is_ms_app_store: bool
BYTECODE_MAGIC: bytes
EXTENSION_SUFFIXES: list[str]
ALL_SUFFIXES: list[str]

architecture: Literal["64bit", "n32bit", "32bit"]
system: Literal["Cygwin", "Linux", "Darwin", "Java", "Windows"]
machine: Literal["sw_64", "loongarch64", "arm", "intel", "ppc", "mips", "riscv", "s390x", "unknown"] | None


def is_wine_dll(filename: _OpenFile) -> bool: ...
@overload
def getenv(name: str, default: str = ...) -> str: ...
@overload
def getenv(name: str, default: None = ...) -> str | None: ...
def setenv(name: str, value: str) -> None: ...
def unsetenv(name: str) -> None: ...


def exec_command(*cmdargs: str, encoding: str | None = ..., raise_enoent: bool
| None = ..., **kwargs: int | bool | Iterable[int] | None) -> str: ...


def exec_command_rc(*cmdargs: str, **kwargs: float | bool | Iterable[int] | None) -> int: ...


def exec_command_stdout(
*command_args: str, encoding: str | None = ..., **kwargs: float | str | bytes | bool | Iterable[int] | None
) -> str: ...


def exec_command_all(
*cmdargs: str, encoding: str | None = ..., **kwargs: int | bool | Iterable[int] | None
) -> tuple[int, str, str]: ...
def exec_python(*args: str, **kwargs: str | None) -> str: ...
def exec_python_rc(*args: str, **kwargs: str | None) -> int: ...
def expand_path(path: GenericPath[AnyStr]) -> AnyStr: ...
def getsitepackages(prefixes: Iterable[str] | None = ...) -> list[str]: ...
def importlib_load_source(name: str, pathname: _Path) -> ModuleType: ...


PY3_BASE_MODULES: set[str]
PURE_PYTHON_MODULE_TYPES: set[str]
SPECIAL_MODULE_TYPES: set[str]
BINARY_MODULE_TYPES: set[str]
VALID_MODULE_TYPES: set[str]
BAD_MODULE_TYPES: set[str]
ALL_MODULE_TYPES: set[str]
MODULE_TYPES_TO_TOC_DICT: dict[str, str]


def check_requirements() -> None: ...
16 changes: 16 additions & 0 deletions typings/PyInstaller/depend/imphookapi.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# https://pyinstaller.org/en/stable/hooks-config.html `hook_api` is a PostGraphAPI

from collections.abc import Iterable

from _typeshed import StrOrBytesPath
from PyInstaller.building.build_main import Analysis # type: ignore[import]

#


class PostGraphAPI:
@property
def __path__(self) -> tuple[str, ...] | None: ...
@property
def analysis(self) -> Analysis: ...
def add_datas(self, list_of_tuples: Iterable[tuple[StrOrBytesPath, StrOrBytesPath]]) -> None: ...
1 change: 1 addition & 0 deletions typings/PyInstaller/isolated/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from PyInstaller.isolated._parent import Python as Python, call as call, decorate as decorate
17 changes: 17 additions & 0 deletions typings/PyInstaller/isolated/_parent.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from collections.abc import Callable
from functools import _AnyCallable
from typing import TypeVar

from typing_extensions import ParamSpec

_AC = TypeVar("_AC", bound=_AnyCallable)
_R = TypeVar("_R")
_P = ParamSpec("_P")


class Python:
def call(self, function: Callable[_P, _R], *args: _P.args, **kwargs: _P.kwargs) -> _R: ...


def call(function: Callable[_P, _R], *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
def decorate(function: _AC) -> _AC: ...
Empty file.
Loading