[+] update packaging

1. update cli and cli_bootstrap;
  1.1. use /meson and /pyproject
    build dirs to fix collision
    for install step;
This commit is contained in:
Siarhei Siniak 2024-12-22 18:33:06 +03:00
parent ea63c67280
commit 1626974759
3 changed files with 82 additions and 23 deletions

@ -1 +1 @@
Subproject commit 64d8fecc5740fb77dcd40ef45a8b3c74c2187ba0
Subproject commit 857be4a1fb1c07e2a239b61ce49b34cdd1698467

@ -1,6 +1,7 @@
import dataclasses
import io
import glob
import os
import pathlib
import logging
import sys
@ -13,6 +14,7 @@ from .os import shutil_which
from typing import (
Optional,
Literal,
Any,
)
logger = logging.getLogger(__name__)
@ -130,6 +132,7 @@ class CLI(abc.ABC):
argv: Optional[list[str]] = None,
output_dir: Optional[pathlib.Path] = None,
force: Optional[bool] = None,
env: Optional[dict[str, str]] = None,
) -> None:
project = self.projects[project_name]
@ -147,12 +150,16 @@ class CLI(abc.ABC):
force=force,
)
if env is None:
env = dict()
cmd = [
sys.executable,
'-m',
'build',
'-w', '-n',
'-Csetup-args=-Dmodes=pyproject',
'-Cbuild-dir=%s' % str(project.build_dir / 'pyproject'),
'-Csetup-args=-Dinstall_path=%s' % str(project.dest_dir),
# '-Cbuild-dir=%s' % str(project.build_dir),
str(project.source_dir),
@ -161,7 +168,12 @@ class CLI(abc.ABC):
if not output_dir is None:
cmd.extend(['-o', str(output_dir)])
subprocess.check_call(cmd)
logger.info(dict(env=env))
subprocess.check_call(
cmd,
env=dict(list(os.environ.items())) | env,
)
def meson_install(
self,
@ -184,7 +196,7 @@ class CLI(abc.ABC):
shutil_which('meson', True,),
'install',
'-C',
project.build_dir,
project.build_dir / 'meson',
'--destdir', project.dest_dir,
*argv,
])
@ -218,7 +230,7 @@ class CLI(abc.ABC):
subprocess.check_call([
shutil_which('ninja', True),
'-C',
str(project.build_dir),
str(project.build_dir / 'meson'),
*argv,
])
@ -236,7 +248,7 @@ class CLI(abc.ABC):
shutil_which('meson', True,),
'compile',
'-C',
project.build_dir,
project.build_dir / 'meson',
*argv,
])
@ -252,15 +264,15 @@ class CLI(abc.ABC):
argv = []
if force:
if project.build_dir.exists():
logger.info(dict(action='removing build dir', path=project.build_dir))
shutil.rmtree(project.build_dir)
if (project.build_dir / 'meson').exists():
logger.info(dict(action='removing build dir', path=project.build_dir / 'meson'))
shutil.rmtree(project.build_dir / 'meson')
cmd = [
shutil_which('meson', True,),
'setup',
str(project.source_dir),
str(project.build_dir),
str(project.build_dir / 'meson'),
'-Dmodes=["meson"]',
# '-Dpkgconfig.relocatable=true',
'-Dprefix=/',

@ -1,17 +1,43 @@
#!/usr/bin/env python3
import glob
import dataclasses
import pathlib
import sys
import subprocess
import os
import logging
env_path = pathlib.Path(__file__).parent / '.venv'
from typing import (Self, Optional,)
logger = logging.getLogger(__name__)
@dataclasses.dataclass
class BootstrapSettings:
env_path: pathlib.Path
python_path: pathlib.Path
@classmethod
def get(
cls,
base_dir: Optional[pathlib.Path] = None,
) -> Self:
if base_dir is None:
base_dir = pathlib.Path.cwd()
env_path = base_dir / '.venv'
python_path = env_path / 'bin' / 'python3'
if not env_path.exists():
return cls(
env_path=env_path,
python_path=python_path,
)
def env_bootstrap() -> None:
bootstrap_settings = BootstrapSettings.get()
subprocess.check_call([
'uv', 'venv', '--seed', '--offline',
str(env_path)
str(bootstrap_settings.env_path)
])
subprocess.check_call([
@ -19,13 +45,13 @@ if not env_path.exists():
'pip',
'install',
'-p',
python_path,
bootstrap_settings.python_path,
'--offline',
'uv',
])
subprocess.check_call([
python_path,
bootstrap_settings.python_path,
'-m',
'uv', 'pip', 'install',
'--offline',
@ -39,29 +65,50 @@ if not env_path.exists():
)
if len(early_wheels) > 0:
subprocess.check_call([
python_path,
bootstrap_settings.python_path,
'-m',
'uv', 'pip', 'install',
'--offline',
*early_wheels,
])
def paths_equal(
a: pathlib.Path | str,
b: pathlib.Path | str
) -> bool:
return (
os.path.abspath(str(a)) ==
os.path.abspath(str(b))
)
if __name__ == '__main__':
if pathlib.Path(sys.executable).absolute() != python_path.absolute():
def run() -> None:
bootstrap_settings = BootstrapSettings.get()
logging.basicConfig(level=logging.INFO)
if not bootstrap_settings.env_path.exists():
env_bootstrap()
logger.info([sys.executable, sys.argv, bootstrap_settings.python_path])
if not paths_equal(sys.executable, bootstrap_settings.python_path):
os.execv(
str(python_path),
str(bootstrap_settings.python_path),
[
str(python_path),
str(bootstrap_settings.python_path),
*sys.argv,
]
)
os.execv(
str(python_path),
str(bootstrap_settings.python_path),
[
str(python_path),
str(bootstrap_settings.python_path),
pathlib.Path(__file__).parent / 'cli.py',
*sys.argv[1:],
]
)
if __name__ == '__main__':
run()