diff --git a/.gitignore b/.gitignore index 4fb3e92..3722934 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ /target/ __pycache__/ _build/ +src/euscan/_version.py diff --git a/bin/euscan b/bin/euscan index 30e96df..c70e686 100755 --- a/bin/euscan +++ b/bin/euscan @@ -11,7 +11,6 @@ import os __author__ = "Corentin Chary (iksaif)" __email__ = "corentin.chary@gmail.com" -__version__ = "git" __productname__ = "euscan" __description__ = "A tool to detect new upstream releases." @@ -32,6 +31,7 @@ from gentoolkit.errors import GentoolkitException from euscan import CONFIG, output from euscan.out import progress_bar +from euscan._version import __version__ # Globals diff --git a/pyproject.toml b/pyproject.toml index 5aa51d6..471fa7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools"] +requires = ["setuptools>=60","setuptools-scm>=8.0"] build-backend = "setuptools.build_meta" [project] @@ -24,3 +24,6 @@ homepage = "https://gitlab.com/src_prepare/euscan-ng" [tool.setuptools] script-files = ["bin/euscan"] + +[tool.setuptools_scm] +version_file = "src/euscan/_version.py" diff --git a/setup.py b/setup.py deleted file mode 100755 index 8eeb3b3..0000000 --- a/setup.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -from setuptools import setup, Command - -import io -import os -import re - - -__version__ = os.getenv('VERSION', default='9999') - -cwd = os.getcwd() - -# Load EPREFIX from Portage, fall back to the empty string if it fails -try: - from portage.const import EPREFIX -except ImportError: - EPREFIX = '' - -# Python files that need `__version__ = ""` subbed, relative to this dir: -python_scripts = [os.path.join(cwd, path) for path in ( - 'bin/euscan', -)] - - -class SetVersion(Command): - """Set python __version__ to our __version__.""" - description = "hardcode scripts' version using VERSION from environment" - user_options = [] # [(long_name, short_name, desc),] - - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - ver = 'git' if __version__ == '9999' else __version__ - print(("Settings version to %s" % ver)) - - def sub(files, pattern): - for f in files: - updated_file = [] - with io.open(f, 'r', 1, 'utf_8') as s: - for line in s: - newline = re.sub(pattern, '"%s"' % ver, line, 1) - if newline != line: - log.info("%s: %s" % (f, newline)) - updated_file.append(newline) - with io.open(f, 'w', 1, 'utf_8') as s: - s.writelines(updated_file) - quote = r'[\'"]{1}' - python_re = r'(?<=^__version__ = )' + quote + '[^\'"]*' + quote - sub(python_scripts, python_re) - -setup( - version=__version__, - cmdclass={ - 'set_version': SetVersion, - }, -) diff --git a/src/euscan/__init__.py b/src/euscan/__init__.py index 821759f..6990b06 100644 --- a/src/euscan/__init__.py +++ b/src/euscan/__init__.py @@ -3,8 +3,6 @@ # Copyright 2011 Corentin Chary # Distributed under the terms of the GNU General Public License v2 -__version__ = "git" - import configparser import os from ast import literal_eval