From 102db093597234197c8ca6006ecb8d4c145a1171 Mon Sep 17 00:00:00 2001 From: wim glenn Date: Sun, 3 Dec 2023 21:37:42 -0600 Subject: [PATCH] v1.20.4 CI (#132) * v1.20.4 * compat blake2b hash 2.x --- .github/workflows/ci.yml | 30 +++++++++++++++++------------- johnnydep/pipper.py | 19 ++++++++++++++----- setup.py | 1 + 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cff457..138a2be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,12 +4,12 @@ on: push: branches: ["main"] pull_request: - branches: ["main"] + branches: ["main", "1.x"] workflow_dispatch: jobs: tests: - name: "Python ${{ matrix.python-version }} on ${{ matrix.os }}" + name: Python ${{ matrix.python-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: @@ -25,36 +25,40 @@ jobs: python-version: "3.7" steps: - - uses: "actions/checkout@v3" - - uses: "actions/setup-python@v4" + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: - python-version: "${{ matrix.python-version }}" - - name: "Install dependencies" + python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -VV python -m pip install -r requirements-dev.txt - - name: "Run tests for ${{ matrix.python-version }} on ${{ matrix.os }}" + - name: Run tests for ${{ matrix.python-version }} on ${{ matrix.os }} run: python -m pytest - name: Upload coverage to Codecov - uses: "codecov/codecov-action@v3" + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} tests-27: - name: "Python 2.7 on ubuntu-20.04" + name: Python 2.7 on ubuntu-20.04 runs-on: ubuntu-20.04 container: image: python:2.7-buster steps: - - uses: "actions/checkout@v3" - - name: "Install dependencies" + - uses: actions/checkout@v3 + - name: Install dependencies run: | python -VV python -m pip install -r requirements-dev.txt - - name: "Run tests for Python 2.7 on ubuntu-20.04" + - name: Run tests for Python 2.7 on ubuntu-20.04 run: python -m pytest - name: Upload coverage to Codecov - uses: "codecov/codecov-action@v3" + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/johnnydep/pipper.py b/johnnydep/pipper.py index 1b533bc..f678dcf 100755 --- a/johnnydep/pipper.py +++ b/johnnydep/pipper.py @@ -33,10 +33,7 @@ def compute_checksum(target, algorithm="sha256", blocksize=2 ** 13): hashtype = getattr(hashlib, algorithm) - if algorithm == "blake2b": - hash_ = hashtype(digest_size=32) - else: - hash_ = hashtype() + hash_ = hashtype() log.debug("computing checksum", target=target, algorithm=algorithm) with open(target, "rb") as f: for chunk in iter(lambda: f.read(blocksize), b""): @@ -46,6 +43,18 @@ def compute_checksum(target, algorithm="sha256", blocksize=2 ** 13): return result +def _warehouse_hash(target): + try: + blake2b = hashlib.blake2b + except AttributeError: + # Python < 3.6 + import pyblake2 + blake2b = pyblake2.blake2b + with open(target, "rb") as f: + b2b = blake2b(f.read(), digest_size=32) + return b2b.hexdigest() + + def _get_pip_version(): # try to get pip version without actually importing pip # setuptools gets upset if you import pip before importing setuptools.. @@ -213,7 +222,7 @@ def get(dist_name, index_url=None, env=None, extra_index_url=None, tmpdir=None, except ValueError: pass else: - b2b = compute_checksum(whl, "blake2b") + b2b = _warehouse_hash(whl) path = "/".join([b2b[:2], b2b[2:4], b2b[4:], os.path.basename(whl)]) urls = {x for x in out.split() if x.startswith("http") and x.endswith(path)} if len(urls) == 1: diff --git a/setup.py b/setup.py index 7ca4634..35fe91b 100644 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ "colorama ; python_version < '3.7' or platform_system == 'Windows'", # structlog "cachetools", "oyaml", + "pyblake2 ; python_version < '3.6'", "toml", "pip", "packaging >= 17, != 22",