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
#
import os
import pkg_resources
Import("env")
required_pkgs = {'dulwich'}
installed_pkgs = {pkg.key for pkg in pkg_resources.working_set}
missing_pkgs = required_pkgs - installed_pkgs
if missing_pkgs:
try:
from dulwich import porcelain
except ModuleNotFoundError:
env.Execute('"$PYTHONEXE" -m pip install dulwich')
from dulwich import porcelain
from dulwich import porcelain
def updateFileIfChanged(filename, content):
mustUpdate = True
try:
fp = open(filename, "rb")
with open(filename, "rb") as fp:
if fp.read() == content:
mustUpdate = False
fp.close()
except:
pass
if mustUpdate:
fp = open(filename, "wb")
with open(filename, "wb") as fp:
fp.write(content)
fp.close()
return mustUpdate