Skip to content

Commit

Permalink
Merge pull request #2654 from alandtse/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse authored Oct 31, 2024
2 parents b6c45d0 + 97536d3 commit 65c81f9
Show file tree
Hide file tree
Showing 15 changed files with 2,979 additions and 1,443 deletions.
9 changes: 7 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# See here for image contents: https://github.com/devcontainers/images/tree/main/src/python

# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
ARG VARIANT="3.11-bullseye"
ARG VARIANT="3.12-bullseye"
FROM mcr.microsoft.com/devcontainers/python:${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# Workaround https://unix.stackexchange.com/questions/2544/how-to-work-around-release-file-expired-problem-on-a-local-mirror

# RUN echo "Acquire::Check-Valid-Until \"false\";\nAcquire::Check-Date \"false\";" | cat > /etc/apt/apt.conf.d/10no--check-valid-until
# RUN apt-get update && apt-get install -y ack

RUN pipx install poetry
WORKDIR /workspace
COPY pyproject.toml poetry.lock ./
RUN poetry update
# RUN poetry update

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
# COPY requirements.txt /tmp/pip-tmp/
Expand Down
31 changes: 13 additions & 18 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,32 @@
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3.11-bullseye",
"VARIANT": "3.12-bullseye",
// Options
"NODE_VERSION": "none"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
"customizations": {
"vscode": {
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": ["ms-python.python", "ms-python.vscode-pylance"]
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": ["ms-python.python", "ms-python.vscode-pylance"],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
"runArgs": ["--userns=keep-id"],
"containerUser": "vscode",
"updateRemoteUserUID": true,
"containerEnv": {
"HOME": "/home/vscode"
}
}
52 changes: 52 additions & 0 deletions .github/workflows/poetry-composite-action/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "Install poetry and dependencies"
description: "Install poetry and dependencies"
inputs:
directory:
description: "Directory where you want to run poetry install"
required: false
default: "./"
python_version:
description: "Python version to use"
required: false
default: "3.12"
poetry_version:
description: "Poetry version to use"
required: false
default: "1.8.2"
cache_dependencies:
description: "Whether the dependencies must be cached"
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.local
key: poetry-${{ inputs.poetry_version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ inputs.poetry_version }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: cache dependencies
if: inputs.cache_dependencies == 'true'
id: cache-deps
uses: actions/cache@v4
with:
path: .venv
key: pydeps-${{ hashFiles(format('{0}/poetry.lock', inputs.directory)) }}
- name: Install dependencies
shell: bash
run: cd $INPUT_DIRECTORY; poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'
env:
INPUT_DIRECTORY: ${{ inputs.directory }}
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test

on:
workflow_dispatch:
push:
paths:
- "**.py"
pull_request:
paths:
- "**.py"
- "poetry.lock"

jobs:
tests:
runs-on: "ubuntu-latest"
name: Run tests
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: ./.github/workflows/poetry-composite-action
- name: Prepare test env
run: bash tests/setup.sh
- name: Install poetry
run: poetry install
- name: Run tests
run: |
poetry run pytest \
-qq \
--timeout=9 \
--durations=10 \
-n auto \
--cov custom_components.alexa_media \
--cov-report xml \
-o console_output_style=count \
-p no:sugar \
tests
poetry run coverage lcov
- name: Upload Coverage Results
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
2 changes: 1 addition & 1 deletion .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-python@v2
name: Setup Python
with:
python-version: "3.8.x"
python-version: "3.12.x"
- uses: actions/cache@v2
name: Cache
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ venv.bak/
# macOS files
._*
.DS_Store
coverage.lcov
custom_components/test
10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ repos:
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.10.0
- repo: https://github.com/pre-commit/mirrors-prettier
hooks:
- id: prettier
exclude: ^custom_components/alexa_media/translations|CHANGELOG.md
rev: v4.0.0-alpha.8
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py39-plus]
Expand All @@ -69,11 +69,7 @@ repos:
rev: 1.7.9
hooks:
- id: bandit
args:
- --quiet
- --format=custom
- --configfile=tests/bandit.yaml
files: ^(homeassistant|script|tests)/.+\.py$
args: ["-c", "pyproject.toml"]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ async def async_remove_entry(hass, entry) -> bool:
login_obj = AlexaLogin(
url="",
email=email,
password="",
password="", # nosec
outputpath=hass.config.path,
)
# Delete cookiefile
Expand Down
5 changes: 4 additions & 1 deletion custom_components/alexa_media/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ async def calculate_uuid(hass, email: str, url: str) -> dict:
# increment uuid for second accounts
+ return_index
# hash email/url in case HA uuid duplicated
+ int(hashlib.md5((email.lower() + url.lower()).encode()).hexdigest(), 16)
+ int(
hashlib.sha256((email.lower() + url.lower()).encode()).hexdigest(),
16, # nosec
)
)[-32:]
result["index"] = return_index
_LOGGER.debug("%s: Returning uuid %s", hide_email(email), result)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/alandtse/alexa_media_player/issues",
"loggers": ["alexapy", "authcaptureproxy"],
"requirements": ["alexapy==1.29.3", "packaging>=20.3", "wrapt>=1.14.0"],
"requirements": ["alexapy==1.29.4", "packaging>=20.3", "wrapt>=1.14.0"],
"version": "4.13.5"
}
Loading

0 comments on commit 65c81f9

Please sign in to comment.