From 1f805f0345864f40182ac627b39c8acd20393540 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 20 May 2024 01:52:26 -0400 Subject: [PATCH 01/11] feat: use scikit-build-core Signed-off-by: Henry Schreiner --- .github/workflows/build.yml | 23 +------ CMakeLists.txt | 4 +- MANIFEST.in | 14 ----- constraints-ci.txt | 2 - pyproject.toml | 118 ++++++++++++++++++++++++++---------- requirements-dev.txt | 5 -- requirements-repair.txt | 1 - requirements-test.txt | 4 -- setup.cfg | 3 - setup.py | 73 ---------------------- 10 files changed, 92 insertions(+), 155 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 constraints-ci.txt delete mode 100644 requirements-dev.txt delete mode 100644 requirements-repair.txt delete mode 100644 requirements-test.txt delete mode 100644 setup.cfg delete mode 100755 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1a2c217..2db64b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,43 +105,26 @@ jobs: test_sdist: name: Test SDist with python ${{ matrix.python }} needs: [build_sdist] - # 22.04 doesn't have 2.7 or 3.6 - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - python: ["2.7", "3.6", "3.12"] + python: ["3.7", "3.12"] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 name: Install Python ${{ matrix.python }} - if: matrix.python != '2.7' with: python-version: ${{ matrix.python }} - - name: Install Ubuntu Python 2.7 - if: matrix.python == '2.7' - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends python2 python3-virtualenv - virtualenv -p python2 ${HOME}/cp27 - ${HOME}/cp27/bin/python -m pip install -U pip - ${HOME}/cp27/bin/python -m pip install -U setuptools wheel - echo "${HOME}/cp27/bin" >> $GITHUB_PATH - - uses: actions/download-artifact@v4 with: name: cibw-sdist path: sdist - name: Install SDist - env: - SKBUILD_CONFIGURE_OPTIONS: "-DBUILD_CMAKE_FROM_SOURCE:BOOL=OFF" - run: pip install sdist/*.tar.gz - - - name: Install test dependencies - run: pip install -r requirements-test.txt + run: pip install sdist/*.tar.gz -Ccmake.define.BUILD_CMAKE_FROM_SOURCE=OFF - name: Test installed SDist run: pytest ./tests diff --git a/CMakeLists.txt b/CMakeLists.txt index d0ad97f..2b97da8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,5 +145,5 @@ if(CMAKE_CROSS_COMPILE OR NOT DEFINED ENV{DIST_EXTRA_CONFIG}) endif() endif() -install(FILES ${Ninja_SOURCE_DIR}/misc/ninja_syntax.py DESTINATION src/ninja) -install(PROGRAMS ${ninja_executable} DESTINATION src/ninja/data/bin) +install(FILES ${Ninja_SOURCE_DIR}/misc/ninja_syntax.py DESTINATION ninja) +install(PROGRAMS ${ninja_executable} DESTINATION ninja/data/bin) diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index f4adf95..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,14 +0,0 @@ -include CMakeLists.txt -include NinjaUrls.cmake -include requirements-test.txt -include HISTORY.rst -include README.rst -include LICENSE_Apache_20 - -recursive-exclude _skbuild * -recursive-exclude Ninja-src * - -include src/ninja/_version.py -include src/ninja/_version.pyi -include src/ninja/__init__.pyi -include src/ninja/py.typed diff --git a/constraints-ci.txt b/constraints-ci.txt deleted file mode 100644 index 806e700..0000000 --- a/constraints-ci.txt +++ /dev/null @@ -1,2 +0,0 @@ -cmake==3.22.6 -ninja==1.11.1.1 diff --git a/pyproject.toml b/pyproject.toml index be49ce6..f2d0bbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,28 +1,93 @@ [build-system] -requires = [ - "setuptools >=42", - "setuptools-scm[toml]", - "scikit-build", +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" + +[project] +name = "ninja" +dynamic = ["version", "readme"] +description = "Ninja is a small build system with a focus on speed" +authors = [ + { name = "Jean-Christophe Fillion-Robin", email = "scikit-build@googlegroups.com" }, +] +keywords = [ + "build", + "c++", + "cross-compilation", + "cross-platform", + "fortran", + "ninja", +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: C", + "Programming Language :: C++", + "Programming Language :: Fortran", + "Programming Language :: Python", + "Topic :: Software Development :: Build Tools", + "Typing :: Typed", ] -build-backend = "setuptools.build_meta" -[tool.setuptools_scm] -write_to = "src/ninja/_version.py" +[project.optional-dependencies] +test = [ + "coverage>=4.2", + "importlib_metadata>=2.0", + "pytest-cov>=2.7.1", + "pytest>=4.5.0", +] + +[project.scripts] +ninja = "ninja:ninja" + +[project.urls] +"Bug Tracker" = "https://github.com/scikit-build/ninja-python-distributions/issues" +Documentation = "https://github.com/scikit-build/ninja-python-distributions#readme" +Download = "https://github.com/ninja-build/ninja/releases" +Homepage = "http://ninja-build.org/" +"Mailing list" = "https://groups.google.com/forum/#!forum/scikit-build" +"Source Code" = "https://github.com/scikit-build/ninja-python-distributions" + +[tool.scikit-build] +minimum-version = "0.9" +build-dir = "build/{wheel_tag}" +wheel.py-api = "py2.py3" +wheel.expand-macos-universal-tags = true +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +metadata.readme.provider = "scikit_build_core.metadata.fancy_pypi_readme" + [tool.cibuildwheel] build = "cp39-*" build-verbosity = 1 -before-all = [ - 'pipx install -f --pip-args="-c {project}/constraints-ci.txt" cmake', - 'cmake --version', -] -before-build = "pip install -r requirements-repair.txt" -repair-wheel-command = "python scripts/repair_wheel.py -w {dest_dir} {wheel}" test-extras = "test" test-command = "pytest {project}/tests" test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"] environment-pass = ["SETUPTOOLS_SCM_PRETEND_VERSION"] +[[tool.scikit-build.generate]] +path = "package/_version.py" +template = ''' +version = "${version}" +''' + +[tool.setuptools_scm] + +[tool.hatch.metadata.hooks.fancy-pypi-readme] +content-type = "text/x-rst" + +[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]] +path = "README.rst" + +[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]] +path = "HISTORY.rst" + +[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]] +pattern = ".. :changelog:" +replacement = "" + [[tool.cibuildwheel.overrides]] select = "*-manylinux_{x86_64,i686}" manylinux-x86_64-image = "manylinux1" @@ -32,22 +97,15 @@ environment = { LDFLAGS = "-static-libstdc++" } [tool.cibuildwheel.macos.environment] MACOSX_DEPLOYMENT_TARGET = "10.9" -[tool.cibuildwheel.windows] -before-all = [ - 'pipx install -f --pip-args="-c {project}/constraints-ci.txt" cmake', - 'cmake --version', - 'pipx install -f --pip-args="-c {project}/constraints-ci.txt" ninja', - 'ninja --version', -] - [[tool.cibuildwheel.overrides]] select = "*-musllinux_*" environment = { LDFLAGS = "-static-libstdc++ -static-libgcc" } - [tool.ruff] -select = [ - "E", "F", "W", # flake8 +src = ["src"] + +[tool.ruff.lint] +extend-select = [ "B", # flake8-bugbear "I", # isort "ARG", # flake8-unused-arguments @@ -66,21 +124,19 @@ select = [ "NPY", # NumPy specific rules "PD", # pandas-vet ] -extend-ignore = [ +ignore = [ "PLR", # Design related pylint codes "E501", # Line too long "RUF005", # Python 3 needed "B904", # Python 3 needed # "SIM105", # Python 3 needed ] -src = ["src"] -unfixable = [ - "T20", # Removes print statements - "F841", # Removes unused variables -] -exclude = ["src/ninja/version.py"] flake8-unused-arguments.ignore-variadic-names = true [tool.ruff.per-file-ignores] "*.pyi" = ["ARG001"] "noxfile.py" = ["PLW0603"] # Could be fixed if Python 2 dropped + +[tool.pytest.ini_config] +testpaths = ["tests"] +addopts = ["-v", "--cov", "--cov-report", "xml"] diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index d26e2fb..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,5 +0,0 @@ --r requirements-test.txt --r requirements-repair.txt -scikit-build>=0.10.0 -setuptools>=28.0.0 -wheel>=0.34 diff --git a/requirements-repair.txt b/requirements-repair.txt deleted file mode 100644 index de121f3..0000000 --- a/requirements-repair.txt +++ /dev/null @@ -1 +0,0 @@ -wheel>=0.40.0 diff --git a/requirements-test.txt b/requirements-test.txt deleted file mode 100644 index bd793e9..0000000 --- a/requirements-test.txt +++ /dev/null @@ -1,4 +0,0 @@ -coverage>=4.2 -importlib_metadata>=2.0 -pytest>=4.5.0 -pytest-cov>=2.7.1 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 0cd9906..0000000 --- a/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[tool:pytest] -testpaths = tests -addopts = -v --cov --cov-report xml diff --git a/setup.py b/setup.py deleted file mode 100755 index ab7c4a9..0000000 --- a/setup.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from distutils.text_file import TextFile - -from skbuild import setup - -with open('README.rst', 'r') as fp: - readme = fp.read() - -with open('HISTORY.rst', 'r') as fp: - history = fp.read().replace('.. :changelog:', '') - - -def parse_requirements(filename): - with open(filename, 'r') as file: - return TextFile(filename, file).readlines() - - -requirements = [] -test_requirements = parse_requirements('requirements-test.txt') - - -setup( - name='ninja', - - author='Jean-Christophe Fillion-Robin', - author_email='scikit-build@googlegroups.com', - - package_dir={'': 'src'}, - packages=['ninja'], - package_data={"ninja": ["py.typed"]}, - - entry_points={ - 'console_scripts': [ - 'ninja=ninja:ninja' - ] - }, - - url=r'http://ninja-build.org/', - download_url=r'https://github.com/ninja-build/ninja/releases', - project_urls={ - "Documentation": "https://github.com/scikit-build/ninja-python-distributions#readme", - "Source Code": "https://github.com/scikit-build/ninja-python-distributions", - "Mailing list": "https://groups.google.com/forum/#!forum/scikit-build", - "Bug Tracker": "https://github.com/scikit-build/ninja-python-distributions/issues", - }, - - description=r'Ninja is a small build system with a focus on speed', - - long_description=readme + '\n\n' + history, - long_description_content_type='text/x-rst', - - classifiers=[ - 'License :: OSI Approved :: Apache Software License', - 'License :: OSI Approved :: BSD License', - 'Programming Language :: C', - 'Programming Language :: C++', - 'Programming Language :: Fortran', - 'Programming Language :: Python', - 'Operating System :: OS Independent', - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Build Tools', - 'Typing :: Typed', - ], - - license='Apache 2.0', - - keywords='ninja build c++ fortran cross-platform cross-compilation', - - extras_require={"test": test_requirements}, -) From 3523c75a7946cc694a4ca8f7e29bb8a8ac733fd0 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 20 May 2024 02:07:13 -0400 Subject: [PATCH 02/11] Update pyproject.toml --- pyproject.toml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f2d0bbd..e10d704 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,14 +59,6 @@ metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" metadata.readme.provider = "scikit_build_core.metadata.fancy_pypi_readme" -[tool.cibuildwheel] -build = "cp39-*" -build-verbosity = 1 -test-extras = "test" -test-command = "pytest {project}/tests" -test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"] -environment-pass = ["SETUPTOOLS_SCM_PRETEND_VERSION"] - [[tool.scikit-build.generate]] path = "package/_version.py" template = ''' @@ -88,10 +80,17 @@ path = "HISTORY.rst" pattern = ".. :changelog:" replacement = "" + +[tool.cibuildwheel] +build = "cp39-*" +build-verbosity = 1 +test-extras = "test" +test-command = "pytest {project}/tests" +test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"] +environment-pass = ["SETUPTOOLS_SCM_PRETEND_VERSION"] + [[tool.cibuildwheel.overrides]] select = "*-manylinux_{x86_64,i686}" -manylinux-x86_64-image = "manylinux1" -manylinux-i686-image = "manylinux1" environment = { LDFLAGS = "-static-libstdc++" } [tool.cibuildwheel.macos.environment] From 73c7b5743966d6c912abf78a1892978c164788c3 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 20 May 2024 02:14:37 -0400 Subject: [PATCH 03/11] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e10d704..40fd7c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,7 @@ metadata.readme.provider = "scikit_build_core.metadata.fancy_pypi_readme" [[tool.scikit-build.generate]] -path = "package/_version.py" +path = "ninja/_version.py" template = ''' version = "${version}" ''' From 237655565d223523b3025639fced65c93d1cca0c Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 20 May 2024 02:50:09 -0400 Subject: [PATCH 04/11] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2db64b2..fb77955 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -124,7 +124,7 @@ jobs: path: sdist - name: Install SDist - run: pip install sdist/*.tar.gz -Ccmake.define.BUILD_CMAKE_FROM_SOURCE=OFF + run: pip install $(ls sdist/*.tar.gz)[test] -Ccmake.define.BUILD_CMAKE_FROM_SOURCE=OFF - name: Test installed SDist run: pytest ./tests From a5399ebe935af4ec26952b300d1945b2783338f1 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 20 May 2024 02:54:33 -0400 Subject: [PATCH 05/11] Update CMakeLists.txt --- CMakeLists.txt | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b97da8..cbf8073 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,19 +120,8 @@ ExternalProject_add(build_ninja set(ninja_executable ${Ninja_BINARY_DIR}/ninja${CMAKE_EXECUTABLE_SUFFIX}) set(NINJA_BUILD_LAST_STEP "build") -# This should not be stripped or tested if cross-compiling on Windows +# This should not be tested if cross-compiling on Windows if(CMAKE_CROSS_COMPILE OR NOT DEFINED ENV{DIST_EXTRA_CONFIG}) - find_program(STRIP_EXECUTABLE strip) - if(STRIP_EXECUTABLE) - ExternalProject_Add_Step(build_ninja strip_executables - DEPENDEES ${NINJA_BUILD_LAST_STEP} - COMMENT "Stripping CMake executables" - COMMAND ${STRIP_EXECUTABLE} ${ninja_executable} - USES_TERMINAL 1 - ) - set(NINJA_BUILD_LAST_STEP "strip_executables") - endif() - if(RUN_NINJA_TEST) ExternalProject_Add_Step(build_ninja run_ninja_test_suite DEPENDEES ${NINJA_BUILD_LAST_STEP} From 7749a80919cb9e732f15c9952b53e7b6f1a57ece Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 20 May 2024 03:07:14 -0400 Subject: [PATCH 06/11] Update CMakeLists.txt --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbf8073..3d264e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ endif() #----------------------------------------------------------------------------- # Build from source #----------------------------------------------------------------------------- -set(Ninja_BINARY_DIR ${CMAKE_BINARY_DIR}/Ninja-build) +set(Ninja_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/Ninja-build") # cache arguments set(_cache_args ) foreach(var_name IN ITEMS @@ -117,7 +117,7 @@ ExternalProject_add(build_ninja DEPENDS download_ninja_source ) -set(ninja_executable ${Ninja_BINARY_DIR}/ninja${CMAKE_EXECUTABLE_SUFFIX}) +set(ninja_executable "${Ninja_BINARY_DIR}/ninja${CMAKE_EXECUTABLE_SUFFIX}") set(NINJA_BUILD_LAST_STEP "build") # This should not be tested if cross-compiling on Windows @@ -126,13 +126,13 @@ if(CMAKE_CROSS_COMPILE OR NOT DEFINED ENV{DIST_EXTRA_CONFIG}) ExternalProject_Add_Step(build_ninja run_ninja_test_suite DEPENDEES ${NINJA_BUILD_LAST_STEP} COMMENT "Running Ninja test suite" - COMMAND ${Ninja_BINARY_DIR}/ninja_test${CMAKE_EXECUTABLE_SUFFIX} - WORKING_DIRECTORY ${Ninja_BINARY_DIR} + COMMAND "${Ninja_BINARY_DIR}/ninja_test${CMAKE_EXECUTABLE_SUFFIX}" + WORKING_DIRECTORY "${Ninja_BINARY_DIR}" USES_TERMINAL 1 ) set(NINJA_BUILD_LAST_STEP "run_ninja_test_suite") endif() endif() -install(FILES ${Ninja_SOURCE_DIR}/misc/ninja_syntax.py DESTINATION ninja) +install(FILES "${Ninja_SOURCE_DIR}/misc/ninja_syntax.py" DESTINATION ninja) install(PROGRAMS ${ninja_executable} DESTINATION ninja/data/bin) From 674c3f63094ce07691f3cb86a28e13caf109ca09 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 20 May 2024 06:08:13 -0400 Subject: [PATCH 07/11] refactor: use ninja directly --- .github/workflows/build.yml | 13 ++++- CMakeLists.txt | 102 +++++------------------------------- pyproject.toml | 6 +-- src/ninja/__init__.py | 62 ++++++++++------------ 4 files changed, 54 insertions(+), 129 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fb77955..645eba3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-22.04 + - os: ubuntu-20.04 arch: "x86_64" - os: ubuntu-22.04 arch: "i686" @@ -78,12 +78,23 @@ jobs: name: cibw-wheels-${{ matrix.os }}-${{ matrix.arch }} path: ./wheelhouse/*.whl + - name: Install Ubuntu Python 2.7 + if: matrix.os == 'ubuntu-20.04' + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends python2 python3-virtualenv + virtualenv -p python2 ${HOME}/cp27 + ${HOME}/cp27/bin/python -m pip install -U pip + ${HOME}/cp27/bin/python -m pip install -U setuptools wheel + echo "${HOME}/cp27/bin" >> $GITHUB_PATH + - name: Test wheel on host Linux if: runner.os == 'Linux' && matrix.arch == 'x86_64' run: | pip install wheelhouse/*manylinux*x86_64*.whl ninja --version python -m ninja --version + python --version build_sdist: name: Build source distribution diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d264e3..5f79690 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,6 @@ set(ARCHIVE_DOWNLOAD_DIR "${CMAKE_BINARY_DIR}" CACHE PATH "Directory where to do include(NinjaUrls) -#----------------------------------------------------------------------------- -# Which archives ? -#----------------------------------------------------------------------------- function(check_archive_var archive_var) if(NOT DEFINED "${archive_var}_url") message(FATAL_ERROR "Failed to determine which archive to download: '${archive_var}_url' variable is not defined") @@ -29,9 +26,6 @@ if(WIN32) endif() check_archive_var("${src_archive}") -#----------------------------------------------------------------------------- -# Summary -#----------------------------------------------------------------------------- message(STATUS "*********************************************") message(STATUS "Ninja Python Distribution") message(STATUS "") @@ -45,9 +39,6 @@ message(STATUS " _url : ${${src_archive}_url}") message(STATUS " _sha256 : ${${src_archive}_sha256}") message(STATUS "*********************************************") -#----------------------------------------------------------------------------- -include(ExternalProject) - set(ep_download_no_progress_args) if(NOT BUILD_VERBOSE) set(ep_download_no_progress_args @@ -55,84 +46,15 @@ if(NOT BUILD_VERBOSE) ) endif() -#----------------------------------------------------------------------------- -# Download source -#----------------------------------------------------------------------------- -if(NOT DEFINED Ninja_SOURCE_DIR) - set(Ninja_SOURCE_DIR "${CMAKE_SOURCE_DIR}/Ninja-src") - - # Download selected source archive - ExternalProject_add(download_ninja_source - SOURCE_DIR ${Ninja_SOURCE_DIR} - URL ${${src_archive}_url} - URL_HASH SHA256=${${src_archive}_sha256} - DOWNLOAD_DIR ${ARCHIVE_DOWNLOAD_DIR} - USES_TERMINAL_DOWNLOAD 1 - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - BUILD_IN_SOURCE 1 - INSTALL_COMMAND "" - ${ep_download_no_progress_args} - ) - message(STATUS "download_ninja_source - URL: ${${src_archive}_url}") -elseif(NOT EXISTS ${Ninja_SOURCE_DIR}) - message(FATAL_ERROR "Ninja_SOURCE_DIR is set to a nonexistent directory") -endif() - -#----------------------------------------------------------------------------- -# Build from source -#----------------------------------------------------------------------------- -set(Ninja_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/Ninja-build") -# cache arguments -set(_cache_args ) -foreach(var_name IN ITEMS - CMAKE_BUILD_TYPE - CMAKE_TOOLCHAIN_FILE - CMAKE_BUILD_PARALLEL_LEVEL - CMAKE_JOB_POOLS - CMAKE_JOB_POOL_COMPILE - CMAKE_JOB_POOL_LINK - CMAKE_OSX_DEPLOYMENT_TARGET - CMAKE_OSX_ARCHITECTURES - CMAKE_OSX_SYSROOT - ) - if(DEFINED ${var_name}) - list(APPEND _cache_args -D${var_name}:STRING=${${var_name}}) - message(STATUS "SuperBuild - ${var_name}: ${${var_name}}") - endif() -endforeach() - -# _cache_args should not be empty -list(APPEND _cache_args -DNINJA_SUPERBUILD:BOOL=true) -ExternalProject_add(build_ninja - SOURCE_DIR ${Ninja_SOURCE_DIR} - BINARY_DIR ${Ninja_BINARY_DIR} - DOWNLOAD_COMMAND "" - UPDATE_COMMAND "" - BUILD_ALWAYS 1 - USES_TERMINAL_CONFIGURE 1 - USES_TERMINAL_BUILD 1 - INSTALL_COMMAND "" - CMAKE_CACHE_ARGS ${_cache_args} - DEPENDS - download_ninja_source - ) -set(ninja_executable "${Ninja_BINARY_DIR}/ninja${CMAKE_EXECUTABLE_SUFFIX}") -set(NINJA_BUILD_LAST_STEP "build") - -# This should not be tested if cross-compiling on Windows -if(CMAKE_CROSS_COMPILE OR NOT DEFINED ENV{DIST_EXTRA_CONFIG}) - if(RUN_NINJA_TEST) - ExternalProject_Add_Step(build_ninja run_ninja_test_suite - DEPENDEES ${NINJA_BUILD_LAST_STEP} - COMMENT "Running Ninja test suite" - COMMAND "${Ninja_BINARY_DIR}/ninja_test${CMAKE_EXECUTABLE_SUFFIX}" - WORKING_DIRECTORY "${Ninja_BINARY_DIR}" - USES_TERMINAL 1 - ) - set(NINJA_BUILD_LAST_STEP "run_ninja_test_suite") - endif() -endif() - -install(FILES "${Ninja_SOURCE_DIR}/misc/ninja_syntax.py" DESTINATION ninja) -install(PROGRAMS ${ninja_executable} DESTINATION ninja/data/bin) +include(FetchContent) +FetchContent_Declare( + ninja + URL ${${src_archive}_url} + URL_HASH SHA256=${${src_archive}_sha256} + DOWNLOAD_DIR ${ARCHIVE_DOWNLOAD_DIR} + ${ep_download_no_progress_args} +) +FetchContent_MakeAvailable(ninja) + +install(TARGETS ninja COMPONENT python DESTINATION "${SKBUILD_SCRIPTS_DIR}") +install(FILES "${ninja_SOURCE_DIR}/misc/ninja_syntax.py" COMPONENT python DESTINATION ninja) diff --git a/pyproject.toml b/pyproject.toml index 40fd7c8..a78f2ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,9 +39,6 @@ test = [ "pytest>=4.5.0", ] -[project.scripts] -ninja = "ninja:ninja" - [project.urls] "Bug Tracker" = "https://github.com/scikit-build/ninja-python-distributions/issues" Documentation = "https://github.com/scikit-build/ninja-python-distributions#readme" @@ -57,6 +54,7 @@ wheel.py-api = "py2.py3" wheel.expand-macos-universal-tags = true metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" metadata.readme.provider = "scikit_build_core.metadata.fancy_pypi_readme" +install.components = ["python"] [[tool.scikit-build.generate]] @@ -132,7 +130,7 @@ ignore = [ ] flake8-unused-arguments.ignore-variadic-names = true -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "*.pyi" = ["ARG001"] "noxfile.py" = ["PLW0603"] # Could be fixed if Python 2 dropped diff --git a/src/ninja/__init__.py b/src/ninja/__init__.py index d2c3a24..260dd84 100644 --- a/src/ninja/__init__.py +++ b/src/ninja/__init__.py @@ -1,50 +1,44 @@ # -*- coding: utf-8 -*- import os -import platform import subprocess import sys +import sysconfig from ._version import version as __version__ +from .ninja_syntax import Writer, escape, expand -__all__ = ["__version__", "DATA", "BIN_DIR", "ninja"] +__all__ = ["__version__", "DATA", "BIN_DIR", "ninja", "Writer", "escape", "expand"] def __dir__(): return __all__ -try: - from .ninja_syntax import Writer, escape, expand -except ImportError: - # Support importing `ninja_syntax` from the source tree - if not os.path.exists( - os.path.join(os.path.dirname(__file__), 'ninja_syntax.py')): - sys.path.insert(0, os.path.abspath(os.path.join( - os.path.dirname(__file__), '../../Ninja-src/misc'))) - from ninja_syntax import Writer, escape, expand # noqa: F401 - -DATA = os.path.join(os.path.dirname(__file__), 'data') - -# Support running tests from the source tree -if not os.path.exists(DATA): - from skbuild.constants import CMAKE_INSTALL_DIR as SKBUILD_CMAKE_INSTALL_DIR - from skbuild.constants import set_skbuild_plat_name - - if platform.system().lower() == "darwin": - # Since building the project specifying --plat-name or CMAKE_OSX_* variables - # leads to different SKBUILD_DIR, the code below attempt to guess the most - # likely plat-name. - _skbuild_dirs = os.listdir(os.path.join(os.path.dirname(__file__), '..', '..', '_skbuild')) - if _skbuild_dirs: - _likely_plat_name = '-'.join(_skbuild_dirs[0].split('-')[:3]) - set_skbuild_plat_name(_likely_plat_name) - - _data = os.path.abspath(os.path.join( - os.path.dirname(__file__), '..', '..', SKBUILD_CMAKE_INSTALL_DIR(), 'src/ninja/data')) - if os.path.exists(_data): - DATA = _data - -BIN_DIR = os.path.join(DATA, 'bin') +def _get_ninja_dir(): + ninja_exes = {"ninja" + sysconfig.get_config_var("EXE"), "ninja"} + for ninja_exe in ninja_exes: + path = os.path.join(sysconfig.get_path("scripts"), ninja_exe) + if os.path.isfile(path): + return os.path.dirname(path) + + if sys.version_info >= (3, 10): + user_scheme = sysconfig.get_preferred_scheme("user") + elif os.name == "nt": + user_scheme = "nt_user" + elif sys.platform == "darwin" and sys._framework: + user_scheme = "osx_framework_user" + else: + user_scheme = "posix_user" + + for ninja_exe in ninja_exes: + path = os.path.join(sysconfig.get_path("scripts", scheme=user_scheme), ninja_exe) + + if os.path.isfile(path): + return os.path.dirname(path) + + return None + +BIN_DIR = _get_ninja_dir() def _program(name, args): From 213ba7bd59f6dfbc26356ef10c528c3e323015dd Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 21 May 2024 00:14:32 -0400 Subject: [PATCH 08/11] Update pyproject.toml Co-authored-by: Jean-Christophe Fillion-Robin --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index a78f2ff..bc7a8ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,7 @@ dynamic = ["version", "readme"] description = "Ninja is a small build system with a focus on speed" authors = [ { name = "Jean-Christophe Fillion-Robin", email = "scikit-build@googlegroups.com" }, + { name = "Henry Schreiner", email = "henryfs@princeton.edu" }, ] keywords = [ "build", From 9d374fe8a01ff090cc069df65495b07be6728f6b Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 21 May 2024 00:45:10 -0400 Subject: [PATCH 09/11] fix: better fallback Signed-off-by: Henry Schreiner --- src/ninja/__init__.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/ninja/__init__.py b/src/ninja/__init__.py index 260dd84..2f63898 100644 --- a/src/ninja/__init__.py +++ b/src/ninja/__init__.py @@ -15,34 +15,41 @@ def __dir__(): def _get_ninja_dir(): - ninja_exes = {"ninja" + sysconfig.get_config_var("EXE"), "ninja"} - for ninja_exe in ninja_exes: - path = os.path.join(sysconfig.get_path("scripts"), ninja_exe) - if os.path.isfile(path): - return os.path.dirname(path) + ninja_exe = "ninja" + sysconfig.get_config_var("EXE") + # Default path + path = os.path.join(sysconfig.get_path("scripts"), ninja_exe) + if os.path.isfile(path): + return os.path.dirname(path) + + # User path if sys.version_info >= (3, 10): user_scheme = sysconfig.get_preferred_scheme("user") elif os.name == "nt": user_scheme = "nt_user" - elif sys.platform == "darwin" and sys._framework: + elif sys.platform.startswith("darwin") and sys._framework: user_scheme = "osx_framework_user" else: user_scheme = "posix_user" - for ninja_exe in ninja_exes: - path = os.path.join(sysconfig.get_path("scripts", scheme=user_scheme), ninja_exe) + path = sysconfig.get_path("scripts", scheme=user_scheme) - if os.path.isfile(path): - return os.path.dirname(path) + if os.path.isfile(os.path.join(path, ninja_exe)): + return path - return None + # Fallback to python location + path = os.path.dirname(sys.executable) + if os.path.isfile(os.path.join(path, ninja_exe)): + return path -BIN_DIR = _get_ninja_dir() + return "" +BIN_DIR = _get_ninja_dir() + def _program(name, args): - return subprocess.call([os.path.join(BIN_DIR, name)] + args, close_fds=False) + cmd = os.path.join(BIN_DIR, name) + return subprocess.call([cmd] + args, close_fds=False) def ninja(): From ff17c8bedb09a759c54624fa70a5aed379dd7161 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 04:52:43 +0000 Subject: [PATCH 10/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/ninja/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ninja/__init__.py b/src/ninja/__init__.py index 2f63898..ec23419 100644 --- a/src/ninja/__init__.py +++ b/src/ninja/__init__.py @@ -38,7 +38,7 @@ def _get_ninja_dir(): return path # Fallback to python location - path = os.path.dirname(sys.executable) + path = os.path.dirname(sys.executable) if os.path.isfile(os.path.join(path, ninja_exe)): return path From 016148315104232d67daeb233dc78a93a4467e66 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 27 May 2024 23:36:02 -0400 Subject: [PATCH 11/11] Update pyproject.toml --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index bc7a8ee..3e85911 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,6 +90,8 @@ environment-pass = ["SETUPTOOLS_SCM_PRETEND_VERSION"] [[tool.cibuildwheel.overrides]] select = "*-manylinux_{x86_64,i686}" +manylinux-x86_64-image = "manylinux2010" +manylinux-i686-image = "manylinux2010" environment = { LDFLAGS = "-static-libstdc++" } [tool.cibuildwheel.macos.environment]