Skip to content

Commit

Permalink
Hotfix #64 v0.9.0-beta.2
Browse files Browse the repository at this point in the history
- Remove event dependency as it is no longer required and causes errors on newer Python versions.
- Don't raise errors on some Python versions when Camoufox isn't installed
  • Loading branch information
daijro committed Nov 12, 2024
1 parent 1fb5bbe commit e10f30d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion hrequests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _detect_module() -> bool:
from .session import Session, TLSSession, chrome, firefox

# attempt to import headless browsing dependencies
BROWSER_SUPPORT = str(int(bool(find_spec('camoufox.__init__') or find_spec('patchright'))))
BROWSER_SUPPORT = str(int(bool(find_spec('camoufox') or find_spec('patchright'))))
if BROWSER_SUPPORT == '1':
from .browser import BrowserEngine, BrowserSession, render
else:
Expand Down
7 changes: 4 additions & 3 deletions hrequests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def install(self) -> None:

rprint(
f'[bright_green]:sparkles: Successfully installed hrequests-cgo v{ver}! :tada:[/]'
'\nSee the documentation to get started: https://daijro.gitbook.io/hrequests\n'
'\nSee the documentation to get started: https://daijro.gitbook.io/hrequests'
)

def update(self) -> None:
Expand Down Expand Up @@ -160,7 +160,7 @@ def uninstall(self) -> bool:


HAS_PATCHRIGHT = bool(find_spec('patchright'))
HAS_CAMOUFOX = bool(find_spec('camoufox.__init__'))
HAS_CAMOUFOX = bool(find_spec('camoufox'))


def panel_msg(text: str) -> None:
Expand Down Expand Up @@ -230,7 +230,6 @@ def uninstall(camoufox: bool, patchright: bool) -> None:
# remove old files
if not (path and os.path.exists(path)):
rprint('[bright_yellow]Library components not found.')
return
else:
try:
os.remove(path)
Expand Down Expand Up @@ -259,6 +258,8 @@ def uninstall(camoufox: bool, patchright: bool) -> None:
else:
rprint('[bright_yellow]Patchright is not installed.')

rprint('[bright_green]Complete! :tada:')


@cli.command(name='version')
def version() -> None:
Expand Down
2 changes: 1 addition & 1 deletion hrequests/browser/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def _start_context(self, **launch_args):
self.main_browser = browser

# Handle Patchright geolocation
if not self.proxy or not find_spec('camoufox.__init__'):
if not self.proxy or not find_spec('camoufox'):
# Do not use extra geolocation if Camoufox is not installed
return await browser.new_context(ignore_https_errors=not self.verify, proxy=self.proxy)

Expand Down
4 changes: 2 additions & 2 deletions hrequests/browser/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

# Get the error message for each
if BROWSER_SUPPORT:
if find_spec('camoufox.__init__') and find_spec('patchright'):
if find_spec('camoufox') and find_spec('patchright'):
ERROR = (PlaywrightError, PatchrightError)
elif find_spec('camoufox.__init__'):
elif find_spec('camoufox'):
ERROR = (PlaywrightError,)
elif find_spec('patchright'):
ERROR = (PatchrightError,)
Expand Down
2 changes: 1 addition & 1 deletion hrequests/browser/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def assert_browser(browser: Literal['firefox', 'chrome']) -> None:
raise MissingLibraryException(
'Browsing libraries are not installed. Please run `pip install hrequests[all]`'
)
if browser == 'firefox' and not find_spec('camoufox.__init__'):
if browser == 'firefox' and not find_spec('camoufox'):
raise MissingLibraryException(
'Camoufox is not installed. Please run `pip install hrequests[firefox]`'
)
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "hrequests"
version = "0.9.0-beta"
version = "0.9.0-beta.2"
description = "Hrequests (human requests) is a simple, configurable, feature-rich, replacement for the Python requests library."
authors = ["daijro <daijro.dev@gmail.com>"]
license = "Apache-2.0"
Expand Down Expand Up @@ -42,7 +42,6 @@ aioprocessing = "*"
numpy = "*"
parse = "*"
selectolax = "*"
event = "*"
faust-cchardet = "*"
camoufox = { version = "^0.3.8", optional = true, extras = ["geoip"] }
patchright = { version = "*", optional = true }
Expand Down

0 comments on commit e10f30d

Please sign in to comment.