Skip to content

Commit

Permalink
avoid using pkg_resources
Browse files Browse the repository at this point in the history
This is deprecated in python 3.12.
Also, improve file handling
  • Loading branch information
mpw96 authored Jun 10, 2024
1 parent c144b68 commit 3d66b31
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions pio-scripts/auto_firmware_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
if fp.read() == content:
mustUpdate = False
fp.close()
with open(filename, "rb") as fp:
if fp.read() == content:
mustUpdate = False
except:
pass
if mustUpdate:
fp = open(filename, "wb")
fp.write(content)
fp.close()
with open(filename, "wb") as fp:
fp.write(content)
return mustUpdate


Expand Down

0 comments on commit 3d66b31

Please sign in to comment.