Skip to content

Commit

Permalink
Use pyproject.toml, poetry, ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrisan committed May 15, 2023
1 parent 558fe27 commit 010bb74
Show file tree
Hide file tree
Showing 15 changed files with 921 additions and 69 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/linting.yml

This file was deleted.

23 changes: 14 additions & 9 deletions .github/workflows/publish-to-pypi-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Fetch gateway-mfr-rs
env:
Expand Down Expand Up @@ -60,22 +60,27 @@ jobs:
mv gateway_mfr_aarch64 hm_pyhelper/gateway_mfr_aarch64
mv gateway_mfr_x86_64 hm_pyhelper/gateway_mfr_x86_64
- name: Install pypa/build
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.4.2

- name: Install dependencies
run: |
python -m pip install build --user
poetry install
- name: Build a binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/ .
poetry build
- uses: actions/upload-artifact@v3
with:
name: wheels
path: ./dist/*

- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
if: github.ref == 'refs/heads/master'
run: |
poetry config pypi-token.test-pypi ${{ secrets.TEST_PYPI_API_TOKEN }}
poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry publish
23 changes: 14 additions & 9 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Fetch gateway-mfr-rs
env:
Expand All @@ -30,7 +30,7 @@ jobs:
wget "https://github.com/helium/gateway-mfr-rs/releases/download/${GATEWAY_MFR_RS_RELEASE}/gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-x86_64-unknown-debian-gnu.checksum"
SHA256_ARM=$( shasum -a 256 "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.tar.gz" | awk '{print $1}')
SHA256_AARCH64=$( shasum -a 256 "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-aarch64-unknown-linux-gnu.tar.gz" | awk '{print $1}')
SHA256_X86_64=$( shasum -a 256 "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-x86_64-unknowm-debian-gnu.tar.gz" | awk '{print $1}')
SHA256_X86_64=$( shasum -a 256 "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-x86_64-unknown-debian-gnu.tar.gz" | awk '{print $1}')
echo "Generated checksum ARM: ${SHA256_ARM}"
echo "Generated checksum AARCH64: ${SHA256_AARCH64}"
echo "Generated checksum X86_64: ${SHA256_X86_64}"
Expand Down Expand Up @@ -62,13 +62,18 @@ jobs:
mv gateway_mfr_aarch64 hm_pyhelper/gateway_mfr_aarch64
mv gateway_mfr_x86_64 hm_pyhelper/gateway_mfr_x86_64
- name: Install pypa/build
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.4.2

- name: Install dependencies
run: |
python -m pip install build --user
poetry install
- name: Build a binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/ .
poetry build
- uses: actions/upload-artifact@v3
with:
Expand All @@ -93,6 +98,6 @@ jobs:

- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry config http-basic.pypi ${{ secrets.PYPI_API_TOKEN }}
poetry publish
25 changes: 25 additions & 0 deletions .github/workflows/python-linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Python Linting

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.4.2
- name: Install dependencies
run: |
poetry install --with dev
- name: Lint with ruff
run: |
poetry run ruff check hm_pyhelper
29 changes: 29 additions & 0 deletions .github/workflows/security-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Code Security Audit

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.4.2

- name: Install dependencies
run: |
poetry install --with dev
- name: Run bandit against code base
run: |
poetry run bandit -r hm_pyhelper -c pyproject.toml
18 changes: 9 additions & 9 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Install requirements
run: |
pip install -r requirements.txt
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.4.2

- name: Install test requirements
- name: Install dependencies
run: |
pip install -r test-requirements.txt
poetry install --with dev
- name: Run tests
run: |
export PYTHONPATH=`pwd`
pytest --cov=hm_pyhelper --cov-fail-under=90
poetry run pytest --cov=hm_pyhelper --cov-fail-under=90
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dmypy.json
# Pyre type checker
.pyre/
venv

# ruff
.ruff_cache
1 change: 0 additions & 1 deletion dev-requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion hm_pyhelper/miner_json_rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __fetch_data(self, method, **kwargs):
if kwargs:
req_body["params"] = kwargs
try:
response = requests.post(self.url, json=req_body)
response = requests.post(self.url, json=req_body) # nosec
except requests.exceptions.ConnectionError:
raise MinerConnectionError(
"Unable to connect to miner %s" % self.url
Expand Down
8 changes: 4 additions & 4 deletions hm_pyhelper/miner_param.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import re
import subprocess
import subprocess # nosec
import json
import platform
from urllib.parse import urlparse
Expand Down Expand Up @@ -30,7 +30,7 @@ def run_gateway_mfr(sub_command: str, slot: int = False) -> dict:
command = get_gateway_mfr_command(sub_command, slot=slot)

try:
run_gateway_mfr_result = subprocess.run(
run_gateway_mfr_result = subprocess.run( # nosec
command,
capture_output=True,
check=True
Expand Down Expand Up @@ -86,7 +86,7 @@ def get_gateway_mfr_version() -> Version:
command = [gateway_mfr_path, '--version']

try:
run_gateway_mfr_result = subprocess.run(
run_gateway_mfr_result = subprocess.run( # nosec
command,
capture_output=True,
check=True
Expand Down Expand Up @@ -425,7 +425,7 @@ def config_search_param(command, param):
raise TypeError("The command must be a string value")
if type(param) is not str:
raise TypeError("The param must be a string value")
result = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
result = subprocess.Popen(command.split(), stdout=subprocess.PIPE) # nosec
out, err = result.communicate()
out = out.decode("UTF-8")
if param in out:
Expand Down
Loading

0 comments on commit 010bb74

Please sign in to comment.