shadowmoose / pyderman

Install Selenium-compatible Chrome/Firefox/Opera/PhantomJS/Edge webdrivers automatically.
MIT License
29 stars 11 forks source link

v2.0.2 Mistakenly thinks mac is m1 #12

Closed MarcelWilson closed 2 years ago

MarcelWilson commented 2 years ago

I have a macbook pro 2018 (intel) but pyderman 2.0.2 always attempts to download the m1 version of chromedriver.

Downloading from:  https://chromedriver.storage.googleapis.com/95.0.4638.54/chromedriver_mac64_m1.zip
To:  /Users/me/tests/lib/chromedriver_95.0.4638.54.zip

Digging into the code a little, I noticed this in __init__.py

if _current_os == 'mac' and int(platform.release().split('.')[0]) >= 20:
    _current_os = 'mac-sur'

platform.release() for my machine returns '21.1.0' don't know much about the platform versions, but I'm guessing this value needs to be adjusted.

Screen Shot 2021-11-02 at 5 56 24 PM
shadowmoose commented 2 years ago

Thanks for the report. I'd like to fix this, but I don't own a mac, so checking versions is difficult. I'm tagging this for anybody who is more familiar with the current state of the OS who wants to come along and assist, or at least offer me some guidance on versioning.

eggplants commented 2 years ago

py-cpuinfo is useful:

# In my MacBook Pro:
cpuinfo.get_cpu_info().get("brand_raw")
>>> 'Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz'

# In M1 MacBook:
cpuinfo.get_cpu_info().get("brand_raw")
>>> 'Apple M1 Pro'

It seems to execute sysctl machdep.cpu and extract machdep.cpu.brand_string row.

shadowmoose commented 2 years ago

Interesting, and good to know. I'm not sure that relying on the brand string is reliable enough, but it might be a better solution.

eggplants commented 2 years ago

With only built-in packages:

import platform, shutil, subprocess

def is_m1() -> bool:
    return (
        platform.system().lower() == "darwin" and
        shutil.which("sysctl") and
        subprocess.check_output(
            ["sysctl", "-n", "machdep.cpu.brand_string"]
        ).decode("utf-8").lower().startswith("apple m1")
    )

I'll make pr soon.