diff --git a/.github/workflows/run-linter.yml b/.github/workflows/run-linter.yml new file mode 100644 index 00000000..1f06ddc0 --- /dev/null +++ b/.github/workflows/run-linter.yml @@ -0,0 +1,46 @@ +name: Run linter + +on: + pull_request: + +jobs: + linter: + name: Linter + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Setup python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + architecture: x64 + - name: Setup reviewdog + run: | + /usr/bin/sh utils/reviewdog_install.sh -b ./bin/ v0.20.3 + - name: Install dependencies + run: | + pip install -U pip tox wheel setuptools setuptools_scm[toml] + pip install .[check] + - name: run reviewdog + run: | + ./bin/reviewdog -runners=flake8,mypy,pylint -reporter=github-pr-check -conf=.reviewdog.yml + env: + REVIEWDOG_TOKEN: ${{ secrets.REVIEWDOG_TOKEN }} + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docs: + name: Document checks + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Setup python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + architecture: x64 + - name: Install dependencies + run: | + pip install -U pip tox wheel setuptools setuptools_scm[toml] + - name: docs build and link check + run: | + tox -e docs diff --git a/.github/workflows/run-tox-tests.yml b/.github/workflows/run-tox-tests.yml index e6621ca6..13fddd94 100644 --- a/.github/workflows/run-tox-tests.yml +++ b/.github/workflows/run-tox-tests.yml @@ -11,7 +11,6 @@ on: - synchronize - reopened - jobs: build: runs-on: ${{ matrix.os }} @@ -23,7 +22,7 @@ jobs: "3.10", "3.11", "3.12", - "3.13-dev", # Not yet released, so we need to use -dev to get the release candidate + "3.13", "pypy-3.9", ] include: @@ -101,7 +100,7 @@ jobs: PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} test_slow_tests: - name: Test slow test cases + name: Test slow cases runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore index f9d431ca..f06058c9 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ type_info.json coverage.xml py7zr/version.py prof +cmake-build-debug +bin/ diff --git a/.reviewdog.yml b/.reviewdog.yml new file mode 100644 index 00000000..ba545170 --- /dev/null +++ b/.reviewdog.yml @@ -0,0 +1,19 @@ +runner: + flake8: + name: flake8 + cmd: flake8 py7zr tests + format: flake8 + level: error + + mypy: + name: mypy + cmd: mypy --strict --show-column-numbers -p py7zr + errorformat: + - "%f:%l:%c: %m" + level: error + + pylint: + name: pylint + cmd: pylint **/*.py -j 0 + errorformat: + - "%f:%l:%c: %t%n: %m" \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index b728fa37..b603c8b3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -26,6 +26,7 @@ recursive-include docs *.pdf recursive-include docs *.svg recursive-include docs Makefile prune .github +exclude utils/reviewdog_install.sh exclude .gitignore exclude .readthedocs.yml exclude codecov.yml diff --git a/py7zr/py7zr.py b/py7zr/py7zr.py index 2f0a9c71..fc021ad9 100644 --- a/py7zr/py7zr.py +++ b/py7zr/py7zr.py @@ -74,7 +74,6 @@ FILE_ATTRIBUTE_UNIX_EXTENSION = 0x8000 FILE_ATTRIBUTE_WINDOWS_MASK = 0x07FFF - class ArchiveFile: """Represent each files metadata inside archive file. It holds file properties; filename, permissions, and type whether diff --git a/pyproject.toml b/pyproject.toml index 9be7fdac..45c18690 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,6 +87,7 @@ check = [ "readme-renderer", "twine", "black>=24.8.0", + "pylint", ] debug = [ "pytest", @@ -169,7 +170,7 @@ markers = [ legacy_tox_ini = """ [tox] isolated_build = True -envlist = mypy, check, pypy{39,310}, py{39,310,311,312,313}, py39d, docs, mprof +envlist = mypy, check, pypy{39,310}, py{39,310,311,312,313}, py39d, docs, mprof, distcheck [testenv] passenv = @@ -180,8 +181,6 @@ passenv = extras = test commands = python -m pytest -vv -depends = - pypy{39,310},py{39,310,311,312,313}: clean, check [testenv:py39] extras = test, test_compat @@ -213,12 +212,15 @@ deps = [testenv:check] extras = check -ignore_errors=true commands = + check-manifest {toxinidir} flake8 py7zr tests + +[testenv:distcheck] +extras = check +commands = python -m build --sdist twine check dist/* - check-manifest {toxinidir} [testenv:clean] deps = coverage[toml]>=5.2 @@ -240,7 +242,7 @@ commands = [gh-actions] python = - 3.9: py39, check, docs, mypy + 3.9: py39 3.10: py310 3.11: py311 3.12: py312 diff --git a/utils/reviewdog_install.sh b/utils/reviewdog_install.sh new file mode 100644 index 00000000..2316aacc --- /dev/null +++ b/utils/reviewdog_install.sh @@ -0,0 +1,394 @@ +#!/bin/sh +set -e +# Code generated by godownloader on 2020-01-10T16:57:26Z. DO NOT EDIT. +# + +usage() { + this=$1 + cat </dev/null +} +echoerr() { + echo "$@" 1>&2 +} +log_prefix() { + echo "$0" +} +_logp=6 +log_set_priority() { + _logp="$1" +} +log_priority() { + if test -z "$1"; then + echo "$_logp" + return + fi + [ "$1" -le "$_logp" ] +} +log_tag() { + case $1 in + 0) echo "emerg" ;; + 1) echo "alert" ;; + 2) echo "crit" ;; + 3) echo "err" ;; + 4) echo "warning" ;; + 5) echo "notice" ;; + 6) echo "info" ;; + 7) echo "debug" ;; + *) echo "$1" ;; + esac +} +log_debug() { + log_priority 7 || return 0 + echoerr "$(log_prefix)" "$(log_tag 7)" "$@" +} +log_info() { + log_priority 6 || return 0 + echoerr "$(log_prefix)" "$(log_tag 6)" "$@" +} +log_err() { + log_priority 3 || return 0 + echoerr "$(log_prefix)" "$(log_tag 3)" "$@" +} +log_crit() { + log_priority 2 || return 0 + echoerr "$(log_prefix)" "$(log_tag 2)" "$@" +} +uname_os() { + os=$(uname -s | tr '[:upper:]' '[:lower:]') + case "$os" in + cygwin_nt*) os="windows" ;; + mingw*) os="windows" ;; + msys_nt*) os="windows" ;; + esac + echo "$os" +} +uname_arch() { + arch=$(uname -m) + case $arch in + x86_64) arch="amd64" ;; + x86) arch="386" ;; + i686) arch="386" ;; + i386) arch="386" ;; + aarch64) arch="arm64" ;; + armv5*) arch="armv5" ;; + armv6*) arch="armv6" ;; + armv7*) arch="armv7" ;; + esac + echo ${arch} +} +uname_os_check() { + os=$(uname_os) + case "$os" in + darwin) return 0 ;; + dragonfly) return 0 ;; + freebsd) return 0 ;; + linux) return 0 ;; + android) return 0 ;; + nacl) return 0 ;; + netbsd) return 0 ;; + openbsd) return 0 ;; + plan9) return 0 ;; + solaris) return 0 ;; + windows) return 0 ;; + esac + log_crit "uname_os_check '$(uname -s)' got converted to '$os' which is not a GOOS value. Please file bug at https://github.com/client9/shlib" + return 1 +} +uname_arch_check() { + arch=$(uname_arch) + case "$arch" in + 386) return 0 ;; + amd64) return 0 ;; + arm64) return 0 ;; + armv5) return 0 ;; + armv6) return 0 ;; + armv7) return 0 ;; + ppc64) return 0 ;; + ppc64le) return 0 ;; + mips) return 0 ;; + mipsle) return 0 ;; + mips64) return 0 ;; + mips64le) return 0 ;; + s390x) return 0 ;; + amd64p32) return 0 ;; + esac + log_crit "uname_arch_check '$(uname -m)' got converted to '$arch' which is not a GOARCH value. Please file bug report at https://github.com/client9/shlib" + return 1 +} +untar() { + tarball=$1 + case "${tarball}" in + *.tar.gz | *.tgz) tar --no-same-owner -xzf "${tarball}" ;; + *.tar) tar --no-same-owner -xf "${tarball}" ;; + *.zip) unzip "${tarball}" ;; + *) + log_err "untar unknown archive format for ${tarball}" + return 1 + ;; + esac +} +http_download_curl() { + local_file=$1 + source_url=$2 + header=$3 + if [ -z "$header" ]; then + code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url") + else + code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url") + fi + if [ "$code" != "200" ]; then + log_debug "http_download_curl received HTTP status $code" + return 1 + fi + return 0 +} +http_download_wget() { + local_file=$1 + source_url=$2 + header=$3 + if [ -z "$header" ]; then + wget -q -O "$local_file" "$source_url" + else + wget -q --header "$header" -O "$local_file" "$source_url" + fi +} +http_download() { + log_debug "http_download $2" + if is_command curl; then + http_download_curl "$@" + return + elif is_command wget; then + http_download_wget "$@" + return + fi + log_crit "http_download unable to find wget or curl" + return 1 +} +http_copy() { + tmp=$(mktemp) + http_download "${tmp}" "$1" "$2" || return 1 + body=$(cat "$tmp") + rm -f "${tmp}" + echo "$body" +} +github_release() { + owner_repo=$1 + version=$2 + test -z "$version" && version="latest" + giturl="https://github.com/${owner_repo}/releases/${version}" + json=$(http_copy "$giturl" "Accept:application/json") + test -z "$json" && return 1 + version=$(echo "$json" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//') + test -z "$version" && return 1 + echo "$version" +} +hash_sha256() { + TARGET=${1:-/dev/stdin} + if is_command gsha256sum; then + hash=$(gsha256sum "$TARGET") || return 1 + echo "$hash" | cut -d ' ' -f 1 + elif is_command sha256sum; then + hash=$(sha256sum "$TARGET") || return 1 + echo "$hash" | cut -d ' ' -f 1 + elif is_command shasum; then + hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1 + echo "$hash" | cut -d ' ' -f 1 + elif is_command openssl; then + hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1 + echo "$hash" | cut -d ' ' -f a + else + log_crit "hash_sha256 unable to find command to compute sha-256 hash" + return 1 + fi +} +hash_sha256_verify() { + TARGET=$1 + checksums=$2 + if [ -z "$checksums" ]; then + log_err "hash_sha256_verify checksum file not specified in arg2" + return 1 + fi + BASENAME=${TARGET##*/} + want=$(grep "${BASENAME}" "${checksums}" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f 1) + if [ -z "$want" ]; then + log_err "hash_sha256_verify unable to find checksum for '${TARGET}' in '${checksums}'" + return 1 + fi + got=$(hash_sha256 "$TARGET") + if [ "$want" != "$got" ]; then + log_err "hash_sha256_verify checksum for '$TARGET' did not verify ${want} vs $got" + return 1 + fi +} +cat /dev/null <