Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use separate packages for pycriu and crit #2282

Merged
merged 1 commit into from
Oct 17, 2023
Merged
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
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ HOSTCFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
export AFLAGS CFLAGS USERCLFAGS HOSTCFLAGS

# Default target
all: flog criu lib
all: flog criu lib crit
.PHONY: all

#
Expand Down Expand Up @@ -298,9 +298,9 @@ clean mrproper:
$(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=soccr $@
$(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=crit $@
$(Q) $(MAKE) $(build)=compel $@
$(Q) $(MAKE) $(build)=compel/plugins $@
$(Q) $(MAKE) $(build)=lib $@
.PHONY: clean mrproper

clean-amdgpu_plugin:
Expand Down Expand Up @@ -347,6 +347,10 @@ amdgpu_plugin: criu
$(Q) $(MAKE) -C plugins/amdgpu all
.PHONY: amdgpu_plugin

crit: lib
$(Q) $(MAKE) -C crit
.PHONY: crit

#
# Generating tar requires tag matched CRIU_VERSION.
# If not found then simply use GIT's describe with
Expand Down Expand Up @@ -412,6 +416,7 @@ help:
@echo ' Targets:'
@echo ' all - Build all [*] targets'
@echo ' * criu - Build criu'
@echo ' * crit - Build crit'
@echo ' zdtm - Build zdtm test-suite'
@echo ' docs - Build documentation'
@echo ' install - Install CRIU (see INSTALL.md)'
Expand All @@ -435,11 +440,12 @@ lint:
flake8 --config=scripts/flake8.cfg test/zdtm.py
flake8 --config=scripts/flake8.cfg test/inhfd/*.py
flake8 --config=scripts/flake8.cfg test/others/rpc/config_file.py
flake8 --config=scripts/flake8.cfg lib/py/images/pb2dict.py
flake8 --config=scripts/flake8.cfg lib/py/images/images.py
flake8 --config=scripts/flake8.cfg lib/pycriu/images/pb2dict.py
flake8 --config=scripts/flake8.cfg lib/pycriu/images/images.py
flake8 --config=scripts/flake8.cfg scripts/criu-ns
flake8 --config=scripts/flake8.cfg test/others/criu-ns/run.py
flake8 --config=scripts/flake8.cfg crit/setup.py
flake8 --config=scripts/flake8.cfg crit/*.py
flake8 --config=scripts/flake8.cfg crit/crit/*.py
flake8 --config=scripts/flake8.cfg scripts/uninstall_module.py
flake8 --config=scripts/flake8.cfg coredump/ coredump/coredump
flake8 --config=scripts/flake8.cfg scripts/github-indent-warnings.py
Expand Down
7 changes: 6 additions & 1 deletion Makefile.install
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ install-lib: lib
$(Q) $(MAKE) $(build)=lib install
.PHONY: install-lib

install-crit: lib
$(Q) $(MAKE) $(build)=crit install
.PHONY: install-crit

install-criu: criu
$(Q) $(MAKE) $(build)=criu install
.PHONY: install-criu
Expand All @@ -50,12 +54,13 @@ install-compel: $(compel-install-targets)
$(Q) $(MAKE) $(build)=compel/plugins install
.PHONY: install-compel

install: install-man install-lib install-criu install-compel install-amdgpu_plugin ;
install: install-man install-lib install-crit install-criu install-compel install-amdgpu_plugin ;
.PHONY: install

uninstall:
$(Q) $(MAKE) -C Documentation $@
$(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=crit $@
$(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=compel $@
$(Q) $(MAKE) $(build)=compel/plugins $@
Expand Down
2 changes: 1 addition & 1 deletion coredump/pycriu
2 changes: 2 additions & 0 deletions crit/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
crit.egg-info/
build/
dist/
version.py
40 changes: 40 additions & 0 deletions crit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
PIP_BREAK_SYSTEM_PACKAGES := 0

VERSION_FILE := $(if $(obj),$(addprefix $(obj)/,crit/version.py),crit/version.py)

all-y += ${VERSION_FILE}
cleanup-y += ${VERSION_FILE}

${VERSION_FILE}:
$(Q) echo "__version__ = '${CRIU_VERSION}'" > $@

install: ${VERSION_FILE}
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP INSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
.PHONY: install

uninstall:
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP UNINSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
.PHONY: uninstall
1 change: 1 addition & 0 deletions crit/crit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .version import __version__
20 changes: 10 additions & 10 deletions lib/py/cli.py → crit/crit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os

import pycriu
from . import __version__


def inf(opts):
Expand Down Expand Up @@ -41,9 +42,9 @@ def decode(opts):
try:
img = pycriu.images.load(inf(opts), opts['pretty'], opts['nopl'])
except pycriu.images.MagicException as exc:
print("Unknown magic %#x.\n"\
"Maybe you are feeding me an image with "\
"raw data(i.e. pages.img)?" % exc.magic, file=sys.stderr)
print("Unknown magic %#x.\n"
"Maybe you are feeding me an image with "
"raw data(i.e. pages.img)?" % exc.magic, file=sys.stderr)
sys.exit(1)

if opts['pretty']:
Expand All @@ -59,9 +60,9 @@ def encode(opts):
try:
img = json.load(inf(opts))
except UnicodeDecodeError:
print("Cannot read JSON.\n"\
"Maybe you are feeding me an image with protobuf data? "\
"Encode expects JSON input.", file=sys.stderr)
print("Cannot read JSON.\n"
"Maybe you are feeding me an image with protobuf data? "
"Encode expects JSON input.", file=sys.stderr)
sys.exit(1)
pycriu.images.dump(img, outf(opts, False))

Expand Down Expand Up @@ -131,7 +132,7 @@ def ftype_find_in_files(opts, ft, fid):
if files_img is None:
try:
files_img = pycriu.images.load(dinf(opts, "files.img"))['entries']
except:
except Exception:
files_img = []

if len(files_img) == 0:
Expand Down Expand Up @@ -364,7 +365,7 @@ def main():
desc = 'CRiu Image Tool'
parser = argparse.ArgumentParser(
description=desc, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--version', action='version', version=pycriu.__version__)
parser.add_argument('--version', action='version', version=__version__)

subparsers = parser.add_subparsers(
help='Use crit CMD --help for command-specific help')
Expand All @@ -374,8 +375,7 @@ def main():
'decode', help='convert criu image from binary type to json')
decode_parser.add_argument(
'--pretty',
help=
'Multiline with indents and some numerical fields in field-specific format',
help='Multiline with indents and some numerical fields in field-specific format',
action='store_true')
decode_parser.add_argument(
'-i',
Expand Down
1 change: 0 additions & 1 deletion crit/pycriu

This file was deleted.

23 changes: 21 additions & 2 deletions crit/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools", "wheel"] # PEP 508 specifications.
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "crit"
description = "CRiu Image Tool"
authors = [
{name = "CRIU team", email = "[email protected]"},
]
license = {text = "GPLv2"}
dynamic = ["version"]
requires-python = ">=3.6"

[project.scripts]
crit = "crit.__main__:main"

[tool.setuptools]
packages = ["crit"]

[tool.setuptools.dynamic]
version = {attr = "crit.__version__"}
7 changes: 0 additions & 7 deletions crit/requirements.txt

This file was deleted.

20 changes: 20 additions & 0 deletions crit/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Configuring setuptools using pyproject.toml files was introduced in setuptools 61.0.0
# https://setuptools.pypa.io/en/latest/history.html#v61-0-0
# For older versions of setuptools, we need to use the setup.cfg file
# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#declarative-config

[metadata]
name = crit
description = CRiu Image Tool
author = CRIU team
author_email = [email protected]
license = GPLv2
version = attr: crit.__version__

[options]
packages = crit
python_requires = >=3.6

[options.entry_points]
console_scripts =
crit = crit.__main__:main
19 changes: 5 additions & 14 deletions crit/setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
from setuptools import setup, find_packages
import pycriu
#!/usr/bin/env python3
import setuptools

setup(
name='crit',
version=pycriu.__version__,
description='CRiu Image Tool',
author='CRIU team',
author_email='[email protected]',
license='GPLv2',
url='https://github.com/checkpoint-restore/criu',
packages=find_packages('.'),
scripts=['crit'],
install_requires=[],
)

if __name__ == '__main__':
setuptools.setup()
1 change: 1 addition & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pycriu.egg-info/
32 changes: 15 additions & 17 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ lib-a: lib/c/$(CRIU_A)

#
# Python bindings.
lib/py/Makefile: ;
lib/py/%: .FORCE
lib/pycriu/Makefile: ;
lib/pycriu/%: .FORCE
$(call msg-gen, $@)
$(Q) $(MAKE) $(build)=lib/py $@
$(Q) $(MAKE) $(build)=lib/pycriu $@
lib-py:
$(Q) $(MAKE) $(build)=lib/py all
$(Q) $(MAKE) $(build)=lib/pycriu all
.PHONY: lib-py

clean-lib:
$(Q) $(MAKE) $(build)=lib/c clean
$(Q) $(MAKE) $(build)=lib/py clean
$(Q) $(MAKE) $(build)=lib/pycriu clean
.PHONY: clean-lib
clean: clean-lib
cleanup-y += lib/c/$(CRIU_SO) lib/c/$(CRIU_A) lib/c/criu.pc
Expand All @@ -59,17 +59,15 @@ install: lib-c lib-a lib-py lib/c/criu.pc.in
$(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP INSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " SKIP INSTALL pycriu: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install -r ./crit/requirements.txt
$(Q) $(PYTHON) -m pip install --no-build-isolation --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
$(E) " INSTALL " pycriu
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./lib
endif
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install -r ./crit/requirements.txt
$(Q) $(PYTHON) -m pip install --no-build-isolation --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
$(E) " INSTALL " pycriu
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./lib
endif
.PHONY: install

Expand All @@ -84,14 +82,14 @@ uninstall:
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/pkgconfig/,criu.pc)
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP UNINSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " SKIP UNINSTALL pycriu: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
$(E) " UNINSTALL" pycriu
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) pycriu
endif
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
$(E) " UNINSTALL" pycriu
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) pycriu
endif
.PHONY: uninstall
1 change: 1 addition & 0 deletions lib/py/.gitignore → lib/pycriu/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
*_pb2.py
*.pyc
version.py
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/py/__init__.py → lib/pycriu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import rpc_pb2 as rpc
from . import images
from .criu import *
from .version import __version__
from .version import __version__
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions lib/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[build-system]
requires = ["setuptools", "protobuf<4.0"]
build-backend = "setuptools.build_meta"

[project]
name = "pycriu"
description = "Python bindings for CRIU"
authors = [
{name = "CRIU team", email = "[email protected]"},
]
license = {text = "GPLv2"}
dynamic = ["version"]
requires-python = ">=3.6"

[tool.setuptools]
packages = ["pycriu", "pycriu.images"]

[tool.setuptools.dynamic]
version = {attr = "pycriu.__version__"}
16 changes: 16 additions & 0 deletions lib/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Configuring setuptools using pyproject.toml files was introduced in setuptools 61.0.0
# https://setuptools.pypa.io/en/latest/history.html#v61-0-0
# For older versions of setuptools, we need to use the setup.cfg file
# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#declarative-config

[metadata]
name = pycriu
description = Python bindings for CRIU
author = CRIU team
author_email = [email protected]
license = GPLv2
version = attr: pycriu.__version__

[options]
packages = find:
python_requires = >=3.6
4 changes: 2 additions & 2 deletions crit/crit → lib/setup.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
import setuptools

from pycriu import cli

if __name__ == '__main__':
cli.main()
setuptools.setup()
Loading
Loading