diff --git a/MANIFEST.in b/MANIFEST.in index b3c68460..3318a7e1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,6 @@ -include curl_cffi/_wrapper.* -include curl_cffi/ffi/* -include curl_cffi/include/curl/* +recursive-include tests/* + +include ffi/* +include include/curl/* +include scripts/build.py +include Makefile diff --git a/Makefile b/Makefile index ad8f4c58..1633082f 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,8 @@ curl-impersonate-$(VERSION)/chrome/patches: $(CURL_VERSION) for p in $=1.12.0", + "cffi>=1.12.0", "certifi", ] readme = "README.md" @@ -27,14 +27,12 @@ classifiers = [ [project.optional-dependencies] dev = [ "autoflake==1.4", - "black==22.8.0", "coverage==6.4.1", "cryptography==38.0.3", "flake8==6.0.0", "flake8-bugbear==22.7.1", "flake8-pie==0.15.0", "httpx==0.23.1", - "isort==5.10.1", "mypy==0.971", "types-certifi==2021.10.8.2", "pytest==7.1.2", @@ -49,7 +47,7 @@ dev = [ ] build = [ "cibuildwheel", - "wheel" + "wheel", ] test = [ "cryptography==38.0.3", @@ -68,20 +66,15 @@ test = [ "fastapi==0.100.0", ] -[tool.ruff.lint] -# Enable the isort rules. -extend-select = ["I"] + +[build-system] +requires = ["wheel", "setuptools", "cffi>=1.12.0"] +build-backend = "setuptools.build_meta" [tool.setuptools] packages = ["curl_cffi", "curl_cffi.requests"] package-data = { curl_cffi = ["libcurl.dll"] } -# include-package-data = true - - -[build-system] -requires = ["wheel", "setuptools", "cffi>=1.12.0"] -build-backend = "setuptools.build_meta" [tool.cibuildwheel] @@ -103,6 +96,7 @@ test-command = "python -bb -m pytest {project}/tests/unittest" test-extras = ["test"] test-skip = "pp*" + # configure cibuildwheel to build native archs ('auto'), and some emulated ones [tool.cibuildwheel.linux] archs = ["auto", "aarch64"] @@ -117,3 +111,8 @@ before-all = "gmake preprocess" [tool.pytest.ini_options] # pythonpath = [ "." ] asyncio_mode = "auto" + + +[tool.ruff.lint] +# Enable the isort rules. +extend-select = ["I"] diff --git a/setup.py b/setup.py index 5d693f32..8be7ae1e 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ import os +import sys import platform import shutil import struct @@ -23,33 +24,66 @@ def get_tag(self): return python, abi, plat -def download_so(): - uname = platform.uname() - machine = uname.machine +def abs_machine(): + machine = platform.machine() + + pointer_bits = struct.calcsize("P") * 8 + if pointer_bits not in (32, 64): + raise Exception("Unsupported pointer size") + + is_64 = pointer_bits == 64 + + # x86 based archs + if machine in ('AMD64', 'x86_64', 'i686'): + return "x86_64" if is_64 else "i686" + # arm based archs + elif machine in ('aarch64', 'arm64', 'armv6l', 'armv7l'): + return "aarch64" if is_64 else "arm" + else: + raise Exception("Unsupported processor") + - # do not download if target platfrom dll not found +def download_so(): + system = platform.system() + machine = abs_machine() - if uname.system == "Windows": + if system == "Windows": sysname = "win32" - if struct.calcsize("P") * 8 == 64: - machine = "x86_64" + so_name = "libcurl.dll" + + if machine == "x86_64": libdir = "./lib64" - else: - machine = "i686" + elif machine == "i686": libdir = "./lib32" - so_name = "libcurl.dll" - elif uname.system == "Darwin": + else: + so_name = "SKIP" + + elif system == "Darwin": sysname = "macos" - libdir = "/Users/runner/work/_temp/install/lib" so_name = "libcurl-impersonate-chrome.4.dylib" + + if machine in ("x86_64", "aarch64"): + libdir = "/Users/runner/work/_temp/install/lib" + else: + so_name = "SKIP" + else: sysname = "linux-gnu" - libdir = os.path.expanduser("~/.local/lib") so_name = "libcurl-impersonate-chrome.so" + if machine in ("x86_64", "arm", "aarch64"): + libdir = os.path.expanduser("~/.local/lib") + else: + so_name = "SKIP" + + if so_name == "SKIP": + print(f"libcurl for {sysname} platform is not available on github.") + return + if (Path(libdir) / so_name).exists(): print(".so files alreay downloaded.") return + file = "libcurl-impersonate.tar.gz" url = ( f"https://github.com/yifeikong/curl-impersonate/releases/download/" @@ -63,7 +97,8 @@ def download_so(): print("Unpacking downloaded files...") os.makedirs(libdir, exist_ok=True) shutil.unpack_archive(file, libdir) - if uname.system == "Windows": + + if system == "Windows": shutil.copy2(f"{libdir}/libcurl.dll", "curl_cffi") @@ -73,11 +108,15 @@ def run(self): super().run() +# this option is only valid in setup.py +kwargs = {"cffi_modules": ["curl_cffi/build.py:ffibuilder"]} +if len(sys.argv) > 1 and sys.argv[1] != 'bdist_wheel': + kwargs = {} + setup( - # this option is only valid in setup.py - cffi_modules=["curl_cffi/build.py:ffibuilder"], cmdclass={ "bdist_wheel": bdist_wheel_abi3, # type: ignore "build": my_build, # type: ignore }, + **kwargs, )