mirror of
https://github.com/scito/extract_otp_secret_keys.git
synced 2025-12-12 17:46:36 +01:00
fixes after change to src-layout
This commit is contained in:
parent
3e4476e317
commit
144c9e6320
10 changed files with 63 additions and 21 deletions
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
|
|
@ -36,8 +36,8 @@ jobs:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install flake8 pytest pytest-mock pytest-cov mypy types-protobuf
|
pip install -r requirements-dev.txt
|
||||||
pip install --use-pep517 -r requirements.txt
|
pip install .
|
||||||
- name: Lint with flake8
|
- name: Lint with flake8
|
||||||
run: |
|
run: |
|
||||||
# stop the build if there are Python syntax errors or undefined names
|
# stop the build if there are Python syntax errors or undefined names
|
||||||
|
|
@ -46,8 +46,8 @@ jobs:
|
||||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
|
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
|
||||||
- name: Type checking with mypy
|
- name: Type checking with mypy
|
||||||
run: |
|
run: |
|
||||||
mypy --install-types --non-interactive *.py
|
mypy --install-types --non-interactive src tests
|
||||||
mypy --strict *.py
|
mypy --strict src tests
|
||||||
if: matrix.python-version == '3.x'
|
if: matrix.python-version == '3.x'
|
||||||
- name: Test with pytest
|
- name: Test with pytest
|
||||||
run: pytest
|
run: pytest
|
||||||
|
|
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -9,8 +9,7 @@ venv/
|
||||||
!example_output.csv
|
!example_output.csv
|
||||||
!.github/
|
!.github/
|
||||||
!.flake8
|
!.flake8
|
||||||
.vscode
|
!.vscode/
|
||||||
!.vscode/settings.json
|
|
||||||
!.devcontainer/
|
!.devcontainer/
|
||||||
!.devcontainer/*.json
|
!.devcontainer/*.json
|
||||||
*.whl
|
*.whl
|
||||||
|
|
@ -19,3 +18,4 @@ dist/
|
||||||
extract_otp_secret_keys.egg-info/
|
extract_otp_secret_keys.egg-info/
|
||||||
*.xml
|
*.xml
|
||||||
pytest-coverage.txt
|
pytest-coverage.txt
|
||||||
|
tests/reports/
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,6 @@ RUN apt-get update && apt-get install -y libzbar0 libsm6 python3-opencv nano \
|
||||||
|
|
||||||
WORKDIR /files
|
WORKDIR /files
|
||||||
|
|
||||||
ENTRYPOINT ["python", "/extract/extract_otp_secret_keys.py"]
|
ENTRYPOINT ["python", "/extract/src/extract_otp_secret_keys.py"]
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source https://github.com/scito/extract_otp_secret_keys
|
LABEL org.opencontainers.image.source https://github.com/scito/extract_otp_secret_keys
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ RUN apk add --no-cache nano zlib jpeg \
|
||||||
&& if [[ "$(apk --print-arch)" == "aarch64" ]]; then apk add --no-cache --virtual .build-deps gcc libc-dev python3-dev py3-setuptools zlib-dev jpeg-dev; fi \
|
&& if [[ "$(apk --print-arch)" == "aarch64" ]]; then apk add --no-cache --virtual .build-deps gcc libc-dev python3-dev py3-setuptools zlib-dev jpeg-dev; fi \
|
||||||
&& pip install --no-cache-dir protobuf qrcode Pillow \
|
&& pip install --no-cache-dir protobuf qrcode Pillow \
|
||||||
&& if [[ "$(apk --print-arch)" == "aarch64" ]]; then apk del .build-deps; fi \
|
&& if [[ "$(apk --print-arch)" == "aarch64" ]]; then apk del .build-deps; fi \
|
||||||
&& if [[ "$RUN_TESTS" == "true" ]]; then /extract/run_pytest.sh test_extract_otp_secret_keys_pytest.py -k "not qreader" --relaxed; else echo "Not running tests..."; fi
|
&& if [[ "$RUN_TESTS" == "true" ]]; then /extract/run_pytest.sh tests/test_extract_otp_secret_keys_pytest.py -k "not qreader" --relaxed; else echo "Not running tests..."; fi
|
||||||
|
|
||||||
WORKDIR /files
|
WORKDIR /files
|
||||||
|
|
||||||
ENTRYPOINT ["python", "/extract/extract_otp_secret_keys.py"]
|
ENTRYPOINT ["python", "/extract/src/extract_otp_secret_keys.py"]
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source https://github.com/scito/extract_otp_secret_keys
|
LABEL org.opencontainers.image.source https://github.com/scito/extract_otp_secret_keys
|
||||||
|
|
|
||||||
|
|
@ -48,13 +48,13 @@ scripts = {extract_otp_secret_keys = "extract_otp_secret_keys:sys_main"}
|
||||||
urls = {Project-URL = "https://github.com/scito/extract_otp_secret_keys", Bug-Reports = "https://github.com/scito/extract_otp_secret_keys/issues", Source = "https://github.com/scito/extract_otp_secret_keys" }
|
urls = {Project-URL = "https://github.com/scito/extract_otp_secret_keys", Bug-Reports = "https://github.com/scito/extract_otp_secret_keys/issues", Source = "https://github.com/scito/extract_otp_secret_keys" }
|
||||||
|
|
||||||
[tool.setuptools]
|
[tool.setuptools]
|
||||||
py-modules = ["extract_otp_secret_keys", "protobuf_generated_python.google_auth_pb2"]
|
py-modules = ["extract_otp_secret_keys"]
|
||||||
|
|
||||||
[tool.setuptools.dynamic]
|
[tool.setuptools.dynamic]
|
||||||
# TODO version = {attr = "extract_otp_secret_keys.VERSION"}
|
# TODO version = {attr = "extract_otp_secret_keys.VERSION"}
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
"." = ["*.txt", "*.json", "*.csv", "*.png", "*.md"]
|
"extract_otp_secret_keys" = ["*.txt", "*.json", "*.csv", "*.png", "*.md"]
|
||||||
|
|
||||||
# https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure%3E
|
# https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure%3E
|
||||||
# https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#which-import-mode
|
# https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#which-import-mode
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
cd /extract
|
cd /extract
|
||||||
pip install -U pytest pytest-mock && pytest "$@"
|
pip install -U pytest pytest-mock && pip install --no-deps . && pytest "$@"
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ Usage:
|
||||||
with Capturing() as output:
|
with Capturing() as output:
|
||||||
print("Output")
|
print("Output")
|
||||||
'''
|
'''
|
||||||
# TODO remove type ignore when fixed, see https://github.com/python/mypy/issues/11871, https://stackoverflow.com/questions/72174409/type-hinting-the-return-value-of-a-class-method-that-returns-self
|
# TODO remove type ignore if fixed, see https://github.com/python/mypy/issues/11871, https://stackoverflow.com/questions/72174409/type-hinting-the-return-value-of-a-class-method-that-returns-self
|
||||||
def __enter__(self): # type: ignore
|
def __enter__(self): # type: ignore
|
||||||
self._stdout = sys.stdout
|
self._stdout = sys.stdout
|
||||||
sys.stdout = self._stringio_std = io.StringIO()
|
sys.stdout = self._stringio_std = io.StringIO()
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ if [ "$OLDVERSION" != "$VERSION" ] || ! $ignore_version_check; then
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
cmd="$BIN/$DEST/bin/protoc --plugin=protoc-gen-mypy=/home/rkurmann/.local/bin/protoc-gen-mypy --python_out=protobuf_generated_python --mypy_out=protobuf_generated_python google_auth.proto"
|
cmd="$BIN/$DEST/bin/protoc --plugin=protoc-gen-mypy=$HOME/.local/bin/protoc-gen-mypy --python_out=protobuf_generated_python --mypy_out=protobuf_generated_python src/google_auth.proto"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
|
|
@ -232,17 +232,42 @@ cmd="$MYPY --install-types --non-interactive *.py"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
cmd="$MYPY --strict *.py"
|
# change to src as python -m mypy adds the current dir Python sys.path
|
||||||
|
# execute in a subshell in order not to loose the exit code and not to change the dir in the currrent shell
|
||||||
|
cmd="(cd src && $MYPY --strict *.py ../tests)"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
|
# pip install
|
||||||
|
|
||||||
|
cmd="$PIP install -e ."
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
|
cmd="extract_otp_secret_keys example_export.txt"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
|
cmd="extract_otp_secret_keys - < example_export.txt"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
|
|
||||||
cmd="pytest --cov=test_extract_otp_secret_keys_pytest --junitxml=pytest.xml --cov-report=term-missing | tee pytest-coverage.txt"
|
cmd="$PYTHON src/extract_otp_secret_keys.py example_export.txt"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
cmd="$PIPENV run pytest --cov=test_extract_otp_secret_keys_pytest"
|
cmd="$PYTHON src/extract_otp_secret_keys.py - < example_export.txt"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
|
COVERAGE_OUT="tests/reports/pytest-coverage.txt"
|
||||||
|
cmd="pytest --cov=test_extract_otp_secret_keys_pytest --junitxml=tests/reports/pytest.xml --cov-report html:tests/reports/html --cov-report=term-missing tests/ | tee $COVERAGE_OUT"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
|
cmd="$PIPENV run pytest --cov=test_extract_otp_secret_keys_pytest tests/"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
|
|
@ -250,7 +275,8 @@ eval "$cmd"
|
||||||
|
|
||||||
# https://github.com/marketplace/actions/pytest-coverage-comment
|
# https://github.com/marketplace/actions/pytest-coverage-comment
|
||||||
# Coverage-95%25-yellowgreen
|
# Coverage-95%25-yellowgreen
|
||||||
TOTAL_COVERAGE=$(cat pytest-coverage.txt | grep 'TOTAL' | perl -ne 'print "$&" if /\b(\d{1,3})%/') && perl -i -pe "s/coverage-(\d{1,3}%)25-/coverage-${TOTAL_COVERAGE}25-/" README.md
|
echo -e "Upgrade code coverage in README.md"
|
||||||
|
TOTAL_COVERAGE=$(cat $COVERAGE_OUT | grep 'TOTAL' | perl -ne 'print "$&" if /\b(\d{1,3})%/') && perl -i -pe "s/coverage-(\d{1,3}%)25-/coverage-${TOTAL_COVERAGE}25-/" README.md
|
||||||
|
|
||||||
# Build docker
|
# Build docker
|
||||||
|
|
||||||
|
|
@ -258,7 +284,15 @@ cmd="docker build . -t extract_otp_secret_keys_no_qr_reader -f Dockerfile_no_qr_
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
cmd="docker run --entrypoint /extract/run_pytest.sh --rm -v \"$(pwd)\":/files:ro extract_otp_secret_keys_no_qr_reader test_extract_otp_secret_keys_pytest.py -k 'not qreader' -vvv --relaxed"
|
cmd="docker run --rm -v \"$(pwd)\":/files:ro extract_otp_secret_keys_no_qr_reader example_export.txt"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
|
cmd="docker run --rm -i -v \"$(pwd)\":/files:ro extract_otp_secret_keys_no_qr_reader - < example_export.txt"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
|
cmd="docker run --entrypoint /extract/run_pytest.sh --rm -v \"$(pwd)\":/files:ro extract_otp_secret_keys_no_qr_reader tests/test_extract_otp_secret_keys_pytest.py -k 'not qreader' -vvv --relaxed"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
|
|
@ -266,15 +300,23 @@ cmd="docker build . -t extract_otp_secret_keys --pull"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
|
cmd="docker run --rm -v \"$(pwd)\":/files:ro extract_otp_secret_keys example_export.txt"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
|
cmd="docker run --rm -i -v \"$(pwd)\":/files:ro extract_otp_secret_keys - < example_export.txt"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
|
||||||
cmd="docker run --entrypoint /extract/run_pytest.sh --rm -v \"$(pwd)\":/files:ro extract_otp_secret_keys"
|
cmd="docker run --entrypoint /extract/run_pytest.sh --rm -v \"$(pwd)\":/files:ro extract_otp_secret_keys"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
cmd="docker image prune"
|
cmd="docker image prune || echo 'No docker image pruning'"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
cmd="$PYTHON extract_otp_secret_keys.py &"
|
cmd="$PYTHON src/extract_otp_secret_keys.py &"
|
||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue