Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyproject & friends #257

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ result = client.create_add_gateway_txn('owner_address', 'payer_address', 'gatewa
To run tests:

```bash
pip install -r requirements.txt
pip install -r test-requirements.txt
PYTHONPATH=./ pytest
poetry install --with dev
poetry run pytest --cov=hm_pyhelper --cov-fail-under=90
```

## Referencing a branch for development
Expand Down
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