build: avoid version parse when uploading release

This commit is contained in:
Lance Edgar 2024-06-14 18:00:04 -05:00
parent 4adabe3261
commit 5b0410b252

View file

@ -25,26 +25,11 @@ Tasks for 'rattail' package
"""
import os
import re
import shutil
from invoke import task
here = os.path.abspath(os.path.dirname(__file__))
__version__ = None
pattern = re.compile(r'^version = "(\d+\.\d+\.\d+)"$')
with open(os.path.join(here, 'pyproject.toml'), 'rt') as f:
for line in f:
line = line.rstrip('\n')
match = pattern.match(line)
if match:
__version__ = match.group(1)
break
if not __version__:
raise RuntimeError("could not parse version!")
@task
def release(c, tests=False):
"""
@ -53,8 +38,10 @@ def release(c, tests=False):
if tests:
c.run('tox')
if os.path.exists('dist'):
shutil.rmtree('dist')
if os.path.exists('rattail.egg-info'):
shutil.rmtree('rattail.egg-info')
c.run('python -m build --sdist')
c.run('twine upload dist/rattail-{}.tar.gz'.format(__version__))
c.run('twine upload dist/*')