Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-hooks/copyright_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def check_copyright(files):
for file in files:
contents = file.read_text()
contents = file.read_text(encoding="utf-8")
if not contents.strip():
# Don't add headers to empty files
continue
Expand All @@ -42,7 +42,7 @@ def check_copyright(files):
if not contents.endswith("\n"):
contents += "\n"
if original_contents != contents:
file.write_text(contents)
file.write_text(contents, encoding="utf-8")


def inject_copyright_header(contents):
Expand Down
22 changes: 10 additions & 12 deletions relenv/build/common/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,13 @@ def run(
root_log = logging.getLogger(None)
if sys.platform == "win32":
if not show_ui:
handler = logging.StreamHandler()
handler.setLevel(logging.getLevelName(log_level))
root_log.addHandler(handler)

for handler in root_log.handlers:
if isinstance(handler, logging.StreamHandler):
handler.setFormatter(
logging.Formatter(f"%(asctime)s {name} %(message)s")
)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.getLevelName(log_level))
root_log.addHandler(stream_handler)

for h in root_log.handlers:
if isinstance(h, logging.StreamHandler):
h.setFormatter(logging.Formatter(f"%(asctime)s {name} %(message)s"))

if not self.dirs.build.exists():
os.makedirs(self.dirs.build, exist_ok=True)
Expand All @@ -431,8 +429,8 @@ def run(
time.sleep(0.3)

logfp = io.open(os.path.join(dirs.logs, "{}.log".format(name)), "w")
handler = logging.FileHandler(dirs.logs / f"{name}.log")
root_log.addHandler(handler)
file_handler = logging.FileHandler(dirs.logs / f"{name}.log")
root_log.addHandler(file_handler)
root_log.setLevel(logging.NOTSET)

# Add line count handler if tracking is enabled
Expand Down Expand Up @@ -497,7 +495,7 @@ def run(
os.chdir(cwd)
if line_count_handler is not None:
root_log.removeHandler(line_count_handler)
root_log.removeHandler(handler)
root_log.removeHandler(file_handler)
logfp.close()

def cleanup(self) -> None:
Expand Down
22 changes: 11 additions & 11 deletions relenv/build/common/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,24 @@

def patch_file(path: PathLike, old: str, new: str) -> None:
"""
Search a file line by line for a string to replace.
Search a file for a string to replace.

:param path: Location of the file to search
:type path: str
:param old: The value that will be replaced
:type path: str
:param old: The value that will be replaced (regex)
:type old: str
:param new: The value that will replace the 'old' value.
:type path: str
"""
log.debug("Patching file: %s", path)
with open(path, "r") as fp:
content = fp.read()
new_content = ""
for line in content.splitlines():
line = re.sub(old, new, line)
new_content += line + "\n"
with open(path, "w") as fp:
fp.write(new_content)
path = pathlib.Path(path)
if not path.exists():
log.warning("File not found for patching: %s", path)
return

content = path.read_text(encoding="utf-8")
new_content = re.sub(old, new, content, flags=re.IGNORECASE | re.MULTILINE)
path.write_text(new_content, encoding="utf-8")


def update_sbom_checksums(
Expand Down
Loading
Loading