build: avoid version parse when uploading release

This commit is contained in:
Lance Edgar 2024-06-14 18:02:39 -05:00
parent ab4dbbedf0
commit da4450b574

View file

@ -25,26 +25,11 @@ Tasks for Tailbone
""" """
import os import os
import re
import shutil import shutil
from invoke import task 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 @task
def release(c, tests=False): def release(c, tests=False):
""" """
@ -53,7 +38,9 @@ def release(c, tests=False):
if tests: if tests:
c.run('tox') c.run('tox')
if os.path.exists('dist'):
shutil.rmtree('dist')
if os.path.exists('Tailbone.egg-info'): if os.path.exists('Tailbone.egg-info'):
shutil.rmtree('Tailbone.egg-info') shutil.rmtree('Tailbone.egg-info')
c.run('python -m build --sdist') c.run('python -m build --sdist')
c.run(f'twine upload dist/tailbone-{__version__}.tar.gz') c.run('twine upload dist/*')