Skip to content
Merged

Dev #14

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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ repos:
hooks:
# Run the linter.
- id: ruff

- repo: https://github.com/jenkinsci/jenkinsfilelint
rev: v1.4.0
hooks:
- id: jenkinsfilelint
args: ["--include", "Jenkinsfile"] # Adjust the pattern as needed
561 changes: 561 additions & 0 deletions Jenkinsfile

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions ci/jenkins/scripts/create_uv_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/env bash
# This script creates a global configuration file for Jenkins to make the UV cache metadata for longer than standard

set -e

MAX_AGE_API=6000
MAX_AGE_FILES=365000000

GLOBAL_CONFIG_FILE=uv.toml

echo "# This file is auto-generated by $(basename $0)" > $GLOBAL_CONFIG_FILE

echo '' >> $GLOBAL_CONFIG_FILE
echo '[[index]]' >> $GLOBAL_CONFIG_FILE
echo "url = \"https://pypi.org/simple\"" >> $GLOBAL_CONFIG_FILE
echo 'default = true' >> $GLOBAL_CONFIG_FILE
echo "cache-control = { api = \"max-age=$MAX_AGE_API\", files = \"max-age=$MAX_AGE_FILES, immutable\" }" >> $GLOBAL_CONFIG_FILE

for arg in "$@"; do
echo '' >> $GLOBAL_CONFIG_FILE
echo '[[index]]' >> $GLOBAL_CONFIG_FILE
echo "url = \"$arg\"" >> $GLOBAL_CONFIG_FILE
echo "cache-control = { api = \"max-age=$MAX_AGE_API\", files = \"max-age=$MAX_AGE_FILES, immutable\" }" >> $GLOBAL_CONFIG_FILE
done

echo "$(realpath $GLOBAL_CONFIG_FILE)"
23 changes: 23 additions & 0 deletions ci/jenkins/scripts/new-uv-global-config.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$GLOBAL_CONFIG_FILE = "uv.toml"
$MAX_AGE_API="6000"
$MAX_AGE_FILES="365000000"

$scriptName = $MyInvocation.MyCommand.Name
"# This file is auto-generated by $scriptName" | Set-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8

'' | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
'[[index]]' | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
"url = `"https://pypi.org/simple`"" | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
'default = true' | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
"cache-control = { api = `"max-age=$MAX_AGE_API`", files = `"max-age=$MAX_AGE_FILES, immutable`" }" | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8


foreach ($arg in $args) {
'' | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
'[[index]]' | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
"url = `"$arg`"" | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
'default = true' | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
"cache-control = { api = `"max-age=$MAX_AGE_API`", files = `"max-age=$MAX_AGE_FILES, immutable`" }" | Add-Content -Path $GLOBAL_CONFIG_FILE -Encoding UTF8
}

Write-Output (Get-ChildItem -Path $GLOBAL_CONFIG_FILE).FullName
34 changes: 18 additions & 16 deletions package_speedwagon/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import packaging.version
import pathlib
import subprocess
import sys
from typing import (
Callable,
Dict,
Expand All @@ -19,11 +18,7 @@
Union, Tuple
)

if sys.version_info < (3, 10):
import importlib_metadata as metadata
else:
from importlib import metadata

from importlib import metadata

import cmake

Expand Down Expand Up @@ -119,6 +114,7 @@ def __init__(
self.app_name = app_name
self.frozen_application_path = frozen_application_path
self.output_path = output_path
self.build_path = os.path.join("build", "packaging", "cpack")

@abc.abstractmethod
def cpack_generator_name(self) -> str:
Expand Down Expand Up @@ -147,9 +143,9 @@ def generate(self) -> str:


def generate_package_description_file(
package_metadata: metadata.PackageMetadata,
output_path: str,
output_name: str = "package_description_file.txt"
package_metadata: metadata.PackageMetadata,
output_path: str,
output_name: str = "package_description_file.txt"
) -> str:
"""Generate package description file.

Expand All @@ -162,6 +158,9 @@ def generate_package_description_file(

"""
description_file = os.path.join(output_path, output_name)
if not os.path.exists(output_path):
os.makedirs(output_path)

with open(description_file, 'w') as f:
data: Union[List[str], str] = package_metadata.get_all(
'summary',
Expand Down Expand Up @@ -300,7 +299,7 @@ def general_section(self) -> str:
"cpack_package_description_file": os.path.abspath(
generate_package_description_file(
self.package_metadata,
output_path=self.output_path
output_path=self.build_path
)
).replace(os.sep, '/')
}
Expand All @@ -321,7 +320,7 @@ class WixToolsetPackageGenerator(CPackGenerator):
def default_license_find_strategies(
self
) -> List[Callable[[], Optional[str]]]:
expected_license_file = os.path.join(self.output_path, "LICENSE.txt")
expected_license_file = os.path.join(self.build_path, "LICENSE.txt")
return [
CopyLicenseFile(
source_file='LICENSE',
Expand Down Expand Up @@ -522,8 +521,8 @@ def get_cpack_path(


def run_cpack(
config_file: str,
build_path: str = os.path.join('.', "dist")
config_file: str,
build_path: str = os.path.join('.', "build"),
) -> None:
"""Execute cpack command with a config file.

Expand All @@ -533,8 +532,11 @@ def run_cpack(

"""
args = [
"--config", config_file,
"-B", build_path,
"--config", os.path.relpath(config_file, build_path),
]
cpack_cmd = get_cpack_path()
subprocess.check_call([cpack_cmd] + args)

if not os.path.exists(build_path):
os.makedirs(build_path)

subprocess.check_call([cpack_cmd] + args, cwd=build_path)
87 changes: 63 additions & 24 deletions package_speedwagon/package_speedwagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
import subprocess
import os
import tomlkit
import tomlkit.exceptions

from typing import Optional, Mapping, Type, List, Callable
from typing import Optional, Mapping, Type, List, Callable, Dict
import zipfile
from package_speedwagon import defaults, freeze, installer, utils

if sys.version_info < (3, 10):
import importlib_metadata as metadata
else:
from importlib import metadata
from importlib import metadata

if sys.version_info < (3, 11):
from pip._vendor import tomli as tomllib
Expand Down Expand Up @@ -254,7 +252,7 @@ def create_virtualenv(
raise

def read_pkg_info(raw_data: str):
data = {
data: Dict[str, Optional[str]] = {
"name": None,
"version": None,
"license": None,
Expand Down Expand Up @@ -290,7 +288,9 @@ def read_whl_metadata(wheel):
continue
if "METADATA" != filename:
continue
return read_pkg_info(zip_file.read(compressed_file).decode("utf-8"))
return read_pkg_info(
zip_file.read(compressed_file).decode("utf-8")
)
else:
raise FileNotFoundError("Unable to find whl metadata")

Expand Down Expand Up @@ -393,7 +393,11 @@ def get_package_top_level(package_file: pathlib.Path) -> str:
raise ValueError("unknown File type")


def generate_hook_for_hidden(hidden_imports, top_level_package, additional_hooks_path):
def generate_hook_for_hidden(
hidden_imports,
top_level_package,
additional_hooks_path
):
for package in hidden_imports:

if package == top_level_package:
Expand Down Expand Up @@ -448,9 +452,9 @@ def extract_license_file_from_wheel(


def generate_cpack_config_file_string(
source_application_path: str,
args: argparse.Namespace,
generator_type: Type[installer.CPackGenerator]
source_application_path: str,
args: argparse.Namespace,
generator_type: Type[installer.CPackGenerator]
) -> str:
generator = generator_type(
args.app_name,
Expand All @@ -459,6 +463,7 @@ def generate_cpack_config_file_string(
package_metadata=get_package_metadata(args.python_package_file),
cl_args=args
)
generator.build_path = os.path.join(args.build_path, "frozen", "cpack")
generator.toml_config_file = args.config_file

for strategy in DEFAULT_LICENSE_FILE_FINDING_ORDER:
Expand All @@ -474,6 +479,9 @@ def generate_cpack_config_file_string(


class AbsPlatformPackager(abc.ABC):
def __init__(self):
self.build_path = pathlib.Path("build")

@abc.abstractmethod
def generate_config_file(
self,
Expand All @@ -498,7 +506,12 @@ def generate_config_file(
source_application_path: str,
args: argparse.Namespace
) -> pathlib.Path:
cpack_config_file = os.path.join(args.dist, "CPackConfig.cmake")
build_path = os.path.join(args.build_path, "frozen", "cpack")

if not os.path.exists(build_path):
os.makedirs(build_path)

cpack_config_file = os.path.join(build_path, "CPackConfig.cmake")
with open(cpack_config_file, "w") as f:
f.write(
generate_cpack_config_file_string(
Expand All @@ -523,12 +536,12 @@ def create_system_package(
config_file: pathlib.Path,
output_path: pathlib.Path = pathlib.Path("dist")
) -> pathlib.Path:
installer.run_cpack(str(config_file), str(output_path))
installer.run_cpack(str(config_file), str(self.build_path))
try:
return self.locate_installer_artifact(output_path)
return self.locate_installer_artifact(self.build_path)
except FileNotFoundError as error:
raise FileNotFoundError(
f"No dmg found for {config_file}"
f"No dmg found for {config_file}. Looked in {self.build_path}"
) from error


Expand Down Expand Up @@ -610,7 +623,12 @@ def generate_freeze_config(self, specs: freeze.SpecsData) -> str:
else:
package_file: pathlib.Path = self.python_package_file
top_level_package = get_package_top_level(package_file)
generate_hook_for_hidden(specs.hidden_imports, top_level_package, self.additional_hooks_path)

generate_hook_for_hidden(
specs.hidden_imports,
top_level_package,
self.additional_hooks_path
)

freeze.create_hook_for_wheel(
path=self.additional_hooks_path,
Expand Down Expand Up @@ -687,7 +705,13 @@ def generate_freeze_config(self, specs: freeze.SpecsData) -> str:
package_file: pathlib.Path = self.python_package_file

top_level_package = get_package_top_level(package_file)
generate_hook_for_hidden(specs.hidden_imports, top_level_package, self.additional_hooks_path)

generate_hook_for_hidden(
specs.hidden_imports,
top_level_package,
self.additional_hooks_path
)

freeze.create_hook_for_wheel(
path=self.additional_hooks_path,
strategy=lambda: top_level_package,
Expand All @@ -703,8 +727,12 @@ def generate_config_file(
source_application_path: str,
args: argparse.Namespace
) -> pathlib.Path:
build_path = os.path.join(args.build_path, "frozen", "cpack")
cpack_config_file = os.path.join(build_path, "CPackConfig.cmake")

if not os.path.exists(build_path):
os.makedirs(build_path)

cpack_config_file = os.path.join(args.dist, "CPackConfig.cmake")
with open(cpack_config_file, "w") as f:
f.write(
generate_cpack_config_file_string(
Expand All @@ -729,9 +757,9 @@ def create_system_package(
config_file: pathlib.Path,
output_path: pathlib.Path = pathlib.Path("dist")
) -> pathlib.Path:
installer.run_cpack(str(config_file), str(output_path))
installer.run_cpack(str(config_file), str(self.build_path))
try:
return self.locate_installer_artifact(output_path)
return self.locate_installer_artifact(self.build_path)
except FileNotFoundError as error:
raise FileNotFoundError(
f"No .msi found for {config_file}"
Expand Down Expand Up @@ -778,7 +806,8 @@ def main() -> None:
"Scripts" if sys.platform == 'win32' else 'bin'
)),
]):
if len(args.requirement) == 1 and pathlib.Path(args.requirement[0]).name == "pylock.toml":
if len(args.requirement) == 1 and \
pathlib.Path(args.requirement[0]).name == "pylock.toml":
create_virtualenv_from_pylock(
args.python_package_file,
package_env,
Expand All @@ -805,25 +834,35 @@ def main() -> None:
)
with open(specs_file_name) as f:
print(f.read())

frozen_app_build_path = os.path.join(args.build_path, "frozen")

freeze.freeze_env(
specs_file=specs_file_name,
work_path=os.path.join(args.build_path, 'workpath'),
dest=args.dist
dest=frozen_app_build_path
)
expected_frozen_path = freeze.find_frozen_folder(args.dist, args=args)
expected_frozen_path =\
freeze.find_frozen_folder(frozen_app_build_path, args=args)

if not expected_frozen_path:
raise FileNotFoundError(
"Unable to find folder containing frozen application"
)
platform_packager = config_generator.get_application_packager()
platform_packager.build_path =\
os.path.join(args.build_path, "frozen", "cpack")
packaging_config_file = platform_packager.generate_config_file(
source_application_path=expected_frozen_path,
args=args
)
assert os.path.exists(packaging_config_file)
package_file =\
platform_packager.create_system_package(packaging_config_file)
output_file = os.path.join(args.dist, pathlib.Path(package_file).name)
shutil.move(package_file, output_file)

print(f"Created {package_file}")
print(f"Created {output_file}")


if __name__ == '__main__':
Expand Down
Loading
Loading