Skip to content

Commit

Permalink
Fix #2960: Generate PEP-440 compatible devbuild version for setuptools (
Browse files Browse the repository at this point in the history
#2961)

* get_git_version: Only match official 20xx.y release tags

Previously, you'd get results such as `2019-dev-154-gc2f4d607b` due to
the most recent tag being `2019-dev` (otherwise unversioned).

* setup.py: Replace deprecated `distro.linux_distribution` call with `distro.id`

As per https://distro.readthedocs.io/en/latest/#distro.id

Return the distro ID of the current distribution, as a machine-readable string.

For a number of OS distributions, the returned distro ID value is reliable, in the sense
that it is documented and that it does not change across releases of the distribution.

This package maintains the following reliable distro ID values:

Distro ID	Distribution
“ubuntu”	Ubuntu
“debian”	Debian
“rhel”		RedHat Enterprise Linux
“centos”	CentOS
“fedora”	Fedora
“sles”		SUSE Linux Enterprise Server
“opensuse”	openSUSE
“amazon”	Amazon Linux
“arch”		Arch Linux
“cloudlinux”	CloudLinux OS
“exherbo”	Exherbo Linux
“gentoo”	GenToo Linux
“ibm_powerkvm”	IBM PowerKVM
“kvmibm”	KVM for IBM z Systems
“linuxmint”	Linux Mint
“mageia”	Mageia
“mandriva”	Mandriva Linux
“parallels”	Parallels
“pidora”	Pidora
“raspbian”	Raspbian
“oracle”	Oracle Linux (and Oracle Enterprise Linux)
“scientific”	Scientific Linux
“slackware”	Slackware
“xenserver”	XenServer
“openbsd”	OpenBSD
“netbsd”	NetBSD
“freebsd”	FreeBSD

* setup.py: Fix indentation

* setup.py: Convert `git describe`-based version to PEP-440-compliant one

For setuptools installation purposes, anyhow. Ingame UI still supposed
to display the full dev-version identifier including git hash.
  • Loading branch information
ChrisOelmueller committed Jun 14, 2023
1 parent c2f4d60 commit 50397fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
5 changes: 2 additions & 3 deletions horizons/constants.py
Expand Up @@ -55,9 +55,8 @@ def get_git_version():
git = "git.exe"

# Note that this uses glob patterns, not regular expressions.
# TAG_STRUCTURE = "20[0-9][0-9].[0-9]*"
# describe = [git, "describe", "--tags", TAG_STRUCTURE]
describe = [git, "describe", "--tags"]
TAG_STRUCTURE = "20[0-9][0-9].[0-9]*"
describe = [git, "describe", "--tags", "--match", TAG_STRUCTURE]
git_string = subprocess.check_output(describe, cwd=uh_path, universal_newlines=True).rstrip('\n')
return git_string
except (subprocess.CalledProcessError, RuntimeError):
Expand Down
34 changes: 22 additions & 12 deletions setup.py
Expand Up @@ -26,6 +26,7 @@
import json
import os
import platform
import re
import sys
from distutils.command.build import build
from distutils.core import setup
Expand All @@ -41,7 +42,7 @@
# Ensure we are in the correct directory
os.chdir(os.path.realpath(os.path.dirname(__file__)))

if distro.linux_distribution(full_distribution_name=False)[0] in ('debian', 'mint', 'ubuntu'):
if distro.id() in ('debian', 'linuxmint', 'ubuntu'):
executable_path = 'games'
else:
executable_path = 'bin'
Expand Down Expand Up @@ -236,20 +237,29 @@ def run(self):
build.sub_commands.append(('build_i18n', None))

cmdclass = {
'build_i18n': _build_i18n,
'build_i18n': _build_i18n,
}


def _get_pep440_compliant_version(git_describe_output):
pattern = r'(20[\d]{2}\.[\d]+)(?:-([\d]+)-g[0-f]+)?'
if '-g' in git_describe_output:
return re.sub(pattern, r'\1.dev\2', git_describe_output) # git revision count since tag
else:
return re.sub(pattern, r'\1', git_describe_output) # just the tag itself, no suffix


setup(
name='UnknownHorizons',
version=VERSION.RELEASE_VERSION,
description='Realtime Economy Simulation and Strategy Game',
author='The Unknown Horizons Team',
author_email='team@unknown-horizons.org',
url='http://www.unknown-horizons.org',
packages=packages,
package_data=package_data,
data_files=data,
cmdclass=cmdclass)
name='UnknownHorizons',
version=_get_pep440_compliant_version(VERSION.RELEASE_VERSION),
description='Realtime Economy Simulation and Strategy Game',
author='The Unknown Horizons Team',
author_email='team@unknown-horizons.org',
url='http://www.unknown-horizons.org',
packages=packages,
package_data=package_data,
data_files=data,
cmdclass=cmdclass)

# after installation remove gitversion.txt
if os.path.exists('.git'):
Expand Down

0 comments on commit 50397fa

Please sign in to comment.