diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76a4e1a..e36b37c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,7 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 + submodules: true - uses: actions/setup-python@v2 with: @@ -47,13 +48,13 @@ jobs: run: | brew install ninja - - name: Prepare compiler environment for ${{ matrix.os }} + - name: Prepare build environment for ${{ matrix.os }} if: runner.os == 'Windows' uses: ilammy/msvc-dev-cmd@v1 with: arch: x64 - - name: Set have package true for ${{ matrix.os }} + - name: Set GITHUB_ENV vars for ${{ matrix.os }} if: runner.os == 'Linux' run: | echo "HAVE_LIBDATRIE_PKG=TRUE" >> $GITHUB_ENV @@ -67,8 +68,6 @@ jobs: packages: libdatrie-dev pybind11-dev ninja-build - name: Test in place - # windows does not like build_ext -i or removing previous build - if: runner.os != 'Windows' run: | tox -e py diff --git a/.github/workflows/conda.yml b/.github/workflows/conda.yml new file mode 100644 index 0000000..2cfc7d1 --- /dev/null +++ b/.github/workflows/conda.yml @@ -0,0 +1,56 @@ +name: Conda + +on: + workflow_dispatch: + #pull_request: + #push: + # branches: + # - master + +jobs: + build: + strategy: + fail-fast: false + matrix: + platform: [ubuntu-latest, windows-2016, macos-latest] + python-version: [3.6, 3.7, 3.8, 3.9] + + runs-on: ${{ matrix.platform }} + + # The setup-miniconda action needs this to activate miniconda + defaults: + run: + shell: "bash -l {0}" + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: true + + - name: Cache conda + uses: actions/cache@v1 + with: + path: ~/conda_pkgs_dir + key: ${{matrix.os}}-conda-pkgs-${{hashFiles('**/conda.recipe/meta.yaml')}} + + - name: Get conda + uses: conda-incubator/setup-miniconda@v2 + with: + python-version: ${{ matrix.python-version }} + channels: conda-forge + channel-priority: strict + use-only-tar-bz2: true + auto-activate-base: true + + - name: Prepare + run: conda install conda-build conda-verify pytest hypothesis + + - name: Build + run: conda build conda.recipe + + - name: Install + run: conda install -c ${CONDA_PREFIX}/conda-bld/ datrie + + - name: Test + run: pytest -v diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5892b9f..3921b46 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,6 +18,7 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 + submodules: true - uses: actions/setup-python@v2 name: Install Python diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index fe7d296..ee9bc97 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -19,6 +19,7 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 + submodules: true - uses: actions/setup-python@v2 name: Install Python diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3986f13 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libdatrie"] + path = libdatrie + url = https://github.com/tlwg/libdatrie.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 18e2530..1050543 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.15...3.18) option(PY_DEBUG "Set if python being linked is a Py_DEBUG build" OFF) +option(GIT_SUBMODULE "Check submodules during build" ON) option(USE_LIBDATRIE_PKG "Use OS-provided libdatrie package") if(DEFINED ENV{HAVE_LIBDATRIE_PKG}) set(USE_LIBDATRIE_PKG "$ENV{HAVE_LIBDATRIE_PKG}") @@ -30,17 +31,26 @@ if(USE_LIBDATRIE_PKG AND NOT Datrie_FOUND) endif() if(NOT USE_LIBDATRIE_PKG) - message(STATUS "Fetching libdatrie from github") - # Fetch libdatrie - include(FetchContent) + message(STATUS "Trying libdatrie submodule") + find_package(Git QUIET) + if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + # Update submodules as needed + if(GIT_SUBMODULE) + if(NOT EXISTS "${PROJECT_SOURCE_DIR}/libdatrie/datrie-0.2.pc.in") + message(STATUS "Submodule update") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() + endif() + endif() + endif() - FetchContent_Declare( - libdatrie - GIT_REPOSITORY https://github.com/tlwg/libdatrie - GIT_TAG v0.2.13 - ) - FetchContent_MakeAvailable(libdatrie) - # this gets us the package source directory + if(NOT EXISTS "${PROJECT_SOURCE_DIR}/libdatrie/datrie-0.2.pc.in") + message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") + endif() endif() find_package(pybind11 CONFIG) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml new file mode 100644 index 0000000..181539c --- /dev/null +++ b/conda.recipe/meta.yaml @@ -0,0 +1,52 @@ +{% set name = "datrie" %} +{% set version = "0.8.3.dev0" %} + +package: + name: {{ name|lower }} + version: {{ version }} + +source: + path: .. + +build: + number: 0 + script: {{ PYTHON }} -m pip install . -vv + +requirements: + build: + - {{ compiler('c') }} + - {{ compiler('cxx') }} + host: + - python + - cmake >=3.15 + - pybind11 + - ninja + - cython + - pip + + run: + - python + +test: + requires: + - pytest + - hypothesis + imports: + - datrie + source_files: + - tests + commands: + - python -m pytest + +about: + home: "https://github.com/pytries" + license: LGPL-2.0-or-later + license_family: LGPL + license_file: COPYING + summary: "Fast, efficiently stored Trie for Python. Uses libdatrie." + doc_url: "https://github.com/pytries/datrie/blob/master/README.rst" + dev_url: "https://github.com/pytries/datrie" + +extra: + recipe-maintainers: + - sarnold diff --git a/libdatrie b/libdatrie new file mode 160000 index 0000000..d1dfdb8 --- /dev/null +++ b/libdatrie @@ -0,0 +1 @@ +Subproject commit d1dfdb831093892541cae46eba82c46aec94f726 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eeed7eb..fe3864c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,11 +21,11 @@ add_custom_command(OUTPUT ${cython_output} COMMENT "Cythonizing extension ${cython_src}") if(NOT USE_LIBDATRIE_PKG) - # use the locally cloned source from FetchContent - set(DATRIE_INCLUDE_DIR "${libdatrie_SOURCE_DIR}") + # use the local git submodule + set(DATRIE_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/libdatrie") file(GLOB_RECURSE DATRIE_SOURCES LIST_DIRECTORIES true - "${libdatrie_SOURCE_DIR}/datrie/*.c") + "${DATRIE_INCLUDE_DIR}/datrie/*.c") list(APPEND cython_output ${DATRIE_SOURCES}) include_directories(${DATRIE_INCLUDE_DIR}) endif() diff --git a/tox.ini b/tox.ini index c0e0424..71c6424 100644 --- a/tox.ini +++ b/tox.ini @@ -23,19 +23,18 @@ passenv = PIP_DOWNLOAD_CACHE setenv = - PYTHONPATH=. + PYTHONPATH = {toxinidir} + #PYTHONPATH = {env:PYTHONPATH}{:}{toxinidir} deps = pip>=20.0.1 cython>=0.20 - path pytest hypothesis commands = python setup.py build_ext --inplace python -m pytest [] - python -c "import path; path.Path('build').rmtree_p()" [testenv:dev] skip_install = true @@ -56,6 +55,7 @@ deps = path commands= + # this command breaks on windows (permission error) python -c "import path; path.Path('build').rmtree_p()" pip install -e .[test] flake8 src/