Projects STRLCPY criu Commits 7f0f0759
🤬
  • crit: fix compatibility with Python 3.12

    Python 3.12 includes a few breaking changes, such as the removal of the
    distutils module [1] and the deprecation of `setup.py install` in
    favour of pip install [2]. This patch updates the installation script
    for crit to reflect these changes by replacing the use of
    `setup.py install` with `pip install` and `distutils` with
    `setuptools`. In addition, a minimal pyproject.toml file has
    been added as it is required by the new version of pip [3].
    
    It is worth noting that with this change we are switching from the egg
    packaging format to wheel [4] and add pip as a build dependency.
    
    [1] https://www.python.org/downloads/release/python-3120a2/
    [2] https://github.com/pypa/setuptools/pull/2824
    [3] https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/
    [4] https://packaging.python.org/en/latest/discussions/wheel-vs-egg/
    
    Signed-off-by: Radostin Stoyanov <[email protected]>
  • Loading...
  • 7f0f0759
    1 parent bd0f209c
  • ■ ■ ■ ■ ■ ■
    .cirrus.yml
    skipped 35 lines
    36 36   ln -sf /usr/include/google/protobuf/descriptor.proto images/google/protobuf/descriptor.proto
    37 37   dnf config-manager --set-enabled crb # Same as CentOS 8 powertools
    38 38   dnf -y install epel-release epel-next-release
    39  - dnf -y install --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python-devel python-PyYAML python-future python-protobuf python-junit_xml python-flake8 xmlto
     39 + dnf -y install --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python-devel python-PyYAML python-future python-protobuf python-junit_xml python3-importlib-metadata python-flake8 xmlto
    40 40   systemctl stop sssd
    41 41   # Even with selinux in permissive mode the selinux tests will be executed.
    42 42   # The Cirrus CI user runs as a service from selinux point of view and is
    skipped 65 lines
    108 108   yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm || :
    109 109   yum install -y dnf-plugins-core
    110 110   yum config-manager --set-enabled powertools
    111  - yum install -y --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python3-devel python3-flake8 python3-PyYAML python3-future python3-protobuf python3-junit_xml xmlto
     111 + yum install -y --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python3-devel python3-flake8 python3-PyYAML python3-future python3-protobuf python3-importlib-metadata python3-junit_xml xmlto
    112 112   alternatives --set python /usr/bin/python3
    113 113   systemctl stop sssd
    114 114   # Even with selinux in permissive mode the selinux tests will be executed
    skipped 77 lines
  • ■ ■ ■ ■ ■
    .gitignore
    skipped 37 lines
    38 38  criu/protobuf-desc-gen.h
    39 39  lib/build/
    40 40  lib/c/criu.pc
    41  -lib/.crit-setup.files
    42 41  compel/include/asm
    43 42  include/common/asm
    44 43  include/common/config.h
    skipped 2 lines
  • ■ ■ ■ ■ ■
    Makefile
    skipped 427 lines
    428 428   flake8 --config=scripts/flake8.cfg lib/py/images/pb2dict.py
    429 429   flake8 --config=scripts/flake8.cfg lib/py/images/images.py
    430 430   flake8 --config=scripts/flake8.cfg scripts/criu-ns
    431  - flake8 --config=scripts/flake8.cfg scripts/crit-setup.py
     431 + flake8 --config=scripts/flake8.cfg crit/setup.py
     432 + flake8 --config=scripts/flake8.cfg scripts/uninstall_module.py
    432 433   flake8 --config=scripts/flake8.cfg coredump/
    433 434   shellcheck --version
    434 435   shellcheck scripts/*.sh
    skipped 46 lines
  • ■ ■ ■ ■ ■ ■
    crit/.gitignore
     1 +crit.egg-info/
     2 +build/
     3 + 
  • ■ ■ ■ ■ ■ ■
    crit/pyproject.toml
     1 +[build-system]
     2 +requires = ["setuptools"]
     3 + 
  • ■ ■ ■ ■ ■ ■
    crit/setup.py
     1 +import os
     2 +from setuptools import setup, find_packages
     3 + 
     4 + 
     5 +def get_version():
     6 + version = '0.0.1'
     7 + env = os.environ
     8 + if 'CRIU_VERSION_MAJOR' in env and 'CRIU_VERSION_MINOR' in env:
     9 + version = '{}.{}'.format(
     10 + env['CRIU_VERSION_MAJOR'],
     11 + env['CRIU_VERSION_MINOR']
     12 + )
     13 + if 'CRIU_VERSION_SUBLEVEL' in env and env['CRIU_VERSION_SUBLEVEL']:
     14 + version += '.' + env['CRIU_VERSION_SUBLEVEL']
     15 + return version
     16 + 
     17 + 
     18 +setup(
     19 + name='crit',
     20 + version=get_version(),
     21 + description='CRiu Image Tool',
     22 + author='CRIU team',
     23 + author_email='[email protected]',
     24 + license='GPLv2',
     25 + url='https://github.com/checkpoint-restore/criu',
     26 + packages=find_packages('.'),
     27 + scripts=['crit'],
     28 + install_requires=[],
     29 +)
     30 + 
  • ■ ■ ■ ■ ■ ■
    lib/Makefile
    skipped 1 lines
    2 2  CRIU_A := libcriu.a
    3 3  UAPI_HEADERS := lib/c/criu.h images/rpc.proto images/rpc.pb-c.h criu/include/version.h
    4 4   
    5  -#
    6  -# File to keep track of files installed by setup.py
    7  -CRIT_SETUP_FILES := lib/.crit-setup.files
    8  - 
    9 5  all-y += lib-c lib-a lib-py
    10 6   
    11 7  #
    skipped 46 lines
    58 54   $(Q) mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
    59 55   $(Q) sed -e 's,@version@,$(CRIU_VERSION),' -e 's,@libdir@,$(LIBDIR),' -e 's,@includedir@,$(dir $(INCLUDEDIR)/criu/),' lib/c/criu.pc.in > lib/c/criu.pc
    60 56   $(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
     57 +ifeq ($(PYTHON),python3)
    61 58   $(E) " INSTALL " crit
    62  - $(Q) $(PYTHON) scripts/crit-setup.py install --prefix=$(DESTDIR)$(PREFIX) --record $(CRIT_SETUP_FILES)
     59 + $(Q) $(PYTHON) -m pip install --upgrade --force-reinstall --prefix=$(DESTDIR)$(PREFIX) ./crit
     60 +endif
    63 61  .PHONY: install
    64 62   
    65 63  uninstall:
    skipped 5 lines
    71 69   $(Q) $(RM) $(addprefix $(DESTDIR)$(INCLUDEDIR)/criu/,$(notdir $(UAPI_HEADERS)))
    72 70   $(E) " UNINSTALL" pkgconfig/criu.pc
    73 71   $(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/pkgconfig/,criu.pc)
     72 +ifeq ($(PYTHON),python3)
    74 73   $(E) " UNINSTALL" crit
    75  - $(Q) while read -r file; do $(RM) "$$file"; done < $(CRIT_SETUP_FILES)
     74 + $(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
     75 +endif
    76 76  .PHONY: uninstall
    77 77   
  • ■ ■ ■ ■ ■
    scripts/build/Dockerfile.alpine
    skipped 39 lines
    40 40   e2fsprogs \
    41 41   py-yaml \
    42 42   py3-flake8 \
     43 + py3-importlib-metadata \
    43 44   asciidoctor
    44 45   
    45 46  # The rpc test cases are running as user #1000, let's add the user
    skipped 6 lines
  • ■ ■ ■ ■ ■
    scripts/build/Dockerfile.archlinux
    skipped 33 lines
    34 34   flake8 \
    35 35   asciidoctor \
    36 36   python-junit-xml \
     37 + python-importlib-metadata \
    37 38   diffutils
    38 39   
    39 40  COPY . /criu
    skipped 8 lines
  • ■ ■ ■ ■ ■ ■
    scripts/ci/prepare-for-fedora-rawhide.sh
    skipped 26 lines
    27 27   python3-future \
    28 28   python3-protobuf \
    29 29   python3-junit_xml \
     30 + python3-pip \
     31 + python3-importlib-metadata \
    30 32   python-unversioned-command \
    31 33   redhat-rpm-config \
    32 34   sudo \
    skipped 9 lines
  • ■ ■ ■ ■
    scripts/ci/run-ci-tests.sh
    skipped 5 lines
    6 6   libnl-3-dev gdb bash libnet-dev util-linux asciidoctor
    7 7   libnl-route-3-dev time flake8 libbsd-dev python3-yaml
    8 8   libperl-dev pkg-config python3-future python3-protobuf
    9  - python3-junit.xml)
     9 + python3-pip python3-importlib-metadata python3-junit.xml)
    10 10   
    11 11  X86_64_PKGS=(gcc-multilib)
    12 12   
    skipped 317 lines
  • ■ ■ ■ ■
    scripts/ci/vagrant.sh
    skipped 37 lines
    38 38   ssh default sudo dnf upgrade -y
    39 39   ssh default sudo dnf install -y gcc git gnutls-devel nftables-devel libaio-devel \
    40 40   libasan libcap-devel libnet-devel libnl3-devel libbsd-devel make protobuf-c-devel \
    41  - protobuf-devel python3-flake8 python3-future python3-protobuf \
     41 + protobuf-devel python3-flake8 python3-future python3-protobuf python3-importlib-metadata \
    42 42   python3-junit_xml rubygem-asciidoctor iptables libselinux-devel libbpf-devel
    43 43   # Disable sssd to avoid zdtm test failures in pty04 due to sssd socket
    44 44   ssh default sudo systemctl mask sssd
    skipped 45 lines
  • ■ ■ ■ ■ ■ ■
    scripts/crit-setup.py
    1  -import os
    2  -from distutils.core import setup
    3  - 
    4  -criu_version = "0.0.1"
    5  -env = os.environ
    6  - 
    7  -if 'CRIU_VERSION_MAJOR' in env and 'CRIU_VERSION_MINOR' in env:
    8  - criu_version = '{}.{}'.format(
    9  - env['CRIU_VERSION_MAJOR'],
    10  - env['CRIU_VERSION_MINOR']
    11  - )
    12  - 
    13  - if 'CRIU_VERSION_SUBLEVEL' in env and env['CRIU_VERSION_SUBLEVEL']:
    14  - criu_version += '.' + env['CRIU_VERSION_SUBLEVEL']
    15  - 
    16  -setup(name="crit",
    17  - version=criu_version,
    18  - description="CRiu Image Tool",
    19  - author="CRIU team",
    20  - author_email="[email protected]",
    21  - license="GPLv2",
    22  - url="https://github.com/checkpoint-restore/criu",
    23  - package_dir={'pycriu': 'lib/py'},
    24  - packages=["pycriu", "pycriu.images"],
    25  - scripts=["crit/crit"])
    26  - 
  • ■ ■ ■ ■ ■ ■
    scripts/uninstall_module.py
     1 +#!/usr/bin/python3
     2 +"""
     3 +`pip uninstall` doesn't support `--prefix`.
     4 +https://github.com/pypa/pip/issues/11213
     5 +"""
     6 +import argparse
     7 +import os
     8 +import shutil
     9 +import site
     10 +import subprocess
     11 +import sys
     12 + 
     13 +import importlib_metadata
     14 + 
     15 + 
     16 +def add_site_dir(prefix: str):
     17 + """
     18 + Add site directory with prefix to sys.path and update PYTHONPATH.
     19 + """
     20 + # If prefix is used, we need to make sure that we
     21 + # do not uninstall other packages from the system paths.
     22 + sys.path = []
     23 + site.PREFIXES = [prefix]
     24 + pkgs = site.getsitepackages()
     25 + for path in pkgs:
     26 + site.addsitedir(path)
     27 + if 'dist-packages' in path:
     28 + # Ubuntu / Debian might use both dist- and site- packages.
     29 + site.addsitedir(path.replace('dist-packages', 'site-packages'))
     30 + os.environ['PYTHONPATH'] = os.pathsep.join(sys.path)
     31 + 
     32 + 
     33 +def uninstall_module(package_name: str, prefix=None):
     34 + """
     35 + Enable support for '--prefix' with 'pip uninstall'.
     36 + """
     37 + dist_info_path = None
     38 + if prefix:
     39 + add_site_dir(prefix)
     40 + try:
     41 + dist_info_path = str(importlib_metadata.distribution(package_name)._path)
     42 + except importlib_metadata.PackageNotFoundError:
     43 + print(f"Skipping {package_name} as it is not installed.")
     44 + sys.exit(0)
     45 + 
     46 + command = [sys.executable, '-m', 'pip', 'uninstall', '-y', package_name]
     47 + try:
     48 + subprocess.check_call(command, env=os.environ)
     49 + if dist_info_path and os.path.isdir(dist_info_path):
     50 + # .dist-info files are not cleaned up when the package
     51 + # has been installed with --prefix.
     52 + # https://github.com/pypa/pip/issues/5573
     53 + shutil.rmtree(dist_info_path)
     54 + if 'dist-packages' in dist_info_path:
     55 + shutil.rmtree(dist_info_path.replace('dist-packages', 'site-packages'))
     56 + except subprocess.CalledProcessError as err:
     57 + print(f'Error uninstalling package {package_name}: {err}')
     58 + 
     59 + 
     60 +if __name__ == '__main__':
     61 + parser = argparse.ArgumentParser()
     62 + parser.add_argument('module_name', help='The name of the module to uninstall')
     63 + parser.add_argument('--prefix', help='The prefix where the module was installed')
     64 + args = parser.parse_args()
     65 + uninstall_module(args.module_name, args.prefix)
     66 + 
Please wait...
Page is in error, reload to recover