From 592314d882840c17c07181a0c36d3822f0aae35d Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Sun, 7 Aug 2022 00:38:26 -0400 Subject: [PATCH 1/3] staticx: version: Handle git not being installed This bites me frequently when running staticx bind-mounted into a docker container which doesn't have git. --- staticx/version.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/staticx/version.py b/staticx/version.py index 7394c03..71611f5 100644 --- a/staticx/version.py +++ b/staticx/version.py @@ -34,17 +34,21 @@ def get_version(): # If a local git repository is present, use `git describe` to provide a rich version gitdir = normpath(join(PROJPATH, '.git')) if exists(gitdir): - tag, commits, rev = git_describe() - - # Ensure the base version matches the Git tag - if tag != BASE_VERSION: - raise Exception('Git revision different from base version') - - # No local version if we're on a tag - if commits == 0 and not rev.endswith('dirty'): - return BASE_VERSION - - return '{}+{}-{}'.format(BASE_VERSION, commits, rev) + try: + tag, commits, rev = git_describe() + except FileNotFoundError: + # git not installed + pass + else: + # Ensure the base version matches the Git tag + if tag != BASE_VERSION: + raise Exception('Git revision different from base version') + + # No local version if we're on a tag + if commits == 0 and not rev.endswith('dirty'): + return BASE_VERSION + + return '{}+{}-{}'.format(BASE_VERSION, commits, rev) # Git archive From 995ac6ba7faa0db10a9316098001e2c04cd929e1 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Sun, 7 Aug 2022 00:45:37 -0400 Subject: [PATCH 2/3] staticx: version: Replace os.path usage with pathlib --- staticx/version.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/staticx/version.py b/staticx/version.py index 71611f5..4470c36 100644 --- a/staticx/version.py +++ b/staticx/version.py @@ -1,12 +1,12 @@ -from os.path import abspath, dirname, exists, join, normpath +from pathlib import Path import subprocess import sys # This logic has been adapted from that of PyInstaller # https://github.com/pyinstaller/pyinstaller/ -PACKAGEPATH = abspath(dirname(__file__)) -PROJPATH = dirname(PACKAGEPATH) +PACKAGEPATH = Path(__file__).absolute().parent +PROJPATH = PACKAGEPATH.parent # Base version, which will be augmented with Git information BASE_VERSION = '0.13.6' @@ -32,8 +32,8 @@ def get_version(): # Git repo # If a local git repository is present, use `git describe` to provide a rich version - gitdir = normpath(join(PROJPATH, '.git')) - if exists(gitdir): + gitdir = PROJPATH / '.git' + if gitdir.exists(): try: tag, commits, rev = git_describe() except FileNotFoundError: From 8b6a24c287457960e07f4b712745681249341f07 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Sun, 7 Aug 2022 00:48:35 -0400 Subject: [PATCH 3/3] Update changelog for #226 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e759bd0..293f99a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed - Fixed an issue where library symlinks with the same basename would present problems ([#225]) +- Don't crash if .git/ dir is present but git is not installed ([#226]) ## [0.13.6] - 2021-12-02 ### Changed @@ -305,3 +306,4 @@ Initial release [#210]: https://github.com/JonathonReinhart/staticx/pull/210 [#217]: https://github.com/JonathonReinhart/staticx/pull/217 [#225]: https://github.com/JonathonReinhart/staticx/pull/225 +[#226]: https://github.com/JonathonReinhart/staticx/pull/226