Skip to content

Commit

Permalink
Merge pull request #136 from realratchet/master
Browse files Browse the repository at this point in the history
Added nimble support
  • Loading branch information
realratchet authored Feb 22, 2024
2 parents 4d21908 + edc057d commit f3f29e0
Show file tree
Hide file tree
Showing 46 changed files with 974 additions and 634 deletions.
32 changes: 32 additions & 0 deletions .github/actions/buildnim/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Nimlite
description: "Builds Nimlite"
runs:
using: "composite"
steps:
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: "2.0.0"
- name: Nimble Install dependencies
shell: bash
run: |
nimble -y refresh
nimble -y install nimpy argparse
- name: Set Environment Variables
uses: allenevans/[email protected]
with:
NIMLITE_DIR: 'nimlite'
NIM_PACKAGE_NAME: 'libnimlite'
TABLITE_PACKAGE_NAME: 'tablite'
NIMC_FLAGS: '--gc:refc --app:lib --threads:on -d:release -d:danger'
- name: Compile Debug & import (Unix)
shell: bash
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
# compile the libnimlite
nim c ${{ env.NIMC_FLAGS }} --out:${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.so ${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.nim
- name: Compile Debug & import (Windows)
shell: bash
if: runner.os == 'Windows'
run: |
# compile the libnimlite
nim c ${{ env.NIMC_FLAGS }} --tlsEmulation:off --passL:-static --out:${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.pyd ${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.nim
17 changes: 17 additions & 0 deletions .github/actions/validatenim/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Validate Nimlite
description: "Validates Nimlite build"
runs:
using: "composite"
steps:
- name: Compile Debug & import (Unix)
shell: bash
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
# check if compiled successfully
python -c "print(__import__('${{ env.NIMLITE_DIR }}.${{ env.NIM_PACKAGE_NAME }}').__file__)"
- name: Compile Debug & import (Windows)
shell: bash
if: runner.os == 'Windows'
run: |
# check if compiled successfully
python -c "print(__import__('${{ env.NIMLITE_DIR }}.${{ env.NIM_PACKAGE_NAME }}').__file__)"
22 changes: 1 addition & 21 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ jobs:
PYTHON: '3.10'
steps:
- uses: actions/checkout@v3
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: "2.0.0"
- name: Nimble Install dependencies
run: |
nimble -y refresh
nimble -y install nimpy argparse
- name: Set Environment Variables
uses: allenevans/[email protected]
with:
NIMLITE_DIR: 'tablite/_nimlite'
NIM_PACKAGE_NAME: 'nimlite'
TABLITE_PACKAGE_NAME: 'tablite'
NIMC_FLAGS: '--app:lib --threads:on -d:release -d:danger'

- name: Setup Python
uses: actions/setup-python@v3
with:
Expand All @@ -38,12 +23,7 @@ jobs:
python -m pip install pytest
python -m pip install pytest-cov
python -m pip install -r requirements.txt
- name: Compile Debug & import (Unix)
run: |
# compile the nimlite
nim c ${{ env.NIMC_FLAGS }} --out:${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.so ${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.nim
# check if compiled successfully
python -c "print(__import__('${{ env.TABLITE_PACKAGE_NAME }}.${{ env.NIM_PACKAGE_NAME }}').__file__)"
- uses: ./.github/actions/buildnim
- name: Generate Report
run: |
pytest --cov=tablite tests/ --cov-report=xml
Expand Down
18 changes: 1 addition & 17 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ jobs:
cache-dependency-path: |
requirements.txt
requirements_mkdocs.txt
- name: Install Nim Lang
uses: jiro4989/setup-nim-action@v1
with:
nim-version: "2.0.0"
- name: Nimble Install dependencies
run: |
nimble -y refresh
nimble -y install nimpy argparse
- name: Install PIPs
run: |
python -m pip install -r requirements.txt
Expand All @@ -67,16 +59,8 @@ jobs:
- name: Set Env for tablite Import
uses: allenevans/[email protected]
with:
USE_NIMPORTER: 'false'
PYTHONPATH: '.:tablite'
NIMLITE_DIR: 'tablite/_nimlite'
NIM_PACKAGE_NAME: 'nimlite'
TABLITE_PACKAGE_NAME: 'tablite'
NIMC_FLAGS: '--app:lib --threads:on -d:release -d:danger'
- name: Compile NimLite
run: |
nim c ${{ env.NIMC_FLAGS }} --out:${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.so ${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.nim
python -c "print(__import__('${{ env.TABLITE_PACKAGE_NAME }}.${{ env.NIM_PACKAGE_NAME }}').__file__)"
- uses: ./.github/actions/buildnim
- name: Configure Git user
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
Expand Down
31 changes: 4 additions & 27 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,7 @@ jobs:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: "2.0.0"
- name: Nimble Install dependencies
run: |
nimble -y refresh
nimble -y install nimpy argparse
- name: Set Environment Variables
uses: allenevans/[email protected]
with:
NIMLITE_DIR: 'tablite/_nimlite'
NIM_PACKAGE_NAME: 'nimlite'
TABLITE_PACKAGE_NAME: 'tablite'
NIMC_FLAGS: '--app:lib --threads:on -d:release -d:danger'
- name: Compile Debug & import (Unix)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
# compile the nimlite
nim c ${{ env.NIMC_FLAGS }} --out:${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.so ${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.nim
- name: Compile Debug & import (Windows)
if: runner.os == 'Windows'
run: |
# compile the nimlite
nim c ${{ env.NIMC_FLAGS }} --tlsEmulation:off --passL:-static --out:${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.pyd ${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.nim
- uses: ./.github/actions/buildnim
- name: Cache Unix
if: runner.os == 'Linux' || runner.os == 'macOS'
uses: actions/upload-artifact@v3
Expand All @@ -60,8 +37,8 @@ jobs:
- name: Set Environment Variables
uses: allenevans/[email protected]
with:
NIMLITE_DIR: 'tablite/_nimlite'
NIM_PACKAGE_NAME: 'nimlite'
NIMLITE_DIR: 'nimlite'
NIM_PACKAGE_NAME: 'libnimlite'
- name: Cache Restore Unix
uses: actions/download-artifact@v3
with:
Expand All @@ -76,7 +53,7 @@ jobs:
${{ env.NIMLITE_DIR }}
- name: install python
run: |
python3 -m pip install --upgrade build
python3 -m pip install --upgrade build
- name: build wheel
run: |
python3 -m build --wheel
Expand Down
31 changes: 3 additions & 28 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,14 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: "2.0.0"
- name: Nimble Install dependencies
run: |
nimble -y refresh
nimble -y install nimpy argparse
- name: Set Environment Variables
uses: allenevans/[email protected]
with:
NIMLITE_DIR: 'tablite/_nimlite'
NIM_PACKAGE_NAME: 'nimlite'
TABLITE_PACKAGE_NAME: 'tablite'
NIMC_FLAGS: '--app:lib --threads:on -d:release -d:danger'
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install -r requirements.txt
- name: Compile Debug & import (Unix)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
# compile the nimlite
nim c ${{ env.NIMC_FLAGS }} --out:${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.so ${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.nim
# check if compiled successfully
python -c "print(__import__('${{ env.TABLITE_PACKAGE_NAME }}.${{ env.NIM_PACKAGE_NAME }}').__file__)"
- name: Compile Debug & import (Windows)
if: runner.os == 'Windows'
run: |
# compile the nimlite
nim c ${{ env.NIMC_FLAGS }} --tlsEmulation:off --passL:-static --out:${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.pyd ${{ env.NIMLITE_DIR }}/${{ env.NIM_PACKAGE_NAME }}.nim
# check if compiled successfully
python -c "print(__import__('${{ env.TABLITE_PACKAGE_NAME }}.${{ env.NIM_PACKAGE_NAME }}').__file__)"
- uses: ./.github/actions/buildnim
- uses: ./.github/actions/validatenim
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@
*.pyc
tests/new.zip
__pycache__
*/_nimlite/*
!*/_nimlite/**.nim
!*/_nimlite/funcs/
!*/_nimlite/includes/
!*/_nimlite/includes/**.nim
!*/_nimlite/funcs/column_selector/**.nim
!*/_nimlite/**.py
!*/_nimlite/**.pyi
/nimlite/*.so
/nimlite/nimtest

# Notebook checkpoints
.ipynb_checkpoints/
Expand Down
4 changes: 2 additions & 2 deletions build_nim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ fi

if [ $is_release = true ]
then
nim c --app:lib -d:release -d:danger --out:tablite/_nimlite/nimlite.so tablite/_nimlite/nimlite.nim
nim c --app:lib --gc:refc -d:release -d:danger --out:nimlite/libnimlite.so nimlite/libnimlite.nim
echo "Built release."
else
nim c --app:lib -d:debug --out:tablite/_nimlite/nimlite.so tablite/_nimlite/nimlite.nim
nim c --app:lib --gc:refc -d:debug --out:nimlite/libnimlite.so nimlite/libnimlite.nim
echo "Built debug."
fi
1 change: 1 addition & 0 deletions nimlite.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a stub file for other modules to import
13 changes: 13 additions & 0 deletions nimlite.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Package

version = "0.1.0"
author = "Ratchet"
description = "Utilities for tablite to work with nim"
license = "MIT"
# srcDir = "nimlite"


# Dependencies

requires "nim >= 2.0.0"
requires "nimpy >= 0.2.0"
File renamed without changes.
7 changes: 5 additions & 2 deletions tablite/_nimlite/dateutils.nim → nimlite/dateutils.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import std/times
from utils import divmod
from std/hashes import Hash, hash
from std/math import splitDecimal

const DAYS_PER_MONTH_TABLE* = [
Expand Down Expand Up @@ -118,7 +119,7 @@ proc date2NimDateTime*(year: int, month: int, day: int): DateTime {.inline.} =
return dateTime(year, Month(month), MonthdayRange(day), zone=utc())

proc datetime2NimDatetime*(year: int, month: int, day: int, hour: int, minute: int, second: int, microsecond: int): DateTime {.inline.} =
return dateTime(year, Month(month), MonthdayRange(day), hour, second, microsecond * 1000, zone=utc())
return dateTime(year, Month(month), MonthdayRange(day), hour, minute, second, microsecond * 1000, zone=utc())

proc time2NimDuration*(hour: int, minute: int, second: int, microsecond: int): Duration {.inline.} =
return initDuration(hours=hour, minutes=minute, seconds=second, microseconds=microsecond)
Expand All @@ -134,4 +135,6 @@ proc duration2Seconds*(dur: Duration): float {.inline.} = dur.inMicroseconds / 1

proc duration2Date*(dur: Duration): DateTime {.inline.} = dateTime(1970, mJan, 1, zone=utc()) + dur
proc seconds2Date*(seconds: float): DateTime {.inline.} = duration2Date(seconds2Duration(seconds))
proc datetime2Date*(self: DateTime): DateTime {.inline.} = dateTime(self.year, self.month, self.monthday, zone=utc())
proc datetime2Date*(self: DateTime): DateTime {.inline.} = dateTime(self.year, self.month, self.monthday, zone=utc())

proc hash*(self: DateTime): Hash = hash(self.toTime.toUnixFloat)
Loading

0 comments on commit f3f29e0

Please sign in to comment.