Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native cmake support #28

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
codecov:
notify:
after_n_builds: 5
4 changes: 4 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
40 changes: 40 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
workflow_dispatch:
inputs:
upload-wheel:
type: boolean
required: false
default: false
description: Upload wheel as an artifact
pull_request:
branches: [ main ]
push:
branches: [ main ]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
uses: ./.github/workflows/step_test.yaml

build-wheel:
uses: ./.github/workflows/step_build-wheel.yaml
needs: [ tests ]
with:
upload: ${{ inputs.upload-wheel || false }}
pass:
needs: [tests, build-wheel]
runs-on: ubuntu-latest
steps:
- name: Check all CI action
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
if: always()
52 changes: 52 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Prepare release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"
workflow_dispatch:
inputs:
ref:
description: Tag to release
required: true
type: string

permissions:
contents: read

jobs:
tests:
uses: ./.github/workflows/step_test.yaml
build-wheel:
needs: [ tests ]
uses: ./.github/workflows/step_build-wheel.yaml
with:
ref: ${{ inputs.ref }}
upload_pypi:
name: Upload to PyPI repository
needs: [ tests, build-wheel ]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/click-option-group/
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
release:
needs: [ upload_pypi ]
name: Create release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: softprops/action-gh-release@v1
with:
name: click-option-group ${{ github.ref_name }}
prerelease: ${{ contains(github.ref, 'rc') }}
generate_release_notes: true
29 changes: 29 additions & 0 deletions .github/workflows/step_build-wheel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
workflow_call:
inputs:
upload:
description: Upload wheel as artifact
required: false
type: boolean
default: true
ref:
description: Tag to release
required: false
type: string

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Build package
run: pipx run build
- uses: actions/upload-artifact@v3
with:
path: dist/*
if: ${{ inputs.upload }}
45 changes: 45 additions & 0 deletions .github/workflows/step_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
workflow_call:

permissions:
contents: read

jobs:
tests:
name: Check with Python ${{ matrix.python-version }} ${{ matrix.experimental && '(Experimental)' }}
needs: [ pre-commit ]
continue-on-error: ${{ matrix.experimental || false }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
include:
- python-version: "3.12"
experimental: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Install package
run: pip install -e .[test-cov]
- name: Test package
run: pytest --cov --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
name: python ${{ matrix.python-version }}
flags: python-${{ matrix.python-version }}

pass:
needs: [ tests ]
runs-on: ubuntu-latest
steps:
- name: Check test jobs
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
if: always()
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ docs/_build
.tox
_gitmsg.saved.txt

### Basic setups
cmake-build-*

### Project specific
src/fypp/_version.py
CMakeUserPresets.json
4 changes: 3 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ sphinx:
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
- path: .
extra_requirements:
- docs
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

98 changes: 98 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
cmake_minimum_required(VERSION 3.15)
# CMake version compatibility
# TODO: Remove when cmake 3.25 is commonly distributed
if (POLICY CMP0140)
cmake_policy(SET CMP0140 NEW)
endif ()

#[==============================================================================================[
# Basic project defintion #
]==============================================================================================]

project(Fypp
VERSION 3.1.0
LANGUAGES NONE)

# Back-porting to PROJECT_IS_TOP_LEVEL to older cmake
# TODO: Remove when requiring cmake >= 3.21
if (NOT DEFINED Fypp_IS_TOP_LEVEL)
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(PROJECT_IS_TOP_LEVEL ON)
else ()
set(PROJECT_IS_TOP_LEVEL OFF)
endif ()
endif ()

#[==============================================================================================[
# Options #
]==============================================================================================]

option(FYPP_TESTS "Fypp: Build unit tests" ${PROJECT_IS_TOP_LEVEL})
option(FYPP_INSTALL "Fypp: Install project" ${PROJECT_IS_TOP_LEVEL})

#[==============================================================================================[
# Project configuration #
]==============================================================================================]

# Include basic tools
if (FYPP_INSTALL)
include(CMakePackageConfigHelpers)
if (UNIX)
include(GNUInstallDirs)
endif ()
endif ()
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

if (FYPP_TESTS)
enable_testing()
add_subdirectory(test)
endif ()

#[==============================================================================================[
# Install or Export #
]==============================================================================================]
# Installation
if (FYPP_INSTALL)
# cmake export files
write_basic_package_version_file(
FyppConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
ARCH_INDEPENDENT)
configure_package_config_file(
cmake/FyppConfig.cmake.in
FyppConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/Fypp)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FyppConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/FyppConfig.cmake
cmake/CMakeDetermineFyppCompiler.cmake
cmake/CMakeFyppCompiler.cmake.in
cmake/CMakeFyppInformation.cmake
cmake/CMakeTestFyppCompiler.cmake
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/Fypp)
endif ()

# Make project available for FetchContent
if (NOT PROJECT_IS_TOP_LEVEL)
# Set variables for FetchContent
# All variables have to be consistent with FyppConfig.cmake
# Propagate variables
if (CMAKE_VERSION VERSION_LESS 3.25)
# TODO: Remove when cmake 3.25 is commonly distributed
set(Fypp_VERSION ${Fypp_VERSION} PARENT_SCOPE)
set(Fypp_VERSION_MAJOR ${Fypp_VERSION_MAJOR} PARENT_SCOPE)
set(Fypp_VERSION_MINOR ${Fypp_VERSION_MINOR} PARENT_SCOPE)
set(Fypp_VERSION_PATCH ${Fypp_VERSION_PATCH} PARENT_SCOPE)
set(Fypp_VERSION_TWEAK ${Fypp_VERSION_TWEAK} PARENT_SCOPE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE)
else ()
return(PROPAGATE
Fypp_VERSION
Fypp_VERSION_MAJOR
Fypp_VERSION_MINOR
Fypp_VERSION_PATCH
Fypp_VERSION_TWEAK
CMAKE_MODULE_PATH
)
endif ()
endif ()
12 changes: 12 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"include": [
"cmake/CMakePresets-defaults.json",
"cmake/CMakePresets-CI.json"
]
}
6 changes: 0 additions & 6 deletions MANIFEST.in

This file was deleted.

Loading