[+] 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, 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( def deploy_fetch_dist(
self, self,
force: bool, force: bool,
@ -138,6 +178,16 @@ class CLI(abc.ABC):
latest_file['path'], 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( def deploy_wheel(
self, self,
project_name: str, project_name: str,
@ -170,11 +220,22 @@ class CLI(abc.ABC):
if env is None: if env is None:
env = dict() 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 = [ cmd = [
sys.executable, sys.executable,
'-m', '-m',
'build', 'build',
'-w', '-n', '-w', '-n',
*extra_args,
'-Csetup-args=-Dmodes=pyproject', '-Csetup-args=-Dmodes=pyproject',
'-Cbuild-dir=%s' % str(project.build_dir / '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),
@ -269,11 +330,16 @@ class CLI(abc.ABC):
*argv, *argv,
]) ])
@property
def third_party_roots(self) -> list[pathlib.Path]:
return []
def meson_setup( def meson_setup(
self, self,
project_name: str, project_name: str,
force: bool, force: bool,
argv: Optional[list[str]] = None, argv: Optional[list[str]] = None,
# third_party_roots: Optional[list[pathlib.Path]] = None,
) -> None: ) -> None:
project = self.projects[project_name] 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')) logger.info(dict(action='removing build dir', path=project.build_dir / 'meson'))
shutil.rmtree(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 = [ cmd = [
shutil_which('meson', True,), shutil_which('meson', True,),
'setup', 'setup',
str(project.source_dir), str(project.source_dir),
str(project.build_dir / 'meson'), str(project.build_dir / 'meson'),
'-Dmodes=["meson"]', '-Dmodes=["meson"]',
*extra_args,
# '-Dpkgconfig.relocatable=true', # '-Dpkgconfig.relocatable=true',
'-Dprefix=/', '-Dprefix=/',
*argv, *argv,

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