Skip to content

Commit

Permalink
chore: validate files with Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviortheking committed Sep 25, 2024
1 parent 34b0da8 commit 299a00a
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 331 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,31 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
# see details (matrix, python-version, python-version-file, etc.)
# https://github.com/actions/setup-python
with:
python-version: ${{ matrix.python-version }}

- name: Install PDM
uses: pdm-project/setup-pdm@v4

- name: Cache the Virtual Env
uses: actions/cache@v3
with:
path: ./.venv
key: venv-${{ hashFiles('pdm.lock') }}
key: venv-${{ matrix.python-version }}-${{ hashFiles('pdm.lock') }}

- name: Install the project dependencies
run: pdm install -d

- name: Build the project
run: pdm build
- name: Run the automated tests (for example)

- name: Run the Unit tests
run: pdm run test -- -v
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release

on:
push:
tags:
- "*"

jobs:
release:
runs-on: ubuntu-latest
permissions:
# This permission is needed for private repositories.
contents: read
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PDM
uses: pdm-project/setup-pdm@v4

- name: Build & Publish package to PyPI
run: pdm publish
53 changes: 39 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

[project]
name = "tcgdex-sdk"
version = "0.10.0"
# version = "0.0.0"
dynamic = ["version"]
description = ""
authors = [{ name = "Avior", email = "git@avior.me" }, { name = "HellLord77" }]
dependencies = ["dacite>=1.8.1"]
Expand All @@ -10,17 +11,17 @@ readme = "README.md"
license = { text = "MIT" }
maintainers = [{ name = "Avior", email = "git@avior.me" }]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
]

[project.urls]
Expand All @@ -34,6 +35,9 @@ documentation = "https://tcgdex.dev"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

#######
# PDM #
#######
[tool.pdm]
distribution = true

Expand All @@ -48,13 +52,34 @@ test = "python -m unittest discover -s tests"
[tool.pdm.build]
includes = ["src/tcgdexsdk"]

# [tool.pdm.version]
# source = "scm"
# fallback_version = "0.0.0"
# write_to = "tcgdexsdk/version.py"
# write_template = "__version__ = '{}'"

[tool.pdm.version]
source = "file"
path = "src/tcgdexsdk/__init__.py"

########
# Ruff #
########
[tool.ruff]
line-length = 120
# exclude = ["build/", "docs/"]
line-length = 80
respect-gitignore = true
include = ["src/**/*.py"]

[tool.ruff.lint]
select = ["E", "F", "UP", "B", "SIM", "I"]

[tool.ruff.format]
docstring-code-format = true
line-ending = "lf"

###########
# Pyright #
###########
[tool.pyright]
exclude = [".venv"]
venvPath = "."
Expand Down
14 changes: 10 additions & 4 deletions scripts/load_version.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""
Load the current version into the project
Load the current version into the project
"""

import toml
import re
import subprocess

import toml


def run_command(command):
"""
run a command on the system
"""
return subprocess.run(command, stdout=subprocess.PIPE, text=True).stdout


# Load the pyproject.toml file
pyproject = toml.load("pyproject.toml")

Expand All @@ -24,13 +27,16 @@ def run_command(command):
if version == "":
version = pyproject["project"]["version"]


# replace in file
with open("src/tcgdexsdk/__init__.py", 'r+') as file:
with open("src/tcgdexsdk/__init__.py", "r+") as file:
content = file.read()
file.seek(0)

# Use a regex to replace the existing __version__ variable
new_content = re.sub(r'__version__ = ".*?"', f'__version__ = "{version}"', content)
new_content = re.sub(
r'__version__ = ".*?"', f'__version__ = "{version.strip()}"', content
)

file.write(new_content)
file.truncate()
12 changes: 6 additions & 6 deletions src/tcgdexsdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from tcgdexsdk.tcgdex import TCGdex
# Do no edit, set automatically on build (Also on top so it can be used by the code)
__version__ = "0.1.0"

from tcgdexsdk.endpoints.Endpoint import Endpoint
from tcgdexsdk.enums import Language
from tcgdexsdk.models.CardResume import CardResume
from tcgdexsdk.models.Card import Card
from tcgdexsdk.models.CardResume import CardResume
from tcgdexsdk.models.Serie import Serie
from tcgdexsdk.models.SerieResume import SerieResume
from tcgdexsdk.models.Set import Set
from tcgdexsdk.models.SetResume import SetResume
from tcgdexsdk.models.StringEndpoint import StringEndpoint
from tcgdexsdk.tcgdex import TCGdex

__all__ = [
"TCGdex",
Expand All @@ -19,8 +22,5 @@
"SerieResume",
"Set",
"SetResume",
"StringEndpoint"
"StringEndpoint",
]

# Do no edit, set automatically on build
__version__ = "0.10.0"
1 change: 1 addition & 0 deletions src/tcgdexsdk/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Todo when min is 3.11
# Move to StringEnum and auto


class Language(Enum):
EN = "en"
"""English"""
Expand Down
9 changes: 8 additions & 1 deletion src/tcgdexsdk/models/Card.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from tcgdexsdk.enums import Extension, Quality
from tcgdexsdk.models.Model import Model
from tcgdexsdk.models.SetResume import SetResume
from tcgdexsdk.models.subs import CardAbility, CardAttack, CardItem, CardVariants, CardWeakRes, Legal
from tcgdexsdk.models.subs import (
CardAbility,
CardAttack,
CardItem,
CardVariants,
CardWeakRes,
Legal,
)


@dataclass
Expand Down
1 change: 1 addition & 0 deletions src/tcgdexsdk/models/CardResume.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tcgdexsdk.enums import Extension, Quality
from tcgdexsdk.models.Model import Model


@dataclass
class CardResume(Model):
"""Card Resume class, contains basic information about a specific card
Expand Down
8 changes: 2 additions & 6 deletions src/tcgdexsdk/models/IntEndpoint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from dataclasses import dataclass
from http.client import HTTPResponse
from typing import List, Optional, Union
from typing import List

from tcgdexsdk import utils
from tcgdexsdk.enums import Extension, Quality
from tcgdexsdk.models.Card import Card
from tcgdexsdk.models.CardResume import CardResume
from tcgdexsdk.models.Serie import Serie
from tcgdexsdk.models.Model import Model


@dataclass
class IntEndpoint(Model):
"""Generic class that handle a lot of Endpoints"""
Expand Down
3 changes: 2 additions & 1 deletion src/tcgdexsdk/models/Model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass, field
from typing import Any


@dataclass
class Model:
sdk: Any = field(init=False, default=None)
sdk: Any = field(init=False, default=None)
3 changes: 2 additions & 1 deletion src/tcgdexsdk/models/Serie.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from typing import List, Optional, Union

from tcgdexsdk import utils
from tcgdexsdk.enums import Extension, Quality
from tcgdexsdk.enums import Extension
from tcgdexsdk.models.Model import Model
from tcgdexsdk.models.SetResume import SetResume


@dataclass
class Serie(Model):
"""Pokémon TCG Serie"""
Expand Down
16 changes: 8 additions & 8 deletions src/tcgdexsdk/models/SerieResume.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import Optional, Union

from tcgdexsdk import utils
from tcgdexsdk.enums import Extension, Quality
from tcgdexsdk.models.Card import Card
from tcgdexsdk.models.Serie import Serie
from tcgdexsdk.enums import Extension
from tcgdexsdk.models.Model import Model
from tcgdexsdk.models.Serie import Serie


@dataclass
class SerieResume(Model):
Expand Down Expand Up @@ -38,8 +38,8 @@ def get_logo(self, format: Union[str, Extension]) -> Optional[HTTPResponse]:
return utils.download_image(url)

async def get_full_serie(self) -> Optional[Serie]:
"""
Get the full Card
@return: the full card if available
"""
return await self.sdk.serie.get(self.id)
"""
Get the full Card
@return: the full card if available
"""
return await self.sdk.serie.get(self.id)
11 changes: 6 additions & 5 deletions src/tcgdexsdk/models/Set.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from dataclasses import dataclass
from http.client import HTTPResponse
from typing import List, Optional
from typing_extensions import Union
from typing import List, Optional, Union

from tcgdexsdk import utils
from tcgdexsdk.enums import Extension, Quality
from tcgdexsdk.enums import Extension
from tcgdexsdk.models.CardResume import CardResume
from tcgdexsdk.models.Model import Model
from tcgdexsdk.models.SerieResume import SerieResume
from tcgdexsdk.models.subs import Legal, SetCardCountResume


@dataclass
class Set(Model):
"""Pokémon TCG Set class"""
Expand All @@ -25,7 +25,6 @@ class Set(Model):
cardCount: SetCardCountResume
"""the number of card in the set"""


serie: SerieResume
"""the serie this set is a part of"""
tcgOnline: Optional[str]
Expand Down Expand Up @@ -64,7 +63,9 @@ def get_symbol_url(self, extension: Union[str, Extension]) -> Optional[str]:
if self.symbol:
return f"{self.symbol}.{extension}"

def get_symbol(self, format: Union[str, Extension]) -> Optional[HTTPResponse]:
def get_symbol(
self, format: Union[str, Extension]
) -> Optional[HTTPResponse]:
"""
Get the symbol buffer
@param format: the image format
Expand Down
7 changes: 5 additions & 2 deletions src/tcgdexsdk/models/SetResume.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from typing import Optional, Union

from tcgdexsdk import utils
from tcgdexsdk.enums import Extension, Quality
from tcgdexsdk.enums import Extension
from tcgdexsdk.models.Model import Model
from tcgdexsdk.models.subs import SetCardCountResume


@dataclass
class SetResume(Model):
"""Set resume"""
Expand Down Expand Up @@ -51,7 +52,9 @@ def get_symbol_url(self, extension: Union[str, Extension]) -> Optional[str]:
return f"{self.symbol}.{extension}"

# noinspection PyShadowingBuiltins
def get_symbol(self, format: Union[str, Extension]) -> Optional[HTTPResponse]:
def get_symbol(
self, format: Union[str, Extension]
) -> Optional[HTTPResponse]:
"""
Get the symbol buffer
@param format: the image format
Expand Down
8 changes: 2 additions & 6 deletions src/tcgdexsdk/models/StringEndpoint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from dataclasses import dataclass
from http.client import HTTPResponse
from typing import List, Optional, Union
from typing import List

from tcgdexsdk import utils
from tcgdexsdk.enums import Extension, Quality
from tcgdexsdk.models.Card import Card
from tcgdexsdk.models.CardResume import CardResume
from tcgdexsdk.models.Serie import Serie
from tcgdexsdk.models.Model import Model


@dataclass
class StringEndpoint(Model):
"""Generic class that handle a lot of Endpoints"""
Expand Down
Loading

0 comments on commit 299a00a

Please sign in to comment.