Skip to content

Commit

Permalink
add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
s.pirohov committed Jul 4, 2022
1 parent cc0ace3 commit eaf7888
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 57 deletions.
21 changes: 11 additions & 10 deletions webdriver_manager/chrome.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

from webdriver_manager.core.download_manager import DownloadManager
from webdriver_manager.core.manager import DriverManager
from webdriver_manager.core.utils import ChromeType
from webdriver_manager.drivers.chrome import ChromeDriver
Expand All @@ -8,15 +9,15 @@
class ChromeDriverManager(DriverManager):
def __init__(
self,
version="latest",
os_type=None,
path=None,
name="chromedriver",
url="https://chromedriver.storage.googleapis.com",
latest_release_url="https://chromedriver.storage.googleapis.com/LATEST_RELEASE",
chrome_type=ChromeType.GOOGLE,
cache_valid_range=1,
download_manager=None,
version: str = "latest",
os_type: str = None,
path: str = None,
name: str = "chromedriver",
url: str = "https://chromedriver.storage.googleapis.com",
latest_release_url: str = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE",
chrome_type: str = ChromeType.GOOGLE,
cache_valid_range: int = 1,
download_manager: DownloadManager = None,
):
super().__init__(
path,
Expand All @@ -33,7 +34,7 @@ def __init__(
http_client=self.http_client,
)

def install(self):
def install(self) -> str:
driver_path = self._get_driver_path(self.driver)
os.chmod(driver_path, 0o755)
return driver_path
2 changes: 1 addition & 1 deletion webdriver_manager/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(
def http_client(self):
return self._download_manager.http_client

def install(self):
def install(self) -> str:
raise NotImplementedError("Please Implement this method")

def _get_driver_path(self, driver):
Expand Down
23 changes: 12 additions & 11 deletions webdriver_manager/firefox.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import os

from webdriver_manager.core.download_manager import DownloadManager
from webdriver_manager.core.manager import DriverManager
from webdriver_manager.drivers.firefox import GeckoDriver


class GeckoDriverManager(DriverManager):
def __init__(
self,
version="latest",
os_type=None,
path=None,
name="geckodriver",
url="https://github.com/mozilla/geckodriver/releases/download",
latest_release_url="https://api.github.com/repos/mozilla/geckodriver/releases/latest",
mozila_release_tag="https://api.github.com/repos/mozilla/geckodriver/releases/tags/{0}",
cache_valid_range=1,
download_manager=None,
self,
version: str = "latest",
os_type: str = None,
path: str = None,
name: str = "geckodriver",
url: str = "https://github.com/mozilla/geckodriver/releases/download",
latest_release_url: str = "https://api.github.com/repos/mozilla/geckodriver/releases/latest",
mozila_release_tag: str = "https://api.github.com/repos/mozilla/geckodriver/releases/tags/{0}",
cache_valid_range: int = 1,
download_manager: DownloadManager = None,
):
super(GeckoDriverManager, self).__init__(
path, cache_valid_range, download_manager=download_manager
Expand All @@ -31,7 +32,7 @@ def __init__(
http_client=self.http_client,
)

def install(self):
def install(self) -> str:
driver_path = self._get_driver_path(self.driver)
os.chmod(driver_path, 0o755)
return driver_path
43 changes: 22 additions & 21 deletions webdriver_manager/microsoft.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import os

from webdriver_manager.core import utils
from webdriver_manager.core.download_manager import DownloadManager
from webdriver_manager.drivers.edge import EdgeChromiumDriver
from webdriver_manager.drivers.ie import IEDriver
from webdriver_manager.core.manager import DriverManager


class IEDriverManager(DriverManager):
def __init__(
self,
version="latest",
os_type=None,
path=None,
name="IEDriverServer",
url="https://github.com/seleniumhq/selenium/releases/download",
latest_release_url="https://api.github.com/repos/seleniumhq/selenium/releases",
ie_release_tag="https://api.github.com/repos/seleniumhq/selenium/releases/tags/selenium-{0}",
cache_valid_range=1,
download_manager=None,
self,
version: str = "latest",
os_type: str = None,
path: str = None,
name: str = "IEDriverServer",
url: str = "https://github.com/seleniumhq/selenium/releases/download",
latest_release_url: str = "https://api.github.com/repos/seleniumhq/selenium/releases",
ie_release_tag: str = "https://api.github.com/repos/seleniumhq/selenium/releases/tags/selenium-{0}",
cache_valid_range: int = 1,
download_manager: DownloadManager = None,
):
super().__init__(path, cache_valid_range, download_manager=download_manager)
self.driver = IEDriver(
Expand All @@ -30,21 +31,21 @@ def __init__(
http_client=self.http_client,
)

def install(self):
def install(self) -> str:
return self._get_driver_path(self.driver)


class EdgeChromiumDriverManager(DriverManager):
def __init__(
self,
version="latest",
os_type=utils.os_type(),
path=None,
name="edgedriver",
url="https://msedgedriver.azureedge.net",
latest_release_url="https://msedgedriver.azureedge.net/LATEST_RELEASE",
cache_valid_range=1,
download_manager=None,
self,
version: str = "latest",
os_type: str = utils.os_type(),
path: str = None,
name: str = "edgedriver",
url: str = "https://msedgedriver.azureedge.net",
latest_release_url: str = "https://msedgedriver.azureedge.net/LATEST_RELEASE",
cache_valid_range: int = 1,
download_manager: DownloadManager = None,
):
super().__init__(path, cache_valid_range, download_manager=download_manager)
self.driver = EdgeChromiumDriver(
Expand All @@ -56,7 +57,7 @@ def __init__(
http_client=self.http_client,
)

def install(self):
def install(self) -> str:
driver_path = self._get_driver_path(self.driver)
os.chmod(driver_path, 0o755)
return driver_path
29 changes: 15 additions & 14 deletions webdriver_manager/opera.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import os

from webdriver_manager.core.download_manager import DownloadManager
from webdriver_manager.core.manager import DriverManager
from webdriver_manager.drivers.opera import OperaDriver


class OperaDriverManager(DriverManager):
def __init__(
self,
version="latest",
os_type=None,
path=None,
name="operadriver",
url="https://github.com/operasoftware/operachromiumdriver/"
"releases/",
latest_release_url="https://api.github.com/repos/"
"operasoftware/operachromiumdriver/releases/latest",
opera_release_tag="https://api.github.com/repos/"
"operasoftware/operachromiumdriver/releases/tags/{0}",
cache_valid_range=1,
download_manager=None,
self,
version: str = "latest",
os_type: str = None,
path: str = None,
name: str = "operadriver",
url: str = "https://github.com/operasoftware/operachromiumdriver/"
"releases/",
latest_release_url: str = "https://api.github.com/repos/"
"operasoftware/operachromiumdriver/releases/latest",
opera_release_tag: str = "https://api.github.com/repos/"
"operasoftware/operachromiumdriver/releases/tags/{0}",
cache_valid_range: int = 1,
download_manager: DownloadManager = None,
):
super().__init__(path, cache_valid_range, download_manager=download_manager)

Expand All @@ -32,7 +33,7 @@ def __init__(
http_client=self.http_client,
)

def install(self):
def install(self) -> str:
driver_path = self._get_driver_path(self.driver)
if not os.path.isfile(driver_path):
for name in os.listdir(driver_path):
Expand Down

0 comments on commit eaf7888

Please sign in to comment.