Skip to content

Commit

Permalink
Copy get_version implementation from Wagtail
Browse files Browse the repository at this point in the history
  • Loading branch information
kaedroho committed Jun 17, 2021
1 parent 188da75 commit 7a788b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion wagtail_localize/__init__.py
@@ -1,4 +1,4 @@
from wagtail.utils.version import get_version
from .version import get_version


default_app_config = 'wagtail_localize.apps.WagtailLocalizeAppConfig'
Expand Down
42 changes: 42 additions & 0 deletions wagtail_localize/version.py
@@ -0,0 +1,42 @@

# This file is heavily inspired by django.utils.version


def get_version(version):
"""Return a PEP 440-compliant version number from VERSION."""
version = get_complete_version(version)

# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|rc}N - for alpha, beta, and rc releases

main = get_main_version(version)

sub = ''
if version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc', 'dev': '.dev'}
sub = mapping[version[3]] + str(version[4])

return main + sub


def get_main_version(version=None):
"""Return main version (X.Y[.Z]) from VERSION."""
version = get_complete_version(version)
parts = 2 if version[2] == 0 else 3
return '.'.join(str(x) for x in version[:parts])


def get_complete_version(version=None):
"""
Return a tuple of the Wagtail version. If version argument is non-empty,
check for correctness of the tuple provided.
"""
if version is None:
from wagtail import VERSION as version
else:
assert len(version) == 5
assert version[3] in ('dev', 'alpha', 'beta', 'rc', 'final')

return version

0 comments on commit 7a788b3

Please sign in to comment.