[+] update cli logic

1. add pip_sync method;
  1.1. rely on -f flag
    of pip to use a custom cache dir;
This commit is contained in:
Siarhei Siniak 2024-12-29 14:36:30 +03:00
parent 0cee9beaea
commit c9382162de
5 changed files with 119 additions and 16 deletions

@ -1 +1 @@
Subproject commit 857be4a1fb1c07e2a239b61ce49b34cdd1698467
Subproject commit e6422d353cda8ff688ceff7036b91d2a0de0d277

@ -65,6 +65,46 @@ class CLI(abc.ABC):
argv,
)
def pip_sync(
self,
project: str,
features: list[str],
) -> None:
from . import cli_bootstrap
pyproject = cli_bootstrap.pyproject_load(
self.projects[project].source_dir / 'pyproject.toml'
)
dependencies = sum([
pyproject.dependencies[o]
for o in features
], [])
pip_find_links : list[pathlib.Path] = []
if not pyproject.pip_find_links is None:
pip_find_links.extend(pyproject.pip_find_links)
logger.info(dict(
dependencies=dependencies,
))
if len(dependencies) > 0:
subprocess.check_call([
self.dist_settings.python_path,
'-m',
'uv', 'pip', 'install',
*sum([
['-f', str(o),]
for o in pip_find_links
], []),
# '-f', str(pathlib.Path(__file__).parent / 'deps' / 'dist'),
'--offline',
*dependencies,
])
def deploy_fetch_dist(
self,
force: bool,
@ -138,6 +178,16 @@ class CLI(abc.ABC):
latest_file['path'],
])
@property
def pkg_config_path(self,) -> set[pathlib.Path]:
return {
pathlib.Path(o)
for o in glob.glob(
str(self.dist_settings.env_path / 'lib' / 'python*' / '**' / 'pkgconfig'),
recursive=True,
)
}
def deploy_wheel(
self,
project_name: str,
@ -170,11 +220,22 @@ class CLI(abc.ABC):
if env is None:
env = dict()
extra_args: list[str] = []
if len(self.third_party_roots) > 0:
extra_args.extend([
'-Csetup-args=%s' % (
'-Dthird_party_roots=%s' % str(o.absolute())
)
for o in self.third_party_roots
])
cmd = [
sys.executable,
'-m',
'build',
'-w', '-n',
*extra_args,
'-Csetup-args=-Dmodes=pyproject',
'-Cbuild-dir=%s' % str(project.build_dir / 'pyproject'),
'-Csetup-args=-Dinstall_path=%s' % str(project.dest_dir),
@ -269,11 +330,16 @@ class CLI(abc.ABC):
*argv,
])
@property
def third_party_roots(self) -> list[pathlib.Path]:
return []
def meson_setup(
self,
project_name: str,
force: bool,
argv: Optional[list[str]] = None,
# third_party_roots: Optional[list[pathlib.Path]] = None,
) -> None:
project = self.projects[project_name]
@ -285,12 +351,21 @@ class CLI(abc.ABC):
logger.info(dict(action='removing build dir', path=project.build_dir / 'meson'))
shutil.rmtree(project.build_dir / 'meson')
extra_args : list[str] = []
if len(self.third_party_roots) > 0:
extra_args.extend([
'-Dthird_party_roots=%s' % str(o.absolute())
for o in self.third_party_roots
])
cmd = [
shutil_which('meson', True,),
'setup',
str(project.source_dir),
str(project.build_dir / 'meson'),
'-Dmodes=["meson"]',
*extra_args,
# '-Dpkgconfig.relocatable=true',
'-Dprefix=/',
*argv,

@ -17,6 +17,7 @@ logger = logging.getLogger(__name__)
class PyProject:
dependencies: dict[str, list[str]]
early_features: Optional[list[str]] = None
pip_find_links: Optional[list[pathlib.Path]] = None
def pyproject_load(
d: pathlib.Path,
@ -42,7 +43,7 @@ def pyproject_load(
assert isinstance(v, list)
assert isinstance(k, str)
dependencies[k] = v
dependencies[k] = v
res = PyProject(
@ -65,6 +66,12 @@ def pyproject_load(
if 'early_features' in content['tool'][tool_name]:
res.early_features = content['tool'][tool_name]['early_features']
if 'pip_find_links' in content['tool'][tool_name]:
res.pip_find_links = [
pathlib.Path(o)
for o in content['tool'][tool_name]['pip_find_links']
]
return res
@dataclasses.dataclass
@ -115,20 +122,25 @@ def env_bootstrap(
'build', 'setuptools', 'meson-python', 'pybind11',
])
early_wheels = glob.glob(
str(
pathlib.Path(__file__).parent / 'deps' / 'dist' / 'early' / '*.whl'
)
)
# early_wheels = glob.glob(
# str(
# pathlib.Path(__file__).parent / 'deps' / 'dist' / 'early' / '*.whl'
# )
# )
if len(early_wheels) > 0:
subprocess.check_call([
bootstrap_settings.python_path,
'-m',
'uv', 'pip', 'install',
'--offline',
*early_wheels,
])
# if len(early_wheels) > 0:
# subprocess.check_call([
# bootstrap_settings.python_path,
# '-m',
# 'uv', 'pip', 'install',
# '--offline',
# *early_wheels,
# ])
pip_find_links : list[pathlib.Path] = []
if not pyproject.pip_find_links is None:
pip_find_links.extend(pyproject.pip_find_links)
if pyproject.early_features:
early_dependencies = sum([
@ -139,11 +151,17 @@ def env_bootstrap(
logger.info(dict(
early_dependencies=early_dependencies,
))
if len(early_dependencies) > 0:
subprocess.check_call([
bootstrap_settings.python_path,
'-m',
'uv', 'pip', 'install',
*sum([
['-f', str(o),]
for o in pip_find_links
], []),
# '-f', str(pathlib.Path(__file__).parent / 'deps' / 'dist'),
'--offline',
*early_dependencies,
])

@ -0,0 +1,10 @@
import pip._internal.commands.show
def pip_show(
argv: list[str],
) -> list[pip._internal.commands.show._PackageInfo]:
return list(
pip._internal.commands.show.search_packages_info(
argv,
)
)

@ -1,6 +1,6 @@
[project]
name = 'online.fxreader.pr34'
version = '0.1.1'
version = '0.1.4'
dependencies = [
#"-r requirements.txt",