diff options
40 files changed, 91 insertions, 40 deletions
@@ -15,7 +15,7 @@ # limitations under the License. import sys -from pathlib import Path +from mesonbuild._pathlib import Path # If we're run uninstalled, add the script directory to sys.path to ensure that # we always import the correct mesonbuild modules even if PYTHONPATH is mangled diff --git a/mesonbuild/_pathlib.py b/mesonbuild/_pathlib.py new file mode 100644 index 0000000..aac2a1b --- /dev/null +++ b/mesonbuild/_pathlib.py @@ -0,0 +1,49 @@ +# Copyright 2020 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import typing as T + +# Python 3.5 does not have the strict kwarg for resolve and always +# behaves like calling resolve with strict=True in Python 3.6+ +# +# This module emulates the behavior of Python 3.6+ by in Python 3.5 by +# overriding the resolve method with a bit of custom logic +# +# TODO: Drop this module as soon as Python 3.5 support is dropped + +if T.TYPE_CHECKING: + from pathlib import Path +else: + if sys.version_info.major <= 3 and sys.version_info.minor <= 5: + + # Inspired by https://codereview.stackexchange.com/questions/162426/subclassing-pathlib-path + import pathlib + import os + + # Can not directly inherit from pathlib.Path because the __new__ + # operator of pathlib.Path() returns a {Posix,Windows}Path object. + class Path(type(pathlib.Path())): + def resolve(self, strict: bool = False) -> 'Path': + try: + return super().resolve() + except FileNotFoundError: + if strict: + raise + return Path(os.path.normpath(str(self))) + + else: + from pathlib import Path + +from pathlib import PurePath, PureWindowsPath, PurePosixPath diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 65a8932..3e883e9 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -14,7 +14,7 @@ from collections import OrderedDict from functools import lru_cache -from pathlib import Path +from .._pathlib import Path import enum import json import os @@ -917,7 +917,7 @@ class Backend: def get_regen_filelist(self): '''List of all files whose alteration means that the build definition needs to be regenerated.''' - deps = [os.path.join(self.build_to_src, df) + deps = [str(Path(self.build_to_src) / df) for df in self.interpreter.get_build_def_files()] if self.environment.is_cross_build(): deps.extend(self.environment.coredata.cross_files) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e7165d2..f816b1d 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -20,7 +20,7 @@ import subprocess from collections import OrderedDict from enum import Enum, unique import itertools -from pathlib import PurePath, Path +from .._pathlib import PurePath, Path from functools import lru_cache from . import backends diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 021a1da..86ddc1d 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -19,7 +19,7 @@ import xml.dom.minidom import xml.etree.ElementTree as ET import uuid import typing as T -from pathlib import Path, PurePath +from .._pathlib import Path, PurePath from . import backends from .. import build @@ -1000,7 +1000,7 @@ class Vs2010Backend(backends.Backend): if inc_dir not in file_inc_dirs[l]: file_inc_dirs[l].append(inc_dir) # Add include dirs to target as well so that "Go to Document" works in headers - if inc_dir not in target_inc_dirs: + if inc_dir not in target_inc_dirs: target_inc_dirs.append(inc_dir) # Split compile args needed to find external dependencies diff --git a/mesonbuild/cmake/client.py b/mesonbuild/cmake/client.py index 8057c3b..ce79e8e 100644 --- a/mesonbuild/cmake/client.py +++ b/mesonbuild/cmake/client.py @@ -21,7 +21,7 @@ from ..mesonlib import MachineChoice from .. import mlog from contextlib import contextmanager from subprocess import Popen, PIPE, TimeoutExpired -from pathlib import Path +from .._pathlib import Path import typing as T import json diff --git a/mesonbuild/cmake/common.py b/mesonbuild/cmake/common.py index bb0c4ae..21460ca 100644 --- a/mesonbuild/cmake/common.py +++ b/mesonbuild/cmake/common.py @@ -17,7 +17,7 @@ from ..mesonlib import MesonException from .. import mlog -from pathlib import Path +from .._pathlib import Path import typing as T class CMakeException(MesonException): diff --git a/mesonbuild/cmake/executor.py b/mesonbuild/cmake/executor.py index bf89822..0413b56 100644 --- a/mesonbuild/cmake/executor.py +++ b/mesonbuild/cmake/executor.py @@ -16,7 +16,7 @@ # or an interpreter-based tool. import subprocess as S -from pathlib import Path +from .._pathlib import Path from threading import Thread import typing as T import re diff --git a/mesonbuild/cmake/fileapi.py b/mesonbuild/cmake/fileapi.py index 4ef0caf..1b6c30d 100644 --- a/mesonbuild/cmake/fileapi.py +++ b/mesonbuild/cmake/fileapi.py @@ -15,7 +15,7 @@ from .common import CMakeException, CMakeBuildFile, CMakeConfiguration import typing as T from .. import mlog -from pathlib import Path +from .._pathlib import Path import json import re @@ -74,6 +74,7 @@ class CMakeFileAPI: # Debug output debug_json = self.build_dir / '..' / 'fileAPI.json' + debug_json = debug_json.resolve() debug_json.write_text(json.dumps(index, indent=2)) mlog.cmd_ci_include(debug_json.as_posix()) diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py index aa43ae4..cad4509 100644 --- a/mesonbuild/cmake/interpreter.py +++ b/mesonbuild/cmake/interpreter.py @@ -26,7 +26,7 @@ from ..mesondata import mesondata from ..compilers.compilers import lang_suffixes, header_suffixes, obj_suffixes, lib_suffixes, is_header from enum import Enum from functools import lru_cache -from pathlib import Path +from .._pathlib import Path import typing as T import re from os import environ diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py index bee011c..518db4f 100644 --- a/mesonbuild/cmake/traceparser.py +++ b/mesonbuild/cmake/traceparser.py @@ -21,7 +21,7 @@ from .. import mlog from ..mesonlib import version_compare import typing as T -from pathlib import Path +from .._pathlib import Path import re import json import textwrap diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 9f2f106..e85ee6d 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pathlib import Path +from .._pathlib import Path import typing as T import subprocess, os diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index dca09ea..3c2c53c 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -28,7 +28,7 @@ import os import re import subprocess import typing as T -from pathlib import Path +from ..._pathlib import Path from ... import arglist from ... import mesonlib diff --git a/mesonbuild/compilers/mixins/pgi.py b/mesonbuild/compilers/mixins/pgi.py index 61dee8d..bc16cac 100644 --- a/mesonbuild/compilers/mixins/pgi.py +++ b/mesonbuild/compilers/mixins/pgi.py @@ -16,7 +16,7 @@ import typing as T import os -from pathlib import Path +from ..._pathlib import Path from ..compilers import clike_debug_args, clike_optimization_args diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 9d7cb49..710d8c9 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -16,7 +16,7 @@ from . import mlog, mparser import pickle, os, uuid import sys from itertools import chain -from pathlib import PurePath +from ._pathlib import PurePath from collections import OrderedDict, defaultdict from .mesonlib import ( MesonException, EnvironmentException, MachineChoice, PerMachine, diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index e622859..14db6a5 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -27,7 +27,7 @@ import textwrap import platform import typing as T from enum import Enum -from pathlib import Path, PurePath +from .._pathlib import Path, PurePath from .. import mlog from .. import mesonlib diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index 370fa72..404c279 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -16,7 +16,7 @@ import os import re import functools import typing as T -from pathlib import Path +from .._pathlib import Path from .. import mlog from .. import mesonlib diff --git a/mesonbuild/dependencies/hdf5.py b/mesonbuild/dependencies/hdf5.py index 21f4e71..0d3db39 100644 --- a/mesonbuild/dependencies/hdf5.py +++ b/mesonbuild/dependencies/hdf5.py @@ -19,7 +19,7 @@ import os import re import shutil import subprocess -from pathlib import Path +from .._pathlib import Path from ..mesonlib import OrderedSet, join_args from .base import ( diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 15055aa..f41abc8 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -14,7 +14,7 @@ # This file contains the detection logic for miscellaneous external dependencies. -from pathlib import Path +from .._pathlib import Path import functools import re import sysconfig diff --git a/mesonbuild/dependencies/scalapack.py b/mesonbuild/dependencies/scalapack.py index 0147e0b..f8b1ee1 100644 --- a/mesonbuild/dependencies/scalapack.py +++ b/mesonbuild/dependencies/scalapack.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pathlib import Path +from .._pathlib import Path import functools import os import typing as T diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index eb67a45..9f54b0a 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -36,7 +36,7 @@ from .modules import ModuleReturnValue, ExtensionModule from .cmake import CMakeInterpreter from .backend.backends import TestProtocol, Backend -from pathlib import Path, PurePath +from ._pathlib import Path, PurePath import os import shutil import uuid diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py index 1e58207..aa6afb9 100644 --- a/mesonbuild/mcompile.py +++ b/mesonbuild/mcompile.py @@ -21,7 +21,7 @@ import sys import shutil import typing as T from collections import defaultdict -from pathlib import Path +from ._pathlib import Path from . import mlog from . import mesonlib diff --git a/mesonbuild/mdist.py b/mesonbuild/mdist.py index 6985ca9..f6ca0c0 100644 --- a/mesonbuild/mdist.py +++ b/mesonbuild/mdist.py @@ -21,7 +21,7 @@ import subprocess import hashlib import json from glob import glob -from pathlib import Path +from ._pathlib import Path from mesonbuild.environment import detect_ninja from mesonbuild.mesonlib import windows_proof_rmtree, MesonException from mesonbuild.wrap import wrap diff --git a/mesonbuild/mesondata.py b/mesonbuild/mesondata.py index 1f223c2..f2e35f1 100644 --- a/mesonbuild/mesondata.py +++ b/mesonbuild/mesondata.py @@ -19,7 +19,7 @@ #### -from pathlib import Path +from ._pathlib import Path import typing as T if T.TYPE_CHECKING: diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 0b614ba..352c5ca 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -13,7 +13,7 @@ # limitations under the License. """A library of random helper functionality.""" -from pathlib import Path +from ._pathlib import Path import sys import stat import time diff --git a/mesonbuild/minit.py b/mesonbuild/minit.py index 4a38313..38954fa 100644 --- a/mesonbuild/minit.py +++ b/mesonbuild/minit.py @@ -14,7 +14,7 @@ """Code that creates simple startup projects.""" -from pathlib import Path +from ._pathlib import Path from enum import Enum import subprocess import shutil diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index f7cbf80..4c1e8ea 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -28,7 +28,7 @@ from . import mlog from .backend import backends from .mparser import BaseNode, FunctionNode, ArrayNode, ArgumentNode, StringNode from .interpreter import Interpreter -from pathlib import PurePath +from ._pathlib import PurePath import typing as T import os import argparse diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index f8707b6..eefb308 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -19,7 +19,7 @@ import time import platform import typing as T from contextlib import contextmanager -from pathlib import Path +from ._pathlib import Path """This is (mostly) a standalone module used to write logging information about Meson runs. Some output goes to screen, diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 5ba1e38..85088b7 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -14,7 +14,7 @@ import typing as T import hashlib -from pathlib import Path, PurePath, PureWindowsPath +from .._pathlib import Path, PurePath, PureWindowsPath from .. import mlog from . import ExtensionModule diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 1cb7698..912c9ff 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -13,7 +13,7 @@ # limitations under the License. import os, types -from pathlib import PurePath +from .._pathlib import PurePath from .. import build from .. import dependencies diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index ceabd76..87dfc33 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -17,7 +17,7 @@ import json import shutil import typing as T -from pathlib import Path +from .._pathlib import Path from .. import mesonlib from ..mesonlib import MachineChoice, MesonException from . import ExtensionModule diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py index 7bb761f..fdc5cbf 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/unstable_external_project.py @@ -13,7 +13,7 @@ # limitations under the License. import os, subprocess, shlex -from pathlib import Path +from .._pathlib import Path import typing as T from . import ExtensionModule, ModuleReturnValue diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py index df0d796..422dad2 100755 --- a/mesonbuild/msubprojects.py +++ b/mesonbuild/msubprojects.py @@ -1,6 +1,6 @@ import os, subprocess import argparse -from pathlib import Path +from ._pathlib import Path from . import mlog from .mesonlib import quiet_git, verbose_git, GitException, Popen_safe, MesonException diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 0e24c6d..ee1d412 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -14,7 +14,7 @@ # A tool to run tests in many different ways. -from pathlib import Path +from ._pathlib import Path from collections import namedtuple from copy import deepcopy import argparse diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 774544a..a0a4801 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -27,7 +27,7 @@ import sys import configparser import typing as T -from pathlib import Path +from .._pathlib import Path from . import WrapMode from .. import coredata from ..mesonlib import verbose_git, quiet_git, GIT, ProgressBar, MesonException diff --git a/run_meson_command_tests.py b/run_meson_command_tests.py index 7bc6185..1375988 100755 --- a/run_meson_command_tests.py +++ b/run_meson_command_tests.py @@ -19,7 +19,7 @@ import tempfile import unittest import subprocess import zipapp -from pathlib import Path +from mesonbuild._pathlib import Path from mesonbuild.mesonlib import windows_proof_rmtree, python_command, is_windows from mesonbuild.coredata import version as meson_version diff --git a/run_mypy.py b/run_mypy.py index db578be..51b74df 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -15,6 +15,7 @@ modules = [ 'mesonbuild/wrap', # specific files + 'mesonbuild/_pathlib.py', 'mesonbuild/arglist.py', # 'mesonbuild/coredata.py', 'mesonbuild/dependencies/boost.py', diff --git a/run_project_tests.py b/run_project_tests.py index e25729a..8749957 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -17,7 +17,7 @@ from concurrent.futures import ProcessPoolExecutor, CancelledError from enum import Enum from io import StringIO -from pathlib import Path, PurePath +from mesonbuild._pathlib import Path, PurePath import argparse import functools import itertools diff --git a/run_tests.py b/run_tests.py index 0f02636..eae7033 100755 --- a/run_tests.py +++ b/run_tests.py @@ -25,7 +25,7 @@ import argparse from io import StringIO from enum import Enum from glob import glob -from pathlib import Path +from mesonbuild._pathlib import Path from unittest import mock from mesonbuild import compilers from mesonbuild import dependencies diff --git a/run_unittests.py b/run_unittests.py index 7ddf17d..3275a10 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -39,7 +39,7 @@ from unittest import mock from configparser import ConfigParser from contextlib import contextmanager from glob import glob -from pathlib import (PurePath, Path) +from mesonbuild._pathlib import (PurePath, Path) from distutils.dir_util import copy_tree import typing as T |