Skip to content

Commit

Permalink
fix: Store version as plain text file to simplify bumping (#636)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Replaced `VERSION` in tuple format by `__version__` as a string
  • Loading branch information
last-partizan committed May 14, 2022
1 parent 155445f commit 6b4bb73
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 190 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/github-actions.yml
Expand Up @@ -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:
Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions .versionrc.json
Expand Up @@ -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"
}
]
}
25 changes: 0 additions & 25 deletions PKG-INFO

This file was deleted.

22 changes: 5 additions & 17 deletions docs/modeltranslation/conf.py
@@ -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.
#
Expand All @@ -22,23 +20,13 @@
# 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'
Expand Down
15 changes: 0 additions & 15 deletions modeltranslation-version-updater.js

This file was deleted.

1 change: 1 addition & 0 deletions modeltranslation/VERSION
@@ -0,0 +1 @@
0.17.7
70 changes: 2 additions & 68 deletions modeltranslation/__init__.py
@@ -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')
9 changes: 0 additions & 9 deletions pkg-info-updater.js

This file was deleted.

35 changes: 35 additions & 0 deletions setup.cfg
@@ -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
53 changes: 4 additions & 49 deletions setup.py
@@ -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()

0 comments on commit 6b4bb73

Please sign in to comment.