Skip to content

Commit

Permalink
add versions inside yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesneimog committed Nov 24, 2024
1 parent 9397449 commit c370d4c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
12 changes: 11 additions & 1 deletion Sources/pd4web/Builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import subprocess
import importlib.metadata as importlib_metadata
import yaml

# from .Patch import PatchLine
from .Pd4Web import Pd4Web
Expand Down Expand Up @@ -42,6 +43,9 @@ def __init__(self, Pd4Web: Pd4Web):
self.ConfigureProject()
self.CompileProject()
self.CopyExtraJsFiles()

# Save the project versions
self.SaveProjectVersions()

def InitVariables(self):
self.cmakeFile = []
Expand Down Expand Up @@ -498,8 +502,14 @@ def CopyExtraJsFiles(self):
for file in files:
if not os.path.exists(self.Pd4Web.PROJECT_ROOT + "/WebPatch/" + file):
shutil.copy(os.path.join(root, file), self.Pd4Web.PROJECT_ROOT + "/WebPatch/")

os.chdir(cwd)

def SaveProjectVersions(self):
# check if file exists
if not os.path.exists(self.Pd4Web.PROJECT_ROOT + "/Pd4Web/versions.yaml"):
with open(self.Pd4Web.PROJECT_ROOT + "/Pd4Web/versions.yaml", "w") as f:
yaml.dump(self.Pd4Web.Version, f)
return

def __repr__(self) -> str:
return f"< GetCode Object >"
Expand Down
11 changes: 7 additions & 4 deletions Sources/pd4web/Libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def getLibCommitVersion(self, libRepo, tag_name) -> pygit2.Commit:
commit = libRepo.head.peel()
return commit

def CloneLibrary(self, libsPath, libData):
def CloneLibrary(self, libData):
"""
Initializes submodules in the specified repository path.
Expand All @@ -158,11 +158,12 @@ def CloneLibrary(self, libsPath, libData):
curr_commit: pygit2.Commit = libRepo.head.peel()
lib_commit: pygit2.Commit = self.getLibCommitVersion(libRepo, libData.version)
if curr_commit.id == lib_commit.id:
# print(f"Library {libData.repo} is in the right commit", color="green")
return # library up-to-date
self.Pd4Web.Version["externals"][libData.name] = str(lib_commit.id)
return
libRepo.set_head(lib_commit.id)
libRepo.checkout_tree(lib_commit)
libRepo.reset(lib_commit.id, pygit2.GIT_RESET_HARD)
self.Pd4Web.Version["externals"][libData.name] = str(lib_commit.id)
return

libLink = f"https://github.com/{libData.dev}/{libData.repo}"
Expand All @@ -187,6 +188,8 @@ def CloneLibrary(self, libsPath, libData):
submodule_collection.update()
except:
self.Pd4Web.exception("Failed to initialize submodules.")

self.Pd4Web.Version["externals"][libData.name] = str(commit.id)

# TODO: Try to merge commits from submodules
# try:
Expand All @@ -212,7 +215,7 @@ def GetLibrarySourceCode(
os.mkdir(self.Pd4Web.APPDATA + "/Externals")

libFolder = self.Pd4Web.APPDATA + f"/Externals/{libData.name}"
self.CloneLibrary(libFolder, libData)
self.CloneLibrary(libData)
if not os.path.exists(self.PROJECT_ROOT + f"/Pd4Web/Externals/{libData.name}"):
self.Pd4Web.print(
f"Copying {libData.name} to Pd4Web/Externals...",
Expand Down
62 changes: 36 additions & 26 deletions Sources/pd4web/Pd4Web.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,41 @@ def argParse(self):

self.Execute()

def InitVariables(self):
from .Objects import Objects
from .Libraries import ExternalLibraries

self.cpuCores = os.cpu_count()
self.usedObjects = []
self.patchLinesProcessed = []
self.uiReceiversSymbol = []
self.externalsSourceCode = []
self.externalsLinkLibraries = []
self.externalsLinkLibrariesFolders = []
self.externalsSetupFunctions = []

self.declaredLocalAbs = []
self.declaredLibsObjs = []
self.declaredPaths = []
self.processedAbs = []

# Versions
self.Version = {}
self.Version["python"] = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
self.Version["pure-data"] = self.PD_VERSION
self.Version["emsdk"] = self.EMSDK_VERSION
self.Version["pd4web"] = importlib_metadata.version("pd4web")
self.Version["externals"] = {}

self.Libraries: ExternalLibraries = ExternalLibraries(self)
self.Objects: Objects = Objects(self)

self.env = os.environ.copy()
python_dir = os.path.dirname(sys.executable)
self.env["PATH"] = f"{python_dir};{self.env['PATH']}"
self.env["PYTHON"] = sys.executable
self.env["EMSDK_QUIET"] = "1"

def Execute(self):
from .Builder import GetAndBuildExternals
from .Compilers import ExternalsCompiler
Expand Down Expand Up @@ -156,32 +191,7 @@ def get_mainPaths(self):
if not os.path.exists(self.APPDATA):
os.makedirs(self.APPDATA)

def InitVariables(self):
from .Objects import Objects
from .Libraries import ExternalLibraries

self.cpuCores = os.cpu_count()
self.usedObjects = []
self.patchLinesProcessed = []
self.uiReceiversSymbol = []
self.externalsSourceCode = []
self.externalsLinkLibraries = []
self.externalsLinkLibrariesFolders = []
self.externalsSetupFunctions = []

self.declaredLocalAbs = []
self.declaredLibsObjs = []
self.declaredPaths = []
self.processedAbs = []

self.Libraries = ExternalLibraries(self)
self.Objects: Objects = Objects(self)

self.env = os.environ.copy()
python_dir = os.path.dirname(sys.executable)
self.env["PATH"] = f"{python_dir};{self.env['PATH']}"
self.env["PYTHON"] = sys.executable
self.env["EMSDK_QUIET"] = "1"


def DownloadZip(self, url, filename, what=""):
self.print(f"Downloading {what}...", color="green", silence=self.SILENCE)
Expand Down

0 comments on commit c370d4c

Please sign in to comment.