From a1adce322cbe9306907a4fac0d0c6b58971ca6cc Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Mon, 16 Dec 2019 16:02:49 +0000 Subject: _compat.py: Add module to handle version compatibility in python This adds a module that allows us to patch some utilities when they are version conflicts. Let's keep them all in a specific place, which will make things easier when removing support for previous versions whenever possible. --- src/buildstream/__init__.py | 1 + src/buildstream/_compat.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/buildstream/_compat.py diff --git a/src/buildstream/__init__.py b/src/buildstream/__init__.py index c78fcbbf6..40746d735 100644 --- a/src/buildstream/__init__.py +++ b/src/buildstream/__init__.py @@ -28,6 +28,7 @@ if "_BST_COMPLETION" not in os.environ: __version__ = get_versions()["version"] del get_versions + from . import _compat from .utils import UtilError, ProgramNotFoundError from .sandbox import Sandbox, SandboxFlags, SandboxCommandError from .types import Scope, Consistency, CoreWarnings diff --git a/src/buildstream/_compat.py b/src/buildstream/_compat.py new file mode 100644 index 000000000..1c8c99d73 --- /dev/null +++ b/src/buildstream/_compat.py @@ -0,0 +1,32 @@ +# +# Copyright (C) 2019 Bloomberg Finance LP +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . +# + +# This module contains some patches to make it easier to handle different +# python versions. Patches can be removed once we decide a specific version +# does not need to be supported anymore. + +import sys + +# Python < 3.7 +if sys.version_info[:2] < (3, 7): + # multiprocessing.Process got a 'close' method on python3.7 + # A no-op is fine for previous versions + import multiprocessing + def _close(self): + pass + + multiprocessing.Process.close = _close -- cgit v1.2.1