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

Update linters and adjust code #132

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f30d939
remove old linters and scripts
sergioteula Oct 5, 2024
5089686
added pre-commit
sergioteula Oct 5, 2024
19c9122
ruff and mypy working for precommit
sergioteula Oct 6, 2024
cb65227
added ruff mypy and tests to github workflow
sergioteula Oct 6, 2024
70725b9
adjust pyproject and remove workflow for pull request
sergioteula Oct 6, 2024
d76c0ef
try fix for tests with other python versions
sergioteula Oct 6, 2024
7559ebb
use target version for ruff
sergioteula Oct 6, 2024
dfcd6c8
fix unittest execution
sergioteula Oct 6, 2024
e04ed75
test python 3.5 for tests
sergioteula Oct 6, 2024
d72d924
removed python 3.5 for tests
sergioteula Oct 6, 2024
51c3294
added makefile
sergioteula Oct 6, 2024
6d5cdda
automatic fixes from pre-commit
sergioteula Oct 7, 2024
bb07147
applied ruff automatic fixes
sergioteula Oct 7, 2024
8b5dcea
added command to run all tests with different python versions
sergioteula Oct 7, 2024
0f27d27
added pre-commit for mypy from repo
sergioteula Oct 8, 2024
63f6002
use pytest for running tests
sergioteula Oct 8, 2024
ecd790f
add coverage to py312 test job
sergioteula Oct 8, 2024
a97c17e
add pytest config
sergioteula Oct 8, 2024
f1468d4
added environment file for credentials in tests
sergioteula Oct 8, 2024
33649e3
add short summary for pytest
sergioteula Oct 9, 2024
244c189
use amazon credentials on workflow
sergioteula Oct 9, 2024
37ad1fa
created integration test for varios api methods
sergioteula Oct 9, 2024
ae44f9d
run tests in series
sergioteula Oct 9, 2024
afc2a5b
remove get variations from test
sergioteula Oct 9, 2024
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
14 changes: 0 additions & 14 deletions .coveragerc

This file was deleted.

4 changes: 4 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
API_KEY=
API_SECRET=
AFFILIATE_TAG=
COUNTRY_CODE=
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

12 changes: 12 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash -e

docker build \
--build-arg TAG="3.12" \
--build-arg UID="$(id -u)" \
--build-arg GID="$(id -g)" \
-t python-amazon-paapi .

touch .env

docker run -t --rm -u "$(id -u):$(id -g)" -v "${PWD}:/code" --env-file .env \
python-amazon-paapi -c "python -m pre_commit"
12 changes: 0 additions & 12 deletions .githooks/pre-push

This file was deleted.

6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/---bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ assignees: ''
---

**Steps to reproduce**
1.
2.
3.
1.
2.
3.

**Code example**
```python
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/---feature-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ assignees: ''
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is.
A clear and concise description of what the problem is.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.
Expand Down
95 changes: 70 additions & 25 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,118 @@ name: Lint and test

on:
push:
pull_request:
types: [opened, reopened]

permissions:
pull-requests: read

jobs:
env:
API_KEY: ${{ secrets.API_KEY }}
API_SECRET: ${{ secrets.API_SECRET }}
AFFILIATE_TAG: ${{ secrets.AFFILIATE_TAG }}
COUNTRY_CODE: ${{ secrets.COUNTRY_CODE }}

isort:
jobs:
ruff:
runs-on: ubuntu-latest
container:
image: python:3.12
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: pip install isort
- name: Check imports order
run: isort -c .
run: pip install ruff
- name: Check code errors
run: ruff check --output-format=github .

black:
mypy:
runs-on: ubuntu-latest
container:
image: python:3.12
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: pip install black
- name: Check code format
run: black --check --diff --color .
run: pip install mypy
- name: Check code errors
run: mypy amazon_paapi

flake8:
test-py37:
runs-on: ubuntu-latest
needs: [test-py38]
container:
image: python:3.12
image: python:3.7
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: pip install flake8
- name: Check code errors
run: flake8 .
run: pip install -e . && pip install pytest
- name: Run tests
run: python -m pytest

pylint:
test-py38:
runs-on: ubuntu-latest
needs: [test-py39]
container:
image: python:3.12
image: python:3.8
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: pip install pylint
- name: Check code errors
run: find . -type f -name '*.py' | xargs pylint --disable=missing-docstring --disable=too-few-public-methods
run: pip install -e . && pip install pytest
- name: Run tests
run: python -m pytest

test-py39:
runs-on: ubuntu-latest
needs: [test-py310]
container:
image: python:3.9
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: pip install -e . && pip install pytest
- name: Run tests
run: python -m pytest

test-py310:
runs-on: ubuntu-latest
needs: [test-py311]
container:
image: python:3.10
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: pip install -e . && pip install pytest
- name: Run tests
run: python -m pytest

test-py311:
runs-on: ubuntu-latest
needs: [test-py312]
container:
image: python:3.11
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: pip install -e . && pip install pytest
- name: Run tests
run: python -m pytest


test:
test-py312:
runs-on: ubuntu-latest
container:
image: python:3.12
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: pip install coverage certifi six python_dateutil setuptools urllib3
run: pip install -e . && pip install coverage pytest
- name: Run tests
run: coverage run -m unittest && coverage xml && coverage report
run: coverage run -m pytest && coverage xml && coverage report
- name: Save code coverage file
uses: actions/upload-artifact@v4
with:
Expand All @@ -77,7 +122,7 @@ jobs:

sonar:
runs-on: ubuntu-latest
needs: [test]
needs: [test-py312]
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Custom folders and files to ignore
.vscode/
.DS_Store
secrets.py
test.py
coverage_html_report


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
58 changes: 58 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.12

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: mixed-line-ending
- id: check-yaml
- id: check-added-large-files
- id: check-ast
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-toml
- id: name-tests-test

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/lk16/detect-missing-init
rev: v0.1.6
hooks:
- id: detect-missing-init
args: ["--create", "--python-folders", "amazon_paapi"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.11.2'
hooks:
- id: mypy
exclude: sdk/

- repo: local
hooks:
- id: mypy
name: Checking types with mypy
language: system
entry: "python -m mypy amazon_paapi"
pass_filenames: false

- id: test
name: Running tests
language: system
entry: "python -m coverage run -m pytest -rs"
pass_filenames: false

- id: test
name: Checking coverage
language: system
entry: "python -m coverage report"
pass_filenames: false
3 changes: 0 additions & 3 deletions .shellcheckrc

This file was deleted.

29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG TAG="3.12"

FROM python:${TAG}

ARG UID="1000"
ARG GID="1000"

ENV PRE_COMMIT_HOME="/code/.cache/pre-commit"
ENV PRE_COMMIT_COLOR="always"

RUN groupadd --gid ${GID} user \
&& useradd --uid ${UID} --gid user --shell /bin/bash --create-home user

USER user

WORKDIR /code

RUN pip install --no-cache-dir \
coverage \
mypy \
pre-commit \
pytest \
ruff

COPY setup.py setup.py
COPY README.md README.md
RUN pip install --no-cache-dir -e .

ENTRYPOINT [ "bash" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Sergio Abad
Copyright (c) 2024 Sergio Abad

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export UID:=$(shell id -u)
export GID:=$(shell id -g)

export PYTHON_TAGS = 3.7 3.8 3.9 3.10 3.11 3.12

setup:
@git config --unset-all core.hooksPath || true
@git config --local core.hooksPath .githooks

build:
@docker build --build-arg TAG="3.12" --build-arg UID="${UID}" --build-arg GID="${GID}" -t python-amazon-paapi .

coverage: build
@touch .env
@docker run -t --rm -u "${UID}:${GID}" -v "${PWD}:/code" --env-file .env python-amazon-paapi -c \
"python -m coverage run -m pytest -rs && python -m coverage xml && python -m coverage report"

test: build
@touch .env
@docker run -t --rm -u "${UID}:${GID}" -v "${PWD}:/code" --env-file .env python-amazon-paapi -c "python -m pytest -rs"

test-all-python-tags:
@touch .env
@for tag in $$PYTHON_TAGS; do \
docker build --build-arg TAG="$$tag" --build-arg UID="${UID}" --build-arg GID="${GID}" -t python-amazon-paapi .; \
docker run -t --rm -u "${UID}:${GID}" -v "${PWD}:/code" python-amazon-paapi -c "python -m pytest -rs"; \
done

lint: build
@touch .env
@docker run --rm -t -u "${UID}:${GID}" -v "${PWD}:/code" --env-file .env python-amazon-paapi -c "python -m pre_commit run -a"

pre-commit:
@./.githooks/pre-commit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ API](https://webservices.amazon.com/paapi5/documentation/quick-start/using-sdk.h
This module allows interacting with Amazon using the official API in an easier way.

[![PyPI](https://img.shields.io/pypi/v/python-amazon-paapi?color=%231182C2&label=PyPI)](https://pypi.org/project/python-amazon-paapi/)
[![Python](https://img.shields.io/badge/Python->3.6-%23FFD140)](https://www.python.org/)
[![Python](https://img.shields.io/badge/Python->3.7-%23FFD140)](https://www.python.org/)
[![License](https://img.shields.io/badge/License-MIT-%23e83633)](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE)
[![Amazon API](https://img.shields.io/badge/Amazon%20API-5.0-%23FD9B15)](https://webservices.amazon.com/paapi5/documentation/)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sergioteula_python-amazon-paapi&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sergioteula_python-amazon-paapi)
Expand Down
2 changes: 1 addition & 1 deletion amazon_paapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Amazon Product Advertising API wrapper for Python"""
"""Amazon Product Advertising API wrapper for Python."""

__author__ = "Sergio Abad"

from .api import AmazonApi

Check failure on line 5 in amazon_paapi/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

amazon_paapi/__init__.py:5:18: F401 `.api.AmazonApi` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
from .tools import get_asin

Check failure on line 6 in amazon_paapi/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

amazon_paapi/__init__.py:6:20: F401 `.tools.get_asin` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
Loading
Loading