From 616d23d804af6081df77319addf4a6d98146f629 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Mon, 15 Jan 2024 22:16:19 +0000 Subject: [PATCH] IfcGit fixes suggested by `ruff` --- .../blenderbim/bim/module/ifcgit/data.py | 2 +- src/blenderbim/blenderbim/tool/ifcgit.py | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/data.py b/src/blenderbim/blenderbim/bim/module/ifcgit/data.py index 2a74731d02..ef1d2e09ce 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/data.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/data.py @@ -88,7 +88,7 @@ class IfcGitData: try: if tool.IfcGitRepo.repo.branches: return tool.IfcGit.branches_by_hexsha(tool.IfcGitRepo.repo) - except: + except AttributeError: return {} @classmethod diff --git a/src/blenderbim/blenderbim/tool/ifcgit.py b/src/blenderbim/blenderbim/tool/ifcgit.py index 82daab53b9..b27bf15dba 100644 --- a/src/blenderbim/blenderbim/tool/ifcgit.py +++ b/src/blenderbim/blenderbim/tool/ifcgit.py @@ -1,18 +1,17 @@ import os import re - -# allows git import even if git executable isn't found -os.environ["GIT_PYTHON_REFRESH"] = "quiet" -try: - import git -except: - print("Warning: GitPython not available.") import bpy import logging from blenderbim.bim import import_ifc from blenderbim.bim.ifc import IfcStore import blenderbim.tool as tool +# allows git import even if git executable isn't found +os.environ["GIT_PYTHON_REFRESH"] = "quiet" +try: + import git +except ImportError: + print("Warning: GitPython not available.") class IfcGit: @classmethod @@ -54,17 +53,19 @@ class IfcGit: else: return None - if IfcGitRepo.repo != None and IfcGitRepo.repo.working_dir == path_dir: + if IfcGitRepo.repo is not None and IfcGitRepo.repo.working_dir == path_dir: return IfcGitRepo.repo try: repo = git.Repo(path_dir) - except: + except git.exc.InvalidGitRepositoryError: parentdir_path = os.path.abspath(os.path.join(path_dir, os.pardir)) if parentdir_path == path_dir: # root folder return None return cls.repo_from_path(parentdir_path) + except git.exc.NoSuchPathError: + return None if repo: IfcGitRepo.repo = repo return repo @@ -181,9 +182,9 @@ class IfcGit: for commit in commits: - if props.ifcgit_filter == "tagged" and not commit.hexsha in lookup: + if props.ifcgit_filter == "tagged" and commit.hexsha not in lookup: continue - elif props.ifcgit_filter == "relevant" and not commit in commits_relevant: + elif props.ifcgit_filter == "relevant" and commit not in commits_relevant: continue props.ifcgit_commits.add() @@ -485,8 +486,7 @@ class IfcGit: cls.dos2unix(path_ifc) repo.index.add(path_ifc) repo.git.commit("--no-edit") - except: - + except git.exc.GitError: operator.report({"ERROR"}, "Unknown IFC Merge failure") return False @@ -506,7 +506,7 @@ class IfcGit: query = "/^#" + str(step_id) + "[ =]/,/;/:" + relpath_ifc try: logtext = repo.git.log("-L", query, "-s") - except: + except git.exc.CommandError: logtext = "No Git history found :(" return logtext