From 8ce942e250eca6874d883affef8951ea8938f63b Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Mon, 11 Nov 2024 13:06:42 +0100 Subject: [PATCH] Drop support for Conan v1 --- .github/workflows/test_package.yml | 23 +++-------- changelog.md | 4 ++ conanfile.py | 9 ++--- core/conanfile.py | 9 ++--- core/embedded_python_tools.py | 62 ------------------------------ core/test_package/conanfile.py | 6 +-- test_package/conanfile.py | 11 +----- 7 files changed, 19 insertions(+), 105 deletions(-) delete mode 100644 core/embedded_python_tools.py diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index 96c6da0..9d23f93 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -8,37 +8,26 @@ jobs: matrix: os: [windows-latest, ubuntu-latest, macos-latest] embedded-py: [3.11.5, 3.12.4] - conan: - - version: 1 - args: lumicks/testing --build=missing - - version: 2 - args: --user=lumicks --channel=testing --build=missing - name: "${{ matrix.os }}, ${{ matrix.embedded-py }}, v${{ matrix.conan.version }}" + name: "${{ matrix.os }}, ${{ matrix.embedded-py }}" env: - create_pck: conan create . ${{ matrix.conan.args }} -o embedded_python-core/*:version=${{ matrix.embedded-py }} + create_pck: conan create . -o embedded_python-core/*:version=${{ matrix.embedded-py }} --build=missing steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.12" - if: runner.os == 'macOS' name: Set up CC/CXX env run: | echo CC=/usr/bin/clang >> $GITHUB_ENV echo CXX=/usr/bin/clang++ >> $GITHUB_ENV - - if: matrix.conan.version == '1' - name: Install Conan v1 - run: | - python -m pip install conan==1.64.1 - conan profile new default --detect - - if: matrix.conan.version == '2' - name: Install Conan v2 + - name: Install Conan run: | - python -m pip install conan==2.4.1 + python -m pip install conan==2.9.2 conan profile detect - name: Test core - run: conan create ./core ${{ matrix.conan.args }} -o embedded_python-core/*:version=${{ matrix.embedded-py }} + run: cd core && ${{ env.create_pck }} - name: Test baseline run: ${{ env.create_pck }} - name: Test with numpy env diff --git a/changelog.md b/changelog.md index 672bea0..5183c01 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## v1.10.0 | TBD + +- Dropped support for Conan v1. + ## v1.9.1 | 2024-06-17 - Fixed an issue where calling CMake with `-DPython_EXECUTABLE=` created conflicts with the embedded Python (either a loud version error, or silently passing the wrong library paths). Some IDEs would pass this flag implicitly and it would hijack the `find_package(Python)` call used internally by this recipe. Now, we specifically protect against this since there should be no traces of system Python in a project that wishes to embed it. diff --git a/conanfile.py b/conanfile.py index f379d89..7a7274f 100644 --- a/conanfile.py +++ b/conanfile.py @@ -4,13 +4,13 @@ from conan import ConanFile from conan.tools import files, scm -required_conan_version = ">=1.59.0" +required_conan_version = ">=2.5.0" # noinspection PyUnresolvedReferences class EmbeddedPython(ConanFile): name = "embedded_python" - version = "1.9.1" # of the Conan package, `embedded_python-core:version` is the Python version + version = "1.10.0" # of the Conan package, `embedded_python-core:version` is the Python version license = "PSFL" description = "Embedded distribution of Python" topics = "embedded", "python" @@ -31,11 +31,10 @@ class EmbeddedPython(ConanFile): "setuptools_version": "69.5.1", "wheel_version": "0.43.0", } - short_paths = True # some of the pip packages go over the 260 char path limit on Windows exports_sources = "embedded_python.cmake" def requirements(self): - self.requires(f"embedded_python-core/1.3.1@{self.user}/{self.channel}") + self.requires(f"embedded_python-core/1.4.0@{self.user}/{self.channel}") @property def pyversion(self): @@ -202,9 +201,7 @@ def package(self): self._gather_packages(license_folder) def package_info(self): - self.env_info.PYTHONPATH.append(self.package_folder) self.cpp_info.set_property("cmake_build_modules", ["embedded_python.cmake"]) - self.cpp_info.build_modules = ["embedded_python.cmake"] self.cpp_info.includedirs = [] self.cpp_info.bindirs = [] self.cpp_info.libdirs = [] diff --git a/core/conanfile.py b/core/conanfile.py index 647436a..79b8bc1 100644 --- a/core/conanfile.py +++ b/core/conanfile.py @@ -7,13 +7,13 @@ from conan.errors import ConanInvalidConfiguration from conan.tools import files, scm -required_conan_version = ">=1.59.0" +required_conan_version = ">=2.5" # noinspection PyUnresolvedReferences class EmbeddedPythonCore(ConanFile): name = "embedded_python-core" - version = "1.3.1" # of the Conan package, `options.version` is the Python version + version = "1.4.0" # of the Conan package, `options.version` is the Python version license = "PSFL" description = "The core embedded Python (no extra pip packages)" topics = "embedded", "python" @@ -27,7 +27,7 @@ class EmbeddedPythonCore(ConanFile): default_options = { "zip_stdlib": "stored", } - exports_sources = "embedded_python_tools.py", "embedded_python*.cmake" + exports_sources = "embedded_python*.cmake" package_type = "shared-library" def validate(self): @@ -279,7 +279,6 @@ def package(self): src = self.build_folder dst = pathlib.Path(self.package_folder, "embedded_python") files.copy(self, "embedded_python*.cmake", src, dst=self.package_folder) - files.copy(self, "embedded_python_tools.py", src, dst=self.package_folder) license_folder = pathlib.Path(self.package_folder, "licenses") if self.settings.os == "Windows": @@ -321,11 +320,9 @@ def package(self): self._zip_stdlib(dst) def package_info(self): - self.env_info.PYTHONPATH.append(self.package_folder) self.cpp_info.set_property( "cmake_build_modules", ["embedded_python-core.cmake", "embedded_python-tools.cmake"] ) - self.cpp_info.build_modules = ["embedded_python-core.cmake", "embedded_python-tools.cmake"] prefix = pathlib.Path(self.package_folder) / "embedded_python" self.cpp_info.includedirs = [str(prefix / "include")] if self.settings.os == "Windows": diff --git a/core/embedded_python_tools.py b/core/embedded_python_tools.py deleted file mode 100644 index 574959a..0000000 --- a/core/embedded_python_tools.py +++ /dev/null @@ -1,62 +0,0 @@ -import os -import shutil -import pathlib -from conan.tools import files - - -def _symlink_compat(conanfile, src, dst): - """On Windows, symlinks require admin privileges, so we use a directory junction instead""" - if conanfile.settings.os == "Windows": - import _winapi - - try: - _winapi.CreateJunction(str(src), str(dst)) - except OSError: - files.copy(conanfile, "*", src, dst) - else: - os.symlink(src, dst) - - -def symlink_import(conanfile, dst="bin/python/interpreter", bin="bin"): - """Copying the entire embedded Python environment is extremely slow, so we just symlink it - - Usage: - ```python - def imports(self): - import embedded_python_tools - embedded_python_tools.symlink_import(self, dst="bin/python/interpreter") - ``` - - The symlink points to the Conan package location. We still want to copy in `python*.dll` and - `python*.zip` right next to the executable so that they can be found, but the rest of - the Python environment is in a subfolder: - - bin - |- python/interpreter - | |- Lib - | \- ... - |-
.exe - |- python*.dll - |- python*.zip - \- ... - """ - dst = pathlib.Path(dst).absolute() - if not dst.parent.exists(): - dst.parent.mkdir(parents=True) - - # Clean the `dst` path if it already exists - # Note: we use `os.path.lexists` here specifically to also detect and clean up old broken symlinks - if os.path.lexists(dst): - try: # to remove any existing junction/symlink - os.remove(dst) - except: # this seems to be the only way to find out this is not a junction - shutil.rmtree(dst) - root_folder = pathlib.Path(__file__).resolve().parent - src = root_folder / "embedded_python" - _symlink_compat(conanfile, src, dst) - - bin = pathlib.Path(bin).absolute() - files.copy(conanfile, "python*.dll", src, bin, keep_path=False) - files.copy(conanfile, "libpython*.so*", src / "lib", bin, keep_path=False) - files.copy(conanfile, "libpython*.dylib", src / "lib", bin, keep_path=False) - files.copy(conanfile, "python*.zip", src, bin, keep_path=False) diff --git a/core/test_package/conanfile.py b/core/test_package/conanfile.py index da5ca97..4730ee9 100644 --- a/core/test_package/conanfile.py +++ b/core/test_package/conanfile.py @@ -1,7 +1,6 @@ import sys import pathlib import subprocess -import conan from conan import ConanFile from conan.tools.cmake import CMake, cmake_layout @@ -33,10 +32,7 @@ def build(self): @property def _core_package_path(self): - if conan.__version__.startswith("2"): - return pathlib.Path(self.dependencies["embedded_python-core"].package_folder) - else: - return pathlib.Path(self.deps_cpp_info["embedded_python-core"].rootpath) + return pathlib.Path(self.dependencies["embedded_python-core"].package_folder) @property def _py_exe(self): diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 4e0e19f..0eb3949 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,7 +1,6 @@ import sys import pathlib import subprocess -import conan from conan import ConanFile from conan.tools.cmake import CMake, cmake_layout @@ -27,17 +26,11 @@ class TestEmbeddedPython(ConanFile): @property def _core_package_path(self): - if conan.__version__.startswith("2"): - return pathlib.Path(self.dependencies["embedded_python-core"].package_folder) - else: - return pathlib.Path(self.deps_cpp_info["embedded_python-core"].rootpath) + return pathlib.Path(self.dependencies["embedded_python-core"].package_folder) @property def _package_path(self): - if conan.__version__.startswith("2"): - return pathlib.Path(self.dependencies["embedded_python"].package_folder) - else: - return pathlib.Path(self.deps_cpp_info["embedded_python"].rootpath) + return pathlib.Path(self.dependencies["embedded_python"].package_folder) @property def _py_exe(self):