Skip to content

Commit

Permalink
Remove dependency on requests (#267)
Browse files Browse the repository at this point in the history
- Remove dependency on `requests`, and its sub-dependencies `certifi`, `charset-normalizer`, `idna` and `urllib3`
- Remove co-dependnecy specifications `certifi` and `pyinstaller-hooks-contrib`
- Remove custom pyinstaller hook
- Improves build time with reduced hooks
- Improve uncached install time slightly due to less dependencies
- Reduce executable size by 0.58MB (139.045 --> 138.459)
  • Loading branch information
Avasam authored Dec 19, 2023
1 parent 84b8116 commit 726adc1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
4 changes: 0 additions & 4 deletions PyInstaller/hooks/hook-requests.py

This file was deleted.

1 change: 0 additions & 1 deletion scripts/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ types-psutil
types-PyAutoGUI
types-pyinstaller
types-pywin32>=306.0.0.8 ; sys_platform == 'win32'
types-requests
types-toml
3 changes: 0 additions & 3 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Read /docs/build%20instructions.md for more information on how to install, run and build the python code.
#
# Dependencies:
certifi
ImageHash>=4.3.1 ; python_version < '3.12' # Contains type information + setup as package not module # PyWavelets install broken on Python 3.12
git+https://github.com/boppreh/keyboard.git#egg=keyboard # Fix install on macos and linux-ci https://github.com/boppreh/keyboard/pull/568
numpy>=1.26 # Python 3.12 support
Expand All @@ -15,13 +14,11 @@ PyAutoGUI
PyWinCtl>=0.0.42 # py.typed
# When needed, dev builds can be found at https://download.qt.io/snapshots/ci/pyside/dev?C=M;O=D
PySide6-Essentials>=6.6.0 # Python 3.12 support
requests>=2.28.2 # charset_normalizer 3.x update
toml
typing-extensions>=4.4.0 # @override decorator support
#
# Build and compile resources
pyinstaller>=5.13 # Python 3.12 support
pyinstaller-hooks-contrib>=2022.15 # charset-normalizer fix https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/534
#
# https://peps.python.org/pep-0508/#environment-markers
#
Expand Down
3 changes: 0 additions & 3 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from types import FunctionType
from typing import NoReturn

import certifi
import cv2
from cv2.typing import MatLike
from psutil import process_iter
Expand Down Expand Up @@ -52,8 +51,6 @@

CHECK_FPS_ITERATIONS = 10

# Needed when compiled, along with the custom hook-requests PyInstaller hook
os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
myappid = f"Toufool.AutoSplit.v{AUTOSPLIT_VERSION}"
shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

Expand Down
12 changes: 7 additions & 5 deletions src/menu_bar.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import asyncio
import json
import webbrowser
from typing import TYPE_CHECKING, Any, cast
from urllib.error import URLError
from urllib.request import urlopen

import requests
from packaging.version import parse as version_parse
from PySide6 import QtCore, QtWidgets
from PySide6.QtCore import Qt
from PySide6.QtGui import QBrush, QPalette
from PySide6.QtWidgets import QFileDialog
from requests.exceptions import RequestException
from typing_extensions import override

import error_messages
Expand Down Expand Up @@ -97,10 +98,11 @@ def __init__(self, autosplit: "AutoSplit", check_on_open: bool):
@override
def run(self):
try:
response = requests.get(f"https://api.github.com/repos/{GITHUB_REPOSITORY}/releases/latest", timeout=30)
latest_version = str(response.json()["name"]).split("v")[1]
with urlopen(f"https://api.github.com/repos/{GITHUB_REPOSITORY}/releases/latest", timeout=30) as response: # noqa: S310
json_response: dict[str, str] = json.loads(response.read())
latest_version = json_response["name"].split("v")[1]
self._autosplit_ref.update_checker_widget_signal.emit(latest_version, self.check_on_open)
except (RequestException, KeyError):
except (URLError, KeyError):
if not self.check_on_open:
self._autosplit_ref.show_error_signal.emit(error_messages.check_for_updates)

Expand Down

0 comments on commit 726adc1

Please sign in to comment.