From 501c53d1f483a2a73e6bad781143bc0fc2c95bdb Mon Sep 17 00:00:00 2001 From: Two Dev Date: Wed, 11 Dec 2024 13:11:53 +0700 Subject: [PATCH] chore: CI --- .github/workflows/ci.yml | 8 ++++---- Makefile | 8 ++++++-- README.md | 4 ++-- requirements.txt | 2 +- tests/conftest.py | 6 ++++++ tls_requests/models/libraries.py | 21 +++++++++++++++------ tox.ini | 2 +- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b61e98..a1105a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,8 @@ jobs: build: runs-on: ubuntu-latest strategy: - max-parallel: 4 + fail-fast: false + max-parallel: 3 matrix: python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] steps: @@ -23,8 +24,7 @@ jobs: - name: Install Dependencies run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt + make init - name: Lint run: | @@ -32,7 +32,7 @@ jobs: - name: Tests run: | - python -m pytest tests + make pytest deploy: needs: build diff --git a/Makefile b/Makefile index 2a51954..4f71cbc 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ .PHONY: docs init: + python -m pip install --upgrade pip python -m pip install -r requirements-dev.txt test: @@ -14,6 +15,9 @@ lint: python -m isort tls_requests python -m flake8 tls_requests +pytest: + python -m pytest tests + coverage: python -m pytest --cov-config .coveragerc --verbose --cov-report term --cov-report xml --cov=tls_requests tests @@ -25,11 +29,11 @@ publish-test-pypi: python -m pip install 'twine>=6.0.1' python setup.py sdist bdist_wheel twine upload --repository testpypi dist/* - rm -rf build dist .egg *.egg-info + rm -rf build dist .egg wrapper_tls_requests.egg-info publish-pypi: python -m pip install -r requirements-dev.txt python -m pip install 'twine>=6.0.1' python setup.py sdist bdist_wheel twine upload dist/* - rm -rf build dist .egg *.egg-info + rm -rf build dist .egg wrapper_tls_requests.egg-info diff --git a/README.md b/README.md index c1e33d3..a24127f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# TLS REQUESTS -**A powerful and lightweight Python library for making secure and reliable HTTP/TLS Fingerprint requests.** +# TLS Requests +TLS Requests is a powerful Python library for secure HTTP requests, offering browser-like TLS fingerprinting, anti-bot bypassing, and high performance. * * * diff --git a/requirements.txt b/requirements.txt index 30babc9..7a91425 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Base chardet~=5.2.0 -requests>=2.28.0 +requests~=2.32.3 tqdm~=4.67.1 idna~=3.10 diff --git a/tests/conftest.py b/tests/conftest.py index 3d31eb2..95feb18 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1 +1,7 @@ +import tls_requests + pytest_plugins = ['pytest_httpserver', 'pytest_asyncio'] + + +def pytest_configure(config): + tls_requests.TLSLibrary.load() diff --git a/tls_requests/models/libraries.py b/tls_requests/models/libraries.py index e1fc044..0b74417 100644 --- a/tls_requests/models/libraries.py +++ b/tls_requests/models/libraries.py @@ -15,8 +15,13 @@ BIN_DIR = os.path.join(Path(__file__).resolve(strict=True).parent.parent / "bin") GITHUB_API_URL = "https://api.github.com/repos/bogdanfinn/tls-client/releases" +OS_PLATFORM = platform +OS_MACHINE = machine() +if OS_PLATFORM == "linux" and OS_MACHINE == "x86_64": + OS_MACHINE = "amd64" + PATTERN_RE = re.compile( - r"xgo[a-zA-Z0-9.-]+%s-%s\.(so|dll|dylib)" % (platform, machine()), re.I + r"[a-zA-Z0-9.-]+%s-%s\.(so|dll|dylib)" % (OS_PLATFORM, OS_MACHINE), re.I ) @@ -58,6 +63,7 @@ def from_kwargs(cls, **kwargs): class TLSLibrary: @classmethod def fetch_api(cls, version: str = None, retries: int = 3): + for _ in range(retries): try: response = requests.get(GITHUB_API_URL) @@ -70,14 +76,16 @@ def fetch_api(cls, version: str = None, retries: int = 3): asset for release in releases for asset in release.assets - if "xgo" in str(asset.browser_download_url) + if PATTERN_RE.search(asset.browser_download_url) ] if version is not None: for asset in assets: if str(version) == asset.name: - return [asset.browser_download_url] + yield asset.browser_download_url + + for asset in assets: + yield asset.browser_download_url - return [asset.browser_download_url for asset in assets] except Exception as e: print("Unable to fetch GitHub API: %s" % e) @@ -96,11 +104,12 @@ def find_all(cls) -> list[str]: @classmethod def download(cls, version: str = None) -> str: try: + print("System Info - Platform: %s, Machine: %s." % (OS_PLATFORM, OS_MACHINE)) download_url = None for download_url in cls.fetch_api(version): - if PATTERN_RE.search(download_url): - break + break + print("Library Download URL: %s" % download_url) if download_url: destination = os.path.join(BIN_DIR, download_url.split("/")[-1]) with requests.get(download_url, stream=True) as response: diff --git a/tox.ini b/tox.ini index 0ff11cc..0ea49bd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{39,310,311,312,313}-{default, use_chardet_on_py3} +envlist = py{39,310,311,312,313}-default [testenv] deps = -r requirements-dev.txt