Skip to content

Commit

Permalink
feat(env): adaptive version
Browse files Browse the repository at this point in the history
Signed-off-by: Rongrong <[email protected]>
  • Loading branch information
Rongronggg9 committed Apr 2, 2022
1 parent 5d07a75 commit 4f436ad
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from python_socks import parse_proxy_url
from dotenv import load_dotenv
from pathlib import Path
from distutils.version import StrictVersion

from .version import __version__

Expand Down Expand Up @@ -113,11 +114,18 @@ def __list_parser(var: Optional[str]) -> list[str]:
else:
_version = 'dirty'

if not re.match(r'v?\d+\.\d+(\.\d+)?', _version):
_version = 'v' + (__version__ + '-' + _version if not _version == 'dirty' else __version__)
_version_match = re.match(r'^v?\d+\.\d+(\.\w+(\.\w+)?)?', _version)
if _version_match:
try:
if StrictVersion(_version_match.group(0).lstrip('v')) <= StrictVersion(__version__):
_version = _version[_version_match.end():]
_version = re.sub(r'-\d+-', '', _version)
except ValueError:
_version = 'dirty'
_version = 'v' + __version__ + ('-' + _version if not _version == 'dirty' else '')

VERSION: Final = _version
del _version
del _version, _version_match

# ----- basic config -----
SAMPLE_APIS: Final = {
Expand Down

0 comments on commit 4f436ad

Please sign in to comment.