(3.1.0)
Some checks failed
Actions / Build (push) Failing after 19s
Actions / Lint with Ruff, Pylint, & MyPy (push) Successful in 22s
Actions / Build Documentation (push) Successful in 25s

- improved version logic - now using hatch and hatch-vcs to automatically generate versions based on git tag / git commit / distance from last tag
- raise an error if the voices cache is not populated correctly
- lint with mypy in actions
- use pyproject.toml for pylint configuration
This commit is contained in:
Seaswimmer 2024-11-15 11:14:33 -05:00
parent a7113babb7
commit c4205fc4f1
Signed by: cswimr
GPG key ID: A9C162E867C851FA
10 changed files with 66 additions and 28 deletions

View file

@ -45,7 +45,7 @@ jobs:
password: ${{ secrets.PYPI_API_TOKEN }}
lint:
name: Lint with Ruff & Pylint
name: Lint with Ruff, Pylint, & MyPy
runs-on: docker
container: www.coastalcommits.com/cswimr/actions:uv
steps:
@ -65,7 +65,16 @@ jobs:
continue-on-error: true
- name: Analysing code with Pylint
run: uv run pylint --rcfile=.forgejo/workflows/config/.pylintrc $(git ls-files '*.py')
run: uv run pylint $(git ls-files '*.py')
continue-on-error: true
- name: Type checking with MyPy
run: uv run mypy $(git ls-files '*.py')
continue-on-error: true
- name: Running tests # this will be moved to a separate job once I actually migrate to a dedicated test suite
run: uv run tests/tests.py
docs:
name: Build Documentation

View file

@ -1,6 +0,0 @@
[MESSAGES CONTROL]
disable=
line-too-long,
missing-module-docstring,
too-many-arguments,
too-few-public-methods,

3
.gitignore vendored
View file

@ -167,3 +167,6 @@ test.mp3
# actions artifacts
1/
# automatically generated version file
pyflowery/version.py

View file

@ -7,7 +7,7 @@ from pyflowery.exceptions import (
)
from pyflowery.models import FloweryAPIConfig, Language, Result, Voice
from pyflowery.pyflowery import FloweryAPI
from pyflowery.version import VERSION
from pyflowery.version import __version__
__all__ = [
"FloweryAPI",
@ -15,7 +15,7 @@ __all__ = [
"Language",
"Result",
"Voice",
"VERSION",
"__version__",
"ResponseError",
"ClientError",
"InternalServerError",

View file

@ -3,7 +3,7 @@ from logging import Logger, getLogger
from sys import version as pyversion
from typing import Dict, List, Union
from pyflowery.version import VERSION
from pyflowery.version import version
@dataclass
@ -79,4 +79,4 @@ class FloweryAPIConfig:
@property
def prepended_user_agent(self) -> str:
"""Return the user_agent with the PyFlowery module version prepended"""
return f"PyFlowery/{VERSION} {self.user_agent} (Python {pyversion})"
return f"PyFlowery/{version} {self.user_agent} (Python {pyversion})"

View file

@ -31,10 +31,9 @@ class FloweryAPI:
async def _populate_voices_cache(self) -> None:
"""Populate the voices cache. This method is called automatically when the FloweryAPI object is created, and should not be called directly."""
self._voices_cache = tuple([voice async for voice in self.fetch_voices()]) # pylint: disable=consider-using-generator
if self._voices_cache == ():
if not self._voices_cache:
raise ValueError("Failed to populate voices cache! Please report this issue at https://www.coastalcommits.com/cswimr/PyFlowery/issues.")
else:
self.config.logger.info("Voices cache populated!")
self.config.logger.info("Voices cache populated!")
def get_voices(self, voice_id: str | None = None, name: str | None = None) -> Tuple[Voice, ...] | None:
"""Get a set of voices from the cache.
@ -150,7 +149,5 @@ class FloweryAPI:
if request is not None:
if isinstance(request.data, bytes):
return request.data
else:
raise ResponseError(f"Invalid response from Flowery API: {request.data!r}")
else:
raise ResponseError("Invalid response from Flowery API: Empty Response!}")
raise ResponseError(f"Invalid response from Flowery API: {request.data!r}")
raise ResponseError("Invalid response from Flowery API: Empty Response!}")

View file

@ -1 +1,16 @@
VERSION = "3.0.1"
# file generated by setuptools_scm
# don't change, don't track in version control
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Tuple, Union
VERSION_TUPLE = Tuple[Union[int, str], ...]
else:
VERSION_TUPLE = object
version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE
__version__ = version = '3.0.2.dev0+ga7113ba.d20241115'
__version_tuple__ = version_tuple = (3, 0, 2, 'dev0', 'ga7113ba.d20241115')

View file

@ -1,6 +1,5 @@
[project]
name = "pyflowery"
version = "3.0.1"
description = "A Python API wrapper for the Flowery API"
readme = "README.md"
requires-python = "<4.0,>=3.11"
@ -16,6 +15,7 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dynamic = ["version", "urls"]
[dependency-groups]
dev = [
@ -35,6 +35,26 @@ docs = [
[tool.ruff]
line-length = 160
[tool.pylint]
max-line-length = 200
disable = [
"missing-module-docstring",
"too-many-arguments",
"too-many-positional-arguments",
"too-few-public-methods",
]
[tool.hatch.version]
source = "vcs"
[tool.hatch.build.hooks.vcs]
version-file = "pyflowery/version.py"
[tool.hatch.metadata.hooks.vcs.urls]
Homepage = "https://www.coastalcommits.com/cswimr/PyFlowery"
Issues = "https://www.coastalcommits.com/cswimr/PyFlowery/issues"
source_archive = "https://www.coastalcommits.com/cswimr/PyFlowery/archive/{commit_hash}.tar.gz"
[build-system]
requires = ["hatchling"]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

View file

@ -2,7 +2,7 @@ import asyncio
import logging
import sys
from pyflowery import VERSION, FloweryAPI, FloweryAPIConfig
from pyflowery import FloweryAPI, FloweryAPIConfig, __version__
root = logging.getLogger()
root.setLevel(level=logging.DEBUG)
@ -13,7 +13,7 @@ formatter = logging.Formatter(fmt="%(asctime)s - %(name)s - %(levelname)s - %(me
handler.setFormatter(fmt=formatter)
root.addHandler(hdlr=handler)
api = FloweryAPI(config=FloweryAPIConfig(user_agent=f"PyFloweryTests/{VERSION}"))
api = FloweryAPI(config=FloweryAPIConfig(user_agent=f"PyFloweryTests/{__version__}"))
ALEXANDER = "fa3ea565-121f-5efd-b4e9-59895c77df23" # TikTok
JACOB = "38f45366-68e8-5d39-b1ef-3fd4eeb61cdb" # Microsoft Azure

View file

@ -754,11 +754,11 @@ wheels = [
[[package]]
name = "packaging"
version = "24.1"
version = "24.2"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/51/65/50db4dda066951078f0a96cf12f4b9ada6e4b811516bf0262c0f4f7064d4/packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002", size = 148788 }
sdist = { url = "https://files.pythonhosted.org/packages/d0/63/68dbb6eb2de9cb10ee4c9c14a0148804425e13c4fb20d61cce69f53106da/packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f", size = 163950 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl", hash = "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124", size = 53985 },
{ url = "https://files.pythonhosted.org/packages/88/ef/eb23f262cca3c0c4eb7ab1933c3b1f03d021f2c48f54763065b6f0e321be/packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759", size = 65451 },
]
[[package]]
@ -897,7 +897,7 @@ wheels = [
[[package]]
name = "pyflowery"
version = "3.0.0"
version = "3.0.2.dev0+ga7113ba.d20241115"
source = { editable = "." }
dependencies = [
{ name = "aiohttp" },