Skip to content

Commit

Permalink
Merge pull request #100 from OpenXbox/fix/pydantic_v2
Browse files Browse the repository at this point in the history
Compatibility improvements, meta changes
  • Loading branch information
tuxuser authored Nov 25, 2023
2 parents 398320c + 8fe0f8b commit d834c16
Show file tree
Hide file tree
Showing 40 changed files with 603 additions and 582 deletions.
26 changes: 11 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,22 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
python setup.py develop
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 xbox --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 xbox --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
ruff check xbox
ruff check tests
- name: Test with pytest
run: |
pytest
Expand All @@ -36,20 +32,20 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install setuptools wheel twine build
- name: Build and publish
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_KEY }}
run: |
python setup.py sdist bdist_wheel
python -m build
twine upload dist/*
87 changes: 41 additions & 46 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.0
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((xbox|tests)/.+)?[^/]+\.py$
- repo: https://gitlab.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
# - flake8-docstrings==1.5.0
- pydocstyle==5.1.1
files: ^(xbox)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args:
- --quiet
- --format=custom
- --configfile=bandit.yaml
files: ^(xbox|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
- repo: https://github.com/prettier/prettier
rev: 2.0.4
hooks:
- id: prettier
stages: [manual]

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.6
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((xbox|tests)/.+)?[^/]+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args:
- --configfile=pyproject.toml
- --quiet
- --format=custom
files: ^(xbox|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
4 changes: 2 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ sphinx:

build:
# readdocs master now includes a rust toolchain
os: "ubuntu-20.04"
os: "ubuntu-22.04"
tools:
python: "3.9"
python: "3.12"

python:
install:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 2.1.0 (2023-11-25)
* ! Deprecate python 3.7 !
* Deprecate flake8, use ruff for linting instead
* Fixes for compatibility with v2 of json parsing library `pydantic`
* Use python3.12 for CI and Docker
* Migrate from setup.py to pyproject.toml
* Remove requirements.txt
* Use datetime functionality with higher compatibility

## 2.0.11 (2021-04-30)

* Model validation fixes for optional properties (#41)
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cd xbox-webapi-python
python -m venv venv
source venv/bin/activate
pip install -e .[dev]
python setup.py develop
pre-commit install
```

4. Create a branch for local development::
Expand Down Expand Up @@ -98,6 +98,6 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.md.
3. The pull request should work for Python 3.7+. Check
3. The pull request should work for Python 3.8+. Check
<https://github.com/OpenXbox/xbox-webapi-python/actions?query=workflow%3Abuild>
and make sure that the tests pass for all supported Python versions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

#########################################
# Image WITH C compiler, building wheels for next stage
FROM python:3.10-alpine as bigimage
FROM python:3.12-alpine as bigimage

ENV LANG C.UTF-8

# Copy project files
COPY . /src/xbox-webapi

# install the C compiler
RUN apk add --no-cache jq gcc musl-dev libffi-dev openssl-dev
RUN apk add --no-cache jq gcc musl-dev libffi-dev openssl-dev cargo

# instead of installing, create a wheel
RUN pip wheel --wheel-dir=/root/wheels /src/xbox-webapi

#########################################
# Image WITHOUT C compiler, installing the component from wheel
FROM python:3.10-alpine as smallimage
FROM python:3.12-alpine as smallimage

RUN apk add --no-cache openssl

Expand Down
13 changes: 4 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,16 @@ clean-pyc: ## remove Python file artifacts
find . -name '__pycache__' -exec rm -fr {} +

clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/

lint: ## check style with flake8
flake8 xbox tests
lint: ## check style with ruff
ruff check --fix xbox
ruff check --fix tests

test: ## run tests quickly with the default Python
py.test

test-all: ## run tests on every Python version with tox
tox

coverage: ## check code coverage quickly with the default Python
coverage run --source xbox -m pytest
coverage report -m
Expand All @@ -79,11 +76,9 @@ release: clean ## package and upload a release
twine upload dist/*

dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
python -m build
ls -l dist

install: clean ## install the package to the active Python's site-packages
pip install -r requirements.txt
pre-commit install
pip install -e .
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Authentication is supported via OAuth2.

## Dependencies

- Python >= 3.7
- Python >= 3.8

## How to use

Expand Down Expand Up @@ -100,12 +100,17 @@ async def async_main():
with open(tokens_file) as f:
tokens = f.read()
# Assign gathered tokens
auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
auth_mgr.oauth = OAuth2TokenResponse.model_validate_json(tokens)
except FileNotFoundError as e:
print(
f"File {tokens_file} isn`t found or it doesn`t contain tokens! err={e}"
)
sys.exit(-1)
print("Authorizing via OAUTH")
url = auth_mgr.generate_authorization_url()
print(f"Auth via URL: {url}")
authorization_code = input("Enter authorization code> ")
tokens = await auth_mgr.request_oauth_token(authorization_code)
auth_mgr.oauth = tokens

"""
Refresh tokens, just in case
Expand Down
17 changes: 0 additions & 17 deletions bandit.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# The short X.Y version
version = '1.0'
# The full version, including alpha/beta/rc tags
release = '2.0.11'
release = '2.1.0'


# -- General configuration ---------------------------------------------------
Expand Down
Loading

0 comments on commit d834c16

Please sign in to comment.