Skip to content

Commit

Permalink
Publish on PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
brofi committed May 4, 2024
1 parent 1424e81 commit c29fb76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ build = [
"pytest-asyncio >= 0.23.6",
"respx >= 0.21.1",
"tomlkit >= 0.12.4",
"twine >= 5.0.0",
]

[project.scripts]
Expand Down
39 changes: 37 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from collections.abc import Callable
from pathlib import Path
from shutil import rmtree
from typing import Any
from typing import Any, Final

from invoke import Collection, Context, Result, task

Expand All @@ -36,6 +36,14 @@
else:
LoggingConf = _LoggingConf

try:
# noinspection PyUnresolvedReferences
from coh2_live_stats.version import version_tuple as _version_tuple
except ImportError:
version_tuple = None
else:
version_tuple = _version_tuple

try:
# noinspection PyUnresolvedReferences
from scripts import settings_generator as _settings_generator
Expand All @@ -55,6 +63,8 @@

Package = dict[str, str]

_VERSION_LEN: Final[int] = 3

_pkg = 'coh2_live_stats'
_pycmd = [sys.executable, '-m']
_pipcmd = [*_pycmd, 'pip', '--isolated', '--require-virtualenv']
Expand Down Expand Up @@ -223,4 +233,29 @@ def install(c: Context, *, normal_mode: bool = False, dev: bool = False) -> bool
return installed


namespace = Collection(check, build, install)
@task
def publish(c: Context) -> None:
"""Upload package to PyPI."""
if version_tuple is None:
LOG.error('Package coh2_live_stats not installed.')
return
if len(version_tuple) != _VERSION_LEN or not all(
isinstance(x, int) for x in version_tuple[:_VERSION_LEN]
):
LOG.error("Don't publish development versions.")
return

base = f'coh2_live_stats-{'.'.join(map(str, version_tuple))}'
dist_files = [
str(Path(_dist_dir).joinpath(f'{base}.tar.gz')),
str(next(Path(_dist_dir).glob(f'{base}*.whl'))),
]

if not _success(_run(c, *_pycmd, 'twine', 'check', *dist_files)):
LOG.error('Twine failed to check distribution files.')
return

_run(c, *_pycmd, 'twine', 'upload', *dist_files, hide=False)


namespace = Collection(check, build, install, publish)

0 comments on commit c29fb76

Please sign in to comment.