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

@ -1,17 +1,43 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import glob import glob
import dataclasses
import pathlib import pathlib
import sys import sys
import subprocess import subprocess
import os 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' 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([ subprocess.check_call([
'uv', 'venv', '--seed', '--offline', 'uv', 'venv', '--seed', '--offline',
str(env_path) str(bootstrap_settings.env_path)
]) ])
subprocess.check_call([ subprocess.check_call([
@ -19,13 +45,13 @@ if not env_path.exists():
'pip', 'pip',
'install', 'install',
'-p', '-p',
python_path, bootstrap_settings.python_path,
'--offline', '--offline',
'uv', 'uv',
]) ])
subprocess.check_call([ subprocess.check_call([
python_path, bootstrap_settings.python_path,
'-m', '-m',
'uv', 'pip', 'install', 'uv', 'pip', 'install',
'--offline', '--offline',
@ -39,29 +65,50 @@ if not env_path.exists():
) )
if len(early_wheels) > 0: if len(early_wheels) > 0:
subprocess.check_call([ subprocess.check_call([
python_path, bootstrap_settings.python_path,
'-m', '-m',
'uv', 'pip', 'install', 'uv', 'pip', 'install',
'--offline', '--offline',
*early_wheels, *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__': def run() -> None:
if pathlib.Path(sys.executable).absolute() != python_path.absolute(): 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( os.execv(
str(python_path), str(bootstrap_settings.python_path),
[ [
str(python_path), str(bootstrap_settings.python_path),
*sys.argv, *sys.argv,
] ]
) )
os.execv( os.execv(
str(python_path), str(bootstrap_settings.python_path),
[ [
str(python_path), str(bootstrap_settings.python_path),
pathlib.Path(__file__).parent / 'cli.py', pathlib.Path(__file__).parent / 'cli.py',
*sys.argv[1:], *sys.argv[1:],
] ]
) )
if __name__ == '__main__':
run()