From f807cc0bc658b2e13922dd49f28ec2d89baa9854 Mon Sep 17 00:00:00 2001 From: Young Geun Kim Date: Thu, 12 Sep 2024 11:45:40 +0900 Subject: [PATCH] add pip git install ci --- .github/workflows/py-github-check.yaml | 125 +++++++++++++++++++++++++ .github/workflows/py-sdist-check.yaml | 6 +- python/MANIFEST.in | 2 + python/docs/index.qmd | 9 +- python/docs/intro.qmd | 9 ++ python/pyproject.toml | 5 + 6 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/py-github-check.yaml create mode 100644 python/MANIFEST.in diff --git a/.github/workflows/py-github-check.yaml b/.github/workflows/py-github-check.yaml new file mode 100644 index 00000000..22c01114 --- /dev/null +++ b/.github/workflows/py-github-check.yaml @@ -0,0 +1,125 @@ +on: + push: + branches: ['feature/python', 'feature/py-*'] # change to [main, master, 'hotfix/*', 'release/*', develop, 'feature/py-*'] after finish + # pull_request: + # branches: [main, master, 'hotfix/*', 'release/*', develop] + +name: py-github-check + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: ['3.10', '3.11', '3.12'] + + defaults: + run: + working-directory: python + + name: ${{ matrix.os }} (${{ matrix.python-version }}) + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Verify git + run: git --version + + - name: Set system dependencies on Linux + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y libboost-all-dev libeigen3-dev + echo $(sudo apt list --installed) + echo "EIGEN_INCLUDE_DIR=/usr/include/eigen3" >> $GITHUB_ENV + echo "BOOST_INCLUDE_DIR=/usr/include/boost" >> $GITHUB_ENV + + - name: Set system dependencies on macOS + if: runner.os == 'macOS' + run: | + brew update + brew install llvm libomp boost eigen + EIGEN_LOC=$(brew --prefix eigen) + BOOST_LOC=$(brew --prefix boost) + LLVM_LOC=$(brew --prefix llvm) + OMP_LOC=$(brew --prefix libomp) + echo "EIGEN_INCLUDE_DIR=$EIGEN_LOC/include/eigen3" >> $GITHUB_ENV + echo "BOOST_INCLUDE_DIR=$BOOST_LOC/include" >> $GITHUB_ENV + echo "LLVM_LOC=$LLVM_LOC" >> $GITHUB_ENV + echo "OMP_LOC=$OMP_LOC" >> $GITHUB_ENV + echo "CC=$LLVM_LOC/bin/clang" >> $GITHUB_ENV + echo "CXX=$LLVM_LOC/bin/clang++" >> $GITHUB_ENV + echo "CPPFLAGS=-I$LLVM_LOC/include -I$OMP_LOC/include" >> $GITHUB_ENV + echo "LDFLAGS=-L$LLVM_LOC/lib -L$OMP_LOC/lib" >> $GITHUB_ENV + + - name: Set system dependencies on Windows + if: runner.os == 'Windows' + run: | + choco install eigen -y --no-progress + choco install boost-msvc-14.3 -y --no-progress + $eigenPath = ( + Get-ChildItem -Path "C:\ProgramData\chocolatey\lib\eigen" -Recurse -Filter "Eigen" | + Select-Object -First 1 + ).Parent.FullName + if ($eigenPath) { + echo "eigen is installed in $eigenPath" + } else { + Write-Error "Wrong eigen path" + exit 1 + } + $boostPath = $null + $boostCand = @("C:\local", "C:\ProgramData\chocolatey\lib") + foreach ($cand in $boostCand) { + $isPath = ( + Get-ChildItem -Path $cand -Directory | + Where-Object { $_.Name -match "boost" } | + Sort-Object LastWriteTime -Descending | + Select-Object -First 1 + ).FullName + if ($isPath) { + $boostPath = $isPath + break + } + } + if ($boostPath) { + echo "boost is installed in $boostPath" + } else { + Write-Error "Wrong boost path" + exit 1 + } + echo "EIGEN_INCLUDE_DIR=$eigenPath" >> $Env:GITHUB_ENV + echo "BOOST_INCLUDE_DIR=$boostPath" >> $Env:GITHUB_ENV + + - name: Verify Eigen and boost on non-Windows + if: runner.os != 'Windows' + run: | + ls ${{ env.EIGEN_INCLUDE_DIR }} + ls ${{ env.BOOST_INCLUDE_DIR }} + + - name: Verify Eigen and boost on Windows + if: runner.os == 'Windows' + run: | + dir ${{ env.EIGEN_INCLUDE_DIR }} + dir ${{ env.BOOST_INCLUDE_DIR }} + + - name: Install package from github + # change branch after finishing the feature + run: | + pip install --upgrade pip + python -m pip install git+https://github.com/ygeunkim/bvhar.git@feature/python#subdirectory=python[test] + + - name: Verify installation + run: pip list + + - name: OpenMP check + run: python -c "from bvhar.utils import checkomp; checkomp.check_omp()" + + - name: Test + run: pytest diff --git a/.github/workflows/py-sdist-check.yaml b/.github/workflows/py-sdist-check.yaml index bb21f1df..1b695624 100644 --- a/.github/workflows/py-sdist-check.yaml +++ b/.github/workflows/py-sdist-check.yaml @@ -126,7 +126,11 @@ jobs: - name: Install sdist on Windows if: runner.os == 'Windows' run: | - $dist = (Get-ChildItem -Path dist -Filter "*.zip" | Select-Object -First 1).FullName + $dist = ( + Get-ChildItem -Path dist | + Where-Object { $_.Name -like "*.zip" -or $_.Name -like "*.tar.gz" } | + Select-Object -First 1 + ).FullName pip install $dist - name: Verify installation diff --git a/python/MANIFEST.in b/python/MANIFEST.in new file mode 100644 index 00000000..198bf39b --- /dev/null +++ b/python/MANIFEST.in @@ -0,0 +1,2 @@ +include setup.py +include pyproject.toml \ No newline at end of file diff --git a/python/docs/index.qmd b/python/docs/index.qmd index 59a899f6..78b9690f 100644 --- a/python/docs/index.qmd +++ b/python/docs/index.qmd @@ -1,10 +1,14 @@ # bvhar -This is a python version for [`bvhar`](https://cloud.r-project.org/web/packages/bvhar/index.html) package. +This is a Python version for [`bvhar`](https://cloud.r-project.org/web/packages/bvhar/index.html) package. The package implements C++ headers made in R package. Learn more about [`bvhar for R`](https://ygeunkim.github.io/package/bvhar/index.html). +::: {.callout-note} +`bvhar` for Python is not ready to use. This page is rendered just for testing; yet. +::: + ## Eigen and boost setting `bvhar` C++ sources uses @@ -40,5 +44,6 @@ pip install -e . ## Usage -`bvhar` for python is not ready to use. +You can see the development status in PR [#10](https://github.com/ygeunkim/bvhar/pull/10). + diff --git a/python/docs/intro.qmd b/python/docs/intro.qmd index bdfc70ef..2345c505 100644 --- a/python/docs/intro.qmd +++ b/python/docs/intro.qmd @@ -22,8 +22,17 @@ etf_vix # Models +```{python} +from bvhar.model import VarOls, VharOls +``` + ## VAR +```{python} +fit_var = VarOls(etf_vix, 1, True) +fit_var.fit() +``` + ## VHAR ## BVAR diff --git a/python/pyproject.toml b/python/pyproject.toml index 31df082e..2009cbe3 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -61,6 +61,11 @@ doc = [ test = [ "pytest" ] +dev = [ + "pytest", + "jupyter", + "quartodoc" +] [build-system] requires = [