avoid using pkg_resources

This is deprecated in python 3.12.
Also, improve file handling
This commit is contained in:
Marc-Philip 2024-06-10 22:31:15 +02:00 committed by GitHub
parent c144b68306
commit 3d66b318ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,33 +3,27 @@
# Copyright (C) 2022 Thomas Basler and others # Copyright (C) 2022 Thomas Basler and others
# #
import os import os
import pkg_resources
Import("env") Import("env")
required_pkgs = {'dulwich'} try:
installed_pkgs = {pkg.key for pkg in pkg_resources.working_set} from dulwich import porcelain
missing_pkgs = required_pkgs - installed_pkgs except ModuleNotFoundError:
if missing_pkgs:
env.Execute('"$PYTHONEXE" -m pip install dulwich') env.Execute('"$PYTHONEXE" -m pip install dulwich')
from dulwich import porcelain
from dulwich import porcelain
def updateFileIfChanged(filename, content): def updateFileIfChanged(filename, content):
mustUpdate = True mustUpdate = True
try: try:
fp = open(filename, "rb") with open(filename, "rb") as fp:
if fp.read() == content: if fp.read() == content:
mustUpdate = False mustUpdate = False
fp.close()
except: except:
pass pass
if mustUpdate: if mustUpdate:
fp = open(filename, "wb") with open(filename, "wb") as fp:
fp.write(content) fp.write(content)
fp.close()
return mustUpdate return mustUpdate