aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--docs/Packaging.md31
-rw-r--r--klippy/util.py35
-rw-r--r--scripts/make_version.py31
4 files changed, 87 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index bfb0690c..f9521672 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ out
*.pyc
.config
.config.old
+klippy/.version
diff --git a/docs/Packaging.md b/docs/Packaging.md
new file mode 100644
index 00000000..2d8b3100
--- /dev/null
+++ b/docs/Packaging.md
@@ -0,0 +1,31 @@
+# Packaging klipper
+
+Klipper is somewhat of a packaging anomaly among python programs, as it doesn't
+use setuptools to build and install. Some notes regarding how best to package it
+are as follows:
+
+## C modules
+
+Klipper uses a C module to handle some kinematics calculations more quickly.
+This module needs to be compiled at packaging time to avoid introducing a
+runtime dependency on a compiler. To compile the C module, run `python2
+klippy/chelper/__init__.py`.
+
+## Compiling python code
+
+Many distributions have a policy of compiling all python code before packaging
+to improve startup time. You can do this by running `python2 -m compileall
+klippy`.
+
+## Versioning
+
+If you are building a package of Klipper from git, it is usual practice not to
+ship a .git directory, so the versioning must be handled without git. To do
+this, use the script shipped in `scripts/make_version.py` which should be run as
+follows: `python2 scripts/make_version.py YOURDISTRONAME > klippy/.version`.
+
+## Sample packaging script
+
+klipper-git is packaged for Arch Linux, and has a PKGBUILD (package build
+script) available at
+https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=klipper-git.
diff --git a/klippy/util.py b/klippy/util.py
index 86f42246..dfb505a8 100644
--- a/klippy/util.py
+++ b/klippy/util.py
@@ -53,18 +53,31 @@ def get_cpu_info():
model_name = dict(lines).get("model name", "?")
return "%d core %s" % (core_count, model_name)
-def get_git_version():
+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_git_version(from_file=True):
+ klippy_src = os.path.dirname(__file__)
+
# Obtain version info from "git" program
- gitdir = os.path.join(sys.path[0], '..')
- if not os.path.exists(gitdir):
- logging.debug("No '.git' file/directory found")
- return "?"
- prog = "git -C %s describe --always --tags --long --dirty" % (gitdir,)
+ gitdir = os.path.join(klippy_src, '..')
+ prog = ('git', '-C', gitdir, 'describe', '--always', '--tags', '--long', '--dirty')
try:
- process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE)
- output = process.communicate()[0]
- retcode = process.poll()
+ process = subprocess.Popen(prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ ver, err = process.communicate()
+ retcode = process.wait()
+ if retcode == 0:
+ return ver.strip()
+ else:
+ logging.debug("Error getting git version: %s", err)
except OSError:
logging.debug("Exception on run: %s", traceback.format_exc())
- return "?"
- return output.strip()
+
+ if from_file:
+ return get_version_from_file(klippy_src)
+ return "?"
diff --git a/scripts/make_version.py b/scripts/make_version.py
new file mode 100644
index 00000000..47422500
--- /dev/null
+++ b/scripts/make_version.py
@@ -0,0 +1,31 @@
+#!/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),
+ args.distroname.replace(' ', ''), sep='-')
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])