Skip to content

Commit b570092

Browse files
committed
multiple small changes
1 parent 426393a commit b570092

3 files changed

Lines changed: 40 additions & 24 deletions

File tree

builder-tool/pack.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
from src.builderTool import BaseBuilder, Logger, PYTHON, NULL_TARGET #this file use the module to build itself
1+
from src.builderTool import BaseBuilder, Logger, PYTHON #this file use the module to build itself
22

33

44
class Builder(BaseBuilder):
55
def Setup(self):
66
self.addDirectory('src')
7-
self.addAndReplaceByPackageVersion('pyproject.toml', self.tempDir + '/pyproject.toml')
8-
self.addFile("requirements.txt")
9-
self.addAndReplaceByPackageVersion('readme.md', self.tempDir + '/readme.md')
10-
7+
self.addAndReplaceByPackageVersion('pyproject.toml')
8+
self.addAndReplaceByPackageVersion('readme.md')
9+
self.runCommand(f'{PYTHON} -m pip install --upgrade build')
1110

1211
def Build(self):
13-
self.runCommand(f'{PYTHON} -m build --outdir {self.distDir} {self.tempDir} > {NULL_TARGET}')
14-
15-
def Publish(self):
16-
Logger.info("Publishing package")
12+
self.runCommand(f'{PYTHON} -m build --outdir {self.distDir} .')
13+
1714

1815
BaseBuilder.execute()

builder-tool/requirements.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

builder-tool/src/builderTool.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010

1111
try:
1212
from gamuLogger import Logger, LEVELS, debugFunc
13-
except ImportError:
13+
import gamuLogger
14+
15+
if gamuLogger.__version__ < '2.0.0-beta.9':
16+
raise ImportError('Logger version is too old')
17+
18+
except (ImportError, AttributeError):
1419
print("Logger not found, installing...", end=' ', flush=True)
15-
os.system(f'{sys.executable} -m pip install https://github.com/GamuNetwork/logger/releases/download/2.0.0-alpha.4/gamu_logger-2.0.0a4-py3-none-any.whl > {NULL_TARGET} 2> {NULL_TARGET}')
20+
os.system(f'{sys.executable} -m pip install https://github.com/GamuNetwork/logger/releases/download/2.0.0-beta.9/gamu_logger-2.0.0b9-py3-none-any.whl > {NULL_TARGET} 2> {NULL_TARGET}')
1621
print("done")
1722
from gamuLogger import Logger, LEVELS, debugFunc
23+
import gamuLogger
1824

1925
Logger.setModule('Builder')
2026

@@ -124,6 +130,7 @@ def __init__(self):
124130
Logger.setLevel('stdout', LEVELS.DEEP_DEBUG)
125131

126132

133+
Logger.debug("Using gamuLogger version : " + gamuLogger.__version__)
127134
Logger.debug('Using temporary directory: ' + os.path.abspath(self.args.temp_dir))
128135
Logger.debug('Using distribution directory: ' + os.path.abspath(self.args.dist_dir))
129136

@@ -139,46 +146,62 @@ def packageVersion(self):
139146
def distDir(self):
140147
return os.path.abspath(self.args.dist_dir)
141148

142-
def addAndReplaceByPackageVersion(self, src, dst, versionString = "{version}"):
149+
def addAndReplaceByPackageVersion(self, src, dest = None, versionString = "{version}"):
150+
"""Add a file to the temporary directory and replace a string by the package version"""
143151
Logger.debug('Adding file: ' + src + ' and replacing version string by ' + self.packageVersion)
144152
with open(src, 'r') as file:
145153
content = file.read()
146154
content = content.replace(versionString, self.packageVersion)
147-
with open(dst, 'w') as file:
155+
if dest is None:
156+
dest = src
157+
with open(self.tempDir + '/' + dest, 'w') as file:
148158
file.write(content)
159+
return True
149160

150161
def runCommand(self, command) -> bool:
151-
Logger.debug('Executing command: ' + command)
162+
"""Execute a command in the temporary directory"""
163+
Logger.debug(f'Executing command {command}\n working directory: {self.tempDir}')
152164
stdoutFile, stdoutPath = mkstemp()
153165
stderrFile, stderrPath = mkstemp()
166+
167+
cwd = os.getcwd()
168+
os.chdir(self.tempDir)
154169
returnCode = os.system(f'{command} > {stdoutPath} 2> {stderrPath}')
170+
os.chdir(cwd)
171+
155172
if returnCode != 0:
156-
Logger.error(f'Task failed successfully with return code {returnCode}') # this is for the joke
173+
Logger.error(f'Task failed with return code {returnCode}')
157174
with open(stdoutPath, 'r') as file:
158-
Logger.debug('stdout: ' + file.read())
175+
Logger.debug('stdout:\n' + file.read())
159176
with open(stderrPath, 'r') as file:
160-
Logger.debug('stderr: ' + file.read())
177+
Logger.debug('stderr:\n' + file.read())
161178

162179
os.remove(stdoutPath)
163180
os.remove(stderrPath)
164-
return False
181+
raise RuntimeError('Command failed')
165182
else:
166183
Logger.debug('Command executed successfully')
167184
os.remove(stdoutPath)
168185
os.remove(stderrPath)
169186
return True
170187

188+
171189
def addFile(self, path, dest = None):
190+
"""Copy a file to the temporary directory"""
172191
Logger.debug('Adding file: ' + path)
173192
if dest is None:
174193
dest = path
175194
shutil.copy(path, self.tempDir + '/' + dest)
195+
return True
196+
176197

177198
def addDirectory(self, path, dest = None):
199+
"""Copy a directory to the temporary directory"""
178200
Logger.debug('Adding directory: ' + path)
179201
if dest is None:
180202
dest = path
181203
shutil.copytree(path, self.tempDir + '/' + dest, ignore=shutil.ignore_patterns('*.pyc', '*.pyo', '__pycache__'))
204+
return True
182205

183206

184207
def __clean(self) -> bool:
@@ -231,7 +254,6 @@ def __runStep(self, step : str):
231254
return False
232255
else:
233256
if hasSucceeded is None:
234-
Logger.warning('Step "' + step + '" did not return a value, but didn\'t throw anything, assuming it has succeeded')
235257
return True
236258
return hasSucceeded
237259

@@ -268,6 +290,8 @@ def __run(self, configuredSteps : list[str]):
268290

269291
if self.clean:
270292
self.__clean()
293+
else:
294+
Logger.warning(f'Directory {self.tempDir} wasn\'t deleted because cleaning is disabled')
271295

272296
if HasFailed:
273297
Logger.critical('A step has failed')

0 commit comments

Comments
 (0)