diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2025-08-15 17:48:21 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2025-08-15 21:46:37 +0100 |
commit | adcf25e7ba68d13f0ce3420d24fc91840b30e893 (patch) | |
tree | 5f62a0735aa2aa1f06438437dbe39cdd5ad7ebc2 | |
parent | 98e179c3bbbb6a5d10130eae5b97231b76cad7f7 (diff) | |
download | kutter-adcf25e7ba68d13f0ce3420d24fc91840b30e893.tar.gz kutter-adcf25e7ba68d13f0ce3420d24fc91840b30e893.tar.xz kutter-adcf25e7ba68d13f0ce3420d24fc91840b30e893.zip |
Remove git based version handling
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | klippy/klippy.py | 36 | ||||
-rw-r--r-- | klippy/util.py | 123 | ||||
-rw-r--r-- | scripts/buildcommands.py | 12 | ||||
-rwxr-xr-x | scripts/logextract.py | 10 | ||||
-rw-r--r-- | scripts/make_version.py | 31 |
7 files changed, 13 insertions, 204 deletions
@@ -3,4 +3,3 @@ out *.pyc .config .config.old -klippy/.version diff --git a/CHANGELOG.md b/CHANGELOG.md index 163fc3cf..4511186a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ Most changes are breaking. respective `c_helper.so` and `hub-ctrl`. * The config positional argument is now optional and defaults to `/etc/klipper.cfg` +* The version is now stored in `klippy/klippy.py` in `__version__` and is no + longer automatically retrieved from git or from `klippy/.version`. +* The version numbering has changed and versions are not compatible. ### Removed @@ -30,3 +33,4 @@ Most changes are breaking. * Install scripts * Uninstall script * Init script +* The `make_version.py` script diff --git a/klippy/klippy.py b/klippy/klippy.py index 17293af9..093b6619 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -8,6 +8,8 @@ import sys, os, gc, optparse, logging, time, collections, importlib import util, reactor, queuelogger, msgproto import gcode, configfile, pins, mcu, toolhead, webhooks +__version__ = "0.1.0-rc1" + message_ready = "Printer is ready" message_startup = """ @@ -367,44 +369,14 @@ def main(): else: logging.getLogger().setLevel(debuglevel) logging.info("Starting Klippy...") - git_info = util.get_git_version() - git_vers = git_info["version"] - extra_files = [ - fname - for code, fname in git_info["file_status"] - if ( - code in ("??", "!!") - and fname.endswith(".py") - and ( - fname.startswith("klippy/kinematics/") - or fname.startswith("klippy/extras/") - ) - ) - ] - modified_files = [fname for code, fname in git_info["file_status"] if code == "M"] - extra_git_desc = "" - if extra_files: - if not git_vers.endswith("-dirty"): - git_vers = git_vers + "-dirty" - if len(extra_files) > 10: - extra_files[10:] = ["(+%d files)" % (len(extra_files) - 10,)] - extra_git_desc += "\nUntracked files: %s" % (", ".join(extra_files),) - if modified_files: - if len(modified_files) > 10: - modified_files[10:] = ["(+%d files)" % (len(modified_files) - 10,)] - extra_git_desc += "\nModified files: %s" % (", ".join(modified_files),) - extra_git_desc += "\nBranch: %s" % (git_info["branch"]) - extra_git_desc += "\nRemote: %s" % (git_info["remote"]) - extra_git_desc += "\nTracked URL: %s" % (git_info["url"]) - start_args["software_version"] = git_vers + start_args["software_version"] = __version__ start_args["cpu_info"] = util.get_cpu_info() start_args["runtime_config"] = options.runtime_config if bglogger is not None: versions = "\n".join( [ "Args: %s" % (sys.argv,), - "Git version: %s%s" - % (repr(start_args["software_version"]), extra_git_desc), + "Version: %s" % (__version__,), "CPU: %s" % (start_args["cpu_info"],), "Python: %s" % (repr(sys.version),), ] diff --git a/klippy/util.py b/klippy/util.py index b43a7f1c..8ad8ccaa 100644 --- a/klippy/util.py +++ b/klippy/util.py @@ -4,7 +4,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import os, pty, fcntl, termios, signal, logging, json, time -import subprocess, traceback, shlex +import traceback ###################################################################### @@ -117,124 +117,3 @@ def get_cpu_info(): core_count = [k for k, v in lines].count("processor") model_name = dict(lines).get("model name", "?") return "%d core %s" % (core_count, model_name) - - -def get_version_from_file(klippy_src): - try: - with open(os.path.join(klippy_src, ".version")) as h: - return h.read().rstrip() - except IOError: - pass - return "?" - - -def _get_repo_info(gitdir): - repo_info = {"branch": "?", "remote": "?", "url": "?"} - prog_branch = ("git", "-C", gitdir, "branch", "--no-color") - try: - process = subprocess.Popen( - prog_branch, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - branch_list, err = process.communicate() - retcode = process.wait() - if retcode != 0: - logging.debug("Error running git branch: %s", err) - return repo_info - lines = str(branch_list.strip().decode()).split("\n") - for line in lines: - if line[0] == "*": - repo_info["branch"] = line[1:].strip() - break - else: - logging.debug("Unable to find current branch:\n%s", branch_list) - return repo_info - if repo_info["branch"].startswith("(HEAD detached"): - parts = repo_info["branch"].strip("()").split()[-1].split("/", 1) - if len(parts) != 2: - return repo_info - repo_info["remote"] = parts[0] - else: - key = "branch.%s.remote" % (repo_info["branch"],) - prog_config = ("git", "-C", gitdir, "config", "--get", key) - process = subprocess.Popen( - prog_config, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - remote_info, err = process.communicate() - retcode = process.wait() - if retcode != 0: - logging.debug("Error running git config: %s", err) - return repo_info - repo_info["remote"] = str(remote_info.strip().decode()) - prog_remote_url = ( - "git", - "-C", - gitdir, - "remote", - "get-url", - repo_info["remote"], - ) - process = subprocess.Popen( - prog_remote_url, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - remote_url, err = process.communicate() - retcode = process.wait() - if retcode != 0: - logging.debug("Error running git remote get-url: %s", err) - return repo_info - repo_info["url"] = str(remote_url.strip().decode()) - except: - logging.debug("Error fetching repo info: %s", traceback.format_exc()) - return repo_info - - -def get_git_version(from_file=True): - git_info = { - "version": "?", - "file_status": [], - "branch": "?", - "remote": "?", - "url": "?", - } - klippy_src = os.path.dirname(__file__) - - # Obtain version info from "git" program - gitdir = os.path.join(klippy_src, "..") - prog_desc = ( - "git", - "-C", - gitdir, - "describe", - "--always", - "--tags", - "--long", - "--dirty", - ) - prog_status = ("git", "-C", gitdir, "status", "--porcelain", "--ignored") - try: - process = subprocess.Popen( - prog_desc, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - ver, err = process.communicate() - retcode = process.wait() - if retcode == 0: - git_info["version"] = str(ver.strip().decode()) - process = subprocess.Popen( - prog_status, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - stat, err = process.communicate() - status = [l.split(None, 1) for l in str(stat.strip().decode()).split("\n")] - retcode = process.wait() - if retcode == 0: - git_info["file_status"] = status - else: - logging.debug("Error getting git status: %s", err) - git_info.update(_get_repo_info(gitdir)) - return git_info - else: - logging.debug("Error getting git version: %s", err) - except: - logging.debug("Exception on run: %s", traceback.format_exc()) - - if from_file: - git_info["version"] = get_version_from_file(klippy_src) - return git_info diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py index fa4303ed..a9043394 100644 --- a/scripts/buildcommands.py +++ b/scripts/buildcommands.py @@ -8,6 +8,7 @@ import sys, os, subprocess, optparse, logging, shlex, socket, time, traceback import json, zlib sys.path.append("./klippy") +import klippy.klippy import msgproto FILEHEADER = """ @@ -555,18 +556,9 @@ def check_output(prog): return "" -# Obtain version info from "git" program -def git_version(): - if not os.path.exists(".git"): - logging.debug("No '.git' file/directory found") - return "" - ver = check_output("git describe --always --tags --long --dirty").strip() - logging.debug("Got git version: %s" % (repr(ver),)) - return ver - def build_version(extra, cleanbuild): - version = git_version() + version = klippy.klippy.__version__ if not version: cleanbuild = False version = "?" diff --git a/scripts/logextract.py b/scripts/logextract.py index 3050ff0b..d6da323d 100755 --- a/scripts/logextract.py +++ b/scripts/logextract.py @@ -645,11 +645,7 @@ class GatherShutdown: if first is not None and last > first + 5.0: self.finalize() return False - if ( - line.startswith("Git version") - or line.startswith("Start printer at") - or line == "===== Config file =====" - ): + if line.startswith("Start printer at") or line == "===== Config file =====": self.finalize() return False return True @@ -702,9 +698,7 @@ def main(): continue recent_lines.clear() handler = None - if line.startswith("Git version"): - last_git = format_comment(line_num, line) - elif line.startswith("Start printer at"): + if line.startswith("Start printer at"): last_start = format_comment(line_num, line) elif line == "===== Config file =====": handler = GatherConfig(configs, line_num, recent_lines, logname) diff --git a/scripts/make_version.py b/scripts/make_version.py deleted file mode 100644 index 7a48018a..00000000 --- a/scripts/make_version.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python2 -# Get the version number for klippy -# -# Copyright (C) 2018 Lucas Fink <software@lfcode.ca> -# -# This file may be distributed under the terms of the GNU GPLv3 license. - -from __future__ import print_function - -import argparse -import os -import sys - -sys.path.append(os.path.join(os.path.dirname(__file__), "../klippy")) - -import util - - -def main(argv): - p = argparse.ArgumentParser() - p.add_argument("distroname", help="Name of distro this package is intended for") - args = p.parse_args() - print( - util.get_git_version(from_file=False)["version"], - args.distroname.replace(" ", ""), - sep="-", - ) - - -if __name__ == "__main__": - main(sys.argv[1:]) |