fix: Store version as plain text file to simplify bumping (#636)

BREAKING CHANGE: Replaced `VERSION` in tuple format by `__version__` as a string
This commit is contained in:
Serhii Tereshchenko 2022-05-14 11:11:07 +03:00 committed by GitHub
parent 155445f1a7
commit 6b4bb733d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 67 additions and 190 deletions

View file

@ -26,6 +26,23 @@ jobs:
run: |
flake8 modeltranslation
black --check modeltranslation *.py
Install:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install package
run: |
python -m pip install --upgrade pip
pip install .
Test:
runs-on: ubuntu-latest
strategy:
@ -81,7 +98,7 @@ jobs:
if [[ $DB == postgres ]]; then
pip install -q psycopg2-binary
fi
pip install Pillow coverage six $(./get-django-version.py ${{ matrix.django }})
pip install coverage six $(./get-django-version.py ${{ matrix.django }})
- name: Run tests
run: |
coverage run --source=modeltranslation ./runtests.py

View file

@ -4,12 +4,8 @@
"repository": "django-modeltranslation",
"bumpFiles": [
{
"filename": "PKG-INFO",
"updater": "pkg-info-updater.js"
},
{
"filename": "modeltranslation/__init__.py",
"updater": "modeltranslation-version-updater.js"
"filename": "modeltranslation/VERSION",
"type": "plain-text"
}
]
}

View file

@ -1,25 +0,0 @@
Metadata-Version: 1.0
Name: django-modeltranslation
Version: 0.17.7
Summary: Translates Django models using a registration approach.
Home-page: https://github.com/deschler/django-modeltranslation
Author: Peter Eschler,
Dirk Eschler,
Jacek Tomaszewski
Author-email: "Peter Eschler" <peschler@gmail.com>,
"Dirk Eschler" <eschler@gmail.com>,
"Jacek Tomaszewski" <jacek.tomek@gmail.com>
License: New BSD
Description: The modeltranslation application can be used to translate dynamic
content of existing Django models to an arbitrary number of
languages without having to change the original model classes. It
uses a registration approach (comparable to Django's admin app) to
be able to add translations to existing or new projects and is
fully integrated into the Django admin backend.
The advantage of a registration approach is the ability to add
translations to models on a per-project basis. You can use the
same app in different projects, may they use translations or not,
and you never have to touch the original model class.
Platform: UNKNOWN
Keywords: django translation i18n

View file

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# django-modeltranslation documentation build configuration file, created by
# sphinx-quickstart on Wed Oct 17 10:26:58 2012.
#
@ -22,23 +20,13 @@ try:
# The version info for the project you're documenting, acts as replacement
# for |version| and |release|, also used in various other places throughout
# the built documents.
#
# The short X.Y version (e.g.'0.5').
version = '.'.join(str(i) for i in modeltranslation.VERSION[:2])
# The full PEP386-compliant version number version, including
# normalized alpha/beta/rc/dev tags (e.g. '0.5a1').
try:
# FIXME: Can we make this work on services like read-the-docs?
# The build script on rtf bails out early with:
#
# Failed to import project; skipping build.
# Please make sure your repo is correct and you have a conf.py
#
release = modeltranslation.get_version()
except:
# We are broad here with the exception handling because we don't know
# the environment we build on.
release = version
release = modeltranslation.__version__
# The short X.Y version (e.g.'0.5').
version = '.'.join(i for i in release.split('.')[:2])
except ImportError:
version = 'dev'
release = 'dev'

View file

@ -1,15 +0,0 @@
const VERSION_REGEX = /^VERSION = \((?<major>\d+), (?<minor>\d+), (?<patch>\d+), '(?<tag>\w+)', (?<tagVer>\d+)\)$/m;
const NEW_VERSION_REGEX = /(?<major>\d+).(?<minor>\d+).(?<patch>\d+)(-(?<tag>\w+).(?<tagVer>\d+))?/;
module.exports.readVersion = function (contents) {
let v = contents.match(VERSION_REGEX).groups;
let version = `${v.major}.${v.minor}.${v.patch}`;
if (v.tag == "final")
return version;
return version + `-${v.tag}.${v.tagVer}`;
}
module.exports.writeVersion = function (contents, version) {
let v = version.match(NEW_VERSION_REGEX).groups;
return contents.replace(VERSION_REGEX, `VERSION = (${v.major}, ${v.minor}, ${v.patch}, '${v.tag || 'final'}', ${v.tagVer || 0})`);
}

1
modeltranslation/VERSION Normal file
View file

@ -0,0 +1 @@
0.17.7

View file

@ -1,71 +1,5 @@
# -*- coding: utf-8 -*-
"""
Version code adopted from Django development version.
https://github.com/django/django
"""
from pathlib import Path
VERSION = (0, 17, 7, 'final', 0)
__version__ = (Path(__file__).parent / "VERSION").open().read().strip()
default_app_config = 'modeltranslation.apps.ModeltranslationConfig'
def get_version(version=None):
"""
Returns a PEP 386-compliant version number from VERSION.
"""
if version is None:
from modeltranslation import VERSION as version
else:
assert len(version) == 5
assert version[3] in ('alpha', 'beta', 'rc', 'final')
# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|c}N - for alpha, beta and rc releases
parts = 2 if version[2] == 0 else 3
main = '.'.join(str(x) for x in version[:parts])
sub = ''
if version[3] == 'alpha' and version[4] == 0:
git_changeset = get_git_changeset()
if git_changeset:
sub = '.dev%s' % git_changeset
elif version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}
sub = mapping[version[3]] + str(version[4])
return str(main + sub)
def get_git_changeset():
"""
Returns a numeric identifier of the latest git changeset.
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers.
TODO: Check if we can rely on services like read-the-docs to pick this up.
"""
import datetime
import os
import subprocess
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
git_log = subprocess.Popen(
'git log --pretty=format:%ct --quiet -1 HEAD',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
cwd=repo_dir,
universal_newlines=True,
)
timestamp = git_log.communicate()[0]
try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError:
return None
return timestamp.strftime('%Y%m%d%H%M%S')

View file

@ -1,9 +0,0 @@
const VERSION_REGEX = /^Version: (.*)$/m;
module.exports.readVersion = function (contents) {
return contents.match(VERSION_REGEX)[1];
}
module.exports.writeVersion = function (contents, version) {
return contents.replace(VERSION_REGEX, `Version: ${version}`);
}

35
setup.cfg Normal file
View file

@ -0,0 +1,35 @@
[metadata]
name = django-modeltranslation
version = attr:modeltranslation.__version__
description = Translates Django models using a registration approach.
long_description = file:README.rst
long_description_content_type = text/x-rst
author = Peter Eschler
author_email = peschler@gmail.com
maintainer = Sergiy Tereshchenko
maintainer_email = serg.partizan+modeltranslation@gmail.com
url = https://github.com/deschler/django-modeltranslation
classifiers =
Programming Language :: Python
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Operating System :: OS Independent
Environment :: Web Environment
Intended Audience :: Developers
Framework :: Django
License :: OSI Approved :: BSD License
license = New BSD
[options]
install_requires =
Django>=2.2
six
packages =
modeltranslation
modeltranslation.management
modeltranslation.management.commands
[options.package_data]
modeltranslation =
static/modeltranslation/css/*.css
static/modeltranslation/js/*.js

View file

@ -1,53 +1,8 @@
#!/usr/bin/env python
import pkg_resources
from setuptools import setup
# Dynamically calculate the version based on modeltranslation.VERSION.
version = __import__('modeltranslation').get_version()
# (1) check required versions (from https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108)
pkg_resources.require("setuptools>=39.2")
setup(
name='django-modeltranslation',
version=version,
description='Translates Django models using a registration approach.',
long_description=(
'The modeltranslation application can be used to translate dynamic '
'content of existing models to an arbitrary number of languages '
'without having to change the original model classes. It uses a '
'registration approach (comparable to Django\'s admin app) to be able '
'to add translations to existing or new projects and is fully '
'integrated into the Django admin backend.'
),
author='Peter Eschler',
author_email='peschler@gmail.com',
maintainer='Dirk Eschler',
maintainer_email='eschler@gmail.com',
url='https://github.com/deschler/django-modeltranslation',
packages=[
'modeltranslation',
'modeltranslation.management',
'modeltranslation.management.commands',
],
package_data={
'modeltranslation': [
'static/modeltranslation/css/*.css',
'static/modeltranslation/js/*.js',
]
},
install_requires=['Django>=2.2', 'six'],
download_url=(
'https://github.com/deschler/django-modeltranslation/archive/%s.tar.gz' % version
),
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Operating System :: OS Independent',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Framework :: Django',
'License :: OSI Approved :: BSD License',
],
license='New BSD',
)
setup()