Skip to content

Commit

Permalink
Infra: Use Ruff and uv in dev environment (#253)
Browse files Browse the repository at this point in the history
* Simplified to Ruff - fix applied

* Changed pylint to use ruff

* Upgraded pre-commit, added gpg-init

* Workflow upgrades and warning removals

* Fixed devcontainer warnings;
  • Loading branch information
mandarons authored Aug 9, 2024
1 parent 71adbc0 commit bd430d5
Show file tree
Hide file tree
Showing 35 changed files with 747 additions and 1,801 deletions.
10 changes: 8 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ RUN \
software-properties-common git default-jre && \
apt-get clean &&\
rm -rf /var/lib/apt/lists/*
# Install allure report
RUN \
wget https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.20.1/allure-commandline-2.20.1.zip && \
unzip allure-commandline-2.20.1.zip -d /allure && \
rm allure-commandline-2.20.1.zip

ENV PATH "/allure/allure-2.20.1/bin:${PATH}"

RUN mkdir /config /icloud && chown -R vscode:vscode /config /icloud
USER vscode
# Install uv (pip replacement)
RUN \
curl -LsSf https://astral.sh/uv/install.sh | sh

ENV PATH="/allure/allure-2.20.1/bin:/home/vscode/.cargo/bin:${PATH}"

WORKDIR /workspaces
77 changes: 39 additions & 38 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,47 @@
"containerEnv": {
"DEVCONTAINER": "1"
},
"extensions": [
"ms-python.vscode-pylance",
"visualstudioexptteam.vscodeintellicode",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"GitHub.vscode-pull-request-github"
],
"settings": {
"python.pythonPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.linting.flake8Path": "/usr/local/bin/flake8",
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
"python.linting.mypyPath": "/usr/local/bin/mypy",
"python.linting.pylintPath": "/usr/local/bin/pylint",
"python.formatting.provider": "black",
"python.testing.pytestArgs": ["--no-cov"],
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true,
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
"customizations": {
"vscode": {
"extensions": [
"ms-python.vscode-pylance",
"visualstudioexptteam.vscodeintellicode",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"GitHub.vscode-pull-request-github",
"github.vscode-github-actions",
"charliermarsh.ruff"
],
"settings": {
"[python]": {
"diffEditor.ignoreTrimWhitespace": false,
"editor.formatOnType": true,
"editor.formatOnSave": true,
"editor.wordBasedSuggestions": "off",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"python.pythonPath": "./venv/bin/python",
"python.testing.pytestArgs": ["--no-cov"],
"files.trimTrailingWhitespace": true,
"terminal.integrated.defaultProfile.linux": "bash",
"yaml.customTags": [
"!input scalar",
"!secret scalar",
"!include_dir_named scalar",
"!include_dir_list scalar",
"!include_dir_merge_list scalar",
"!include_dir_merge_named scalar"
]
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"yaml.customTags": [
"!input scalar",
"!secret scalar",
"!include_dir_named scalar",
"!include_dir_list scalar",
"!include_dir_merge_list scalar",
"!include_dir_merge_named scalar"
]
}
},
"postCreateCommand": "pip install --upgrade pip && pip install -r requirements-test.txt",

"postCreateCommand": "uv venv && . .venv/bin/activate && uv pip install -r requirements-test.txt && git config commit.gpgsign true",
"mounts": [
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.gnupg,target=/home/vscode/.gnupg,type=bind,consistency=cached"
]
}
}
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

54 changes: 28 additions & 26 deletions .github/workflows/ci-main-test-coverage-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Cache pip dependencies
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-dependencies
with:
path: ~/.cache/pip
Expand All @@ -43,13 +43,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Restore pip cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
Expand All @@ -60,16 +60,18 @@ jobs:
pip install -r requirements-test.txt
- name: Test with pytest
run: |
sudo mkdir /config /icloud && sudo chown -R $(id -u) /config /icloud && pytest
sudo mkdir /config /icloud &&
sudo chown -R $(id -u):$(id -g) /config /icloud &&
ENV_CONFIG_FILE_PATH=./tests/data/test_config.yaml pytest
- name: Upload coverage artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: coverage-output
path: htmlcov
retention-days: 1
- name: Checkout gh-pages
uses: actions/checkout@v3
uses: actions/checkout@v4
if: always()
continue-on-error: true
with:
Expand All @@ -90,19 +92,19 @@ jobs:
run: |
python generate_badges.py
- name: Upload tests artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: test-output.zip
path: test-output.zip
retention-days: 1
- name: Upload coverage artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-output
path: htmlcov
retention-days: 1
- name: Upload badges artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: badges-output
path: badges
Expand All @@ -112,13 +114,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download test artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: test-output.zip
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- name: Checkout gh-pages
uses: actions/checkout@v3
uses: actions/checkout@v4
if: always()
continue-on-error: true
with:
Expand All @@ -129,7 +131,7 @@ jobs:
unzip test-output.zip && rm test-output.zip
- name: Publish test report to gh-pages
if: always()
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
publish_branch: gh-pages
Expand All @@ -140,20 +142,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download coverage artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: coverage-output
path: coverage
- name: Checkout gh-pages
uses: actions/checkout@v3
uses: actions/checkout@v4
if: always()
continue-on-error: true
with:
ref: gh-pages
path: gh-pages
- name: Publish test coverage to gh-pages
if: always()
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
publish_branch: gh-pages
Expand All @@ -164,20 +166,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download badges artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: badges-output
path: badges
- name: Checkout gh-pages
uses: actions/checkout@v3
uses: actions/checkout@v4
if: always()
continue-on-error: true
with:
ref: gh-pages
path: gh-pages
- name: Publish badges to gh-pages
if: always()
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
publish_branch: gh-pages
Expand All @@ -188,24 +190,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Cache Docker layers
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci-pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ jobs:
pip install -r requirements-test.txt
- name: Test with pytest
run: |
sudo mkdir /config /icloud && sudo chown -R $(id -u):$(id -g) /config /icloud && pylint src/ tests/ && ENV_CONFIG_FILE_PATH=./tests/data/test_config.yaml pytest
sudo mkdir /config /icloud &&
sudo chown -R $(id -u):$(id -g) /config /icloud &&
ruff check &&
ENV_CONFIG_FILE_PATH=./tests/data/test_config.yaml pytest
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- name: Generate Allure Report
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/close-stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
- uses: actions/stale@v9
with:
stale-issue-message: "This issue is stale because it has been open 1 year with no activity. Remove stale label or comment or this will be closed in 5 days."
days-before-stale: 365
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/official-release-to-docker-hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Check Out Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Prepare
id: prep
run: |
Expand All @@ -32,25 +32,25 @@ jobs:
fi
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:latest"
echo "${TAGS}"
echo ::set-output name=tags::${TAGS}
echo ::set-output name=version::${VERSION}
echo "name=tags::${TAGS}" >> $GITHUB_OUTPUT
echo "name=version::${VERSION}" >> $GITHUB_OUTPUT
- name: Cache Docker layers
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
Expand All @@ -72,6 +72,6 @@ jobs:
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ allure-report
ignore-config.yaml
session
session_data
icloud/
icloud/
.ruff_cache/
Loading

0 comments on commit bd430d5

Please sign in to comment.