Skip to content

Commit

Permalink
Merge pull request #14 from KapiWow/1-windows-support
Browse files Browse the repository at this point in the history
feat: windows support
  • Loading branch information
nmammeri authored Oct 29, 2024
2 parents 2c84a50 + 96dc04f commit c07969e
Show file tree
Hide file tree
Showing 13 changed files with 6,865 additions and 2,615 deletions.
89 changes: 44 additions & 45 deletions .github/workflows/release_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,48 +91,47 @@ jobs:
cd bindings/extractous-python
pytest -s
#
# windows:
# runs-on: ${{ matrix.platform.runner }}
# strategy:
# matrix:
# platform:
# - runner: windows-latest
# target: x64
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v5
# with:
# python-version: '3.8'
# architecture: ${{ matrix.platform.target }}
# - uses: graalvm/[email protected]
# with:
# java-version: '22'
# distribution: 'graalvm-community'
# set-java-home: 'true'
# - name: Build wheels
# uses: PyO3/maturin-action@v1
# with:
# target: ${{ matrix.platform.target }}
# working-directory: "bindings/extractous-python"
# args: --release --out dist --find-interpreter
# sccache: 'true'
# - name: Upload wheels
# uses: actions/upload-artifact@v4
# with:
# name: wheels-windows-${{ matrix.platform.target }}
# path: bindings/extractous-python/dist
# - name: pytest
# if: ${{ !startsWith(matrix.platform.target, 'aarch64') }}
# shell: bash
# run: |
# set -e
# python3 -m venv .venv
# source .venv/Scripts/activate
# pip install extractous --find-links bindings/extractous-python/dist --force-reinstall
# pip install pytest scikit-learn
# cd bindings/extractous-python
# pytest -s
windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
architecture: ${{ matrix.platform.target }}
- uses: graalvm/[email protected]
with:
java-version: '22'
distribution: 'graalvm-community'
set-java-home: 'true'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
working-directory: "bindings/extractous-python"
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: bindings/extractous-python/dist
- name: pytest
if: ${{ !startsWith(matrix.platform.target, 'aarch64') }}
shell: cmd
run: |
python -m venv .venv
.venv\Scripts\activate.bat
pip install extractous --find-links bindings/extractous-python/dist --force-reinstall
pip install pytest scikit-learn
cd bindings\extractous-python
pytest -s
macos:
runs-on: ${{ matrix.platform.runner }}
Expand Down Expand Up @@ -205,7 +204,7 @@ jobs:
publish-to-testpypi:
name: Publish to TestPyPI
# publish to TestPyPI on any push
needs: [linux, macos, sdist]
needs: [linux, macos, windows, sdist]
runs-on: ubuntu-latest
environment:
name: testpypi
Expand All @@ -230,7 +229,7 @@ jobs:
name: Publish to PyPI
# only publish to PyPI on tag pushes
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, macos, sdist]
needs: [linux, macos, windows, sdist]
runs-on: ubuntu-latest
environment:
name: pypi
Expand All @@ -247,4 +246,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
packages-dir: bindings/extractous-python/dist
packages-dir: bindings/extractous-python/dist
5 changes: 2 additions & 3 deletions bindings/extractous-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "extractous"
version = '0.1.4'
version = '0.1.5'
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
Expand Down Expand Up @@ -65,6 +65,5 @@ rustc-args = ["-C", "link-arg=-Wl,-rpath,$ORIGIN"]
include = [
{path = "**/*.so", format = ["wheel"]},
{path = "**/*.dylib", format = ["wheel"]},
{path = "**/*.dll", format = ["wheel"]},
{path = "**/*.lib", format = ["wheel"]}
{path = "**/*.dll", format = ["wheel"]}
]
9 changes: 9 additions & 0 deletions bindings/extractous-python/python/extractous/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import os
from platform import system

# On Windows there is no equivalent way of setting RPATH
# This adds the current directory to PATH so that the graalvm libs will be found
if system() == "Windows":
libpath = os.path.dirname(__file__)
os.environ["PATH"] = libpath + os.pathsep + os.environ["PATH"]

from ._extractous import *

__doc__ = _extractous.__doc__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_extract_file_to_string(file_name, target_dist):
expected_result_filepath = f"../../test_files/expected_result/{file_name}.txt"
extractor = Extractor()
result = extractor.extract_file_to_string(original_filepath)
with open(expected_result_filepath, "r") as file:
with open(expected_result_filepath, "r", encoding="utf8") as file:
expected = file.read()

assert cosine_similarity(result, expected) > target_dist, \
Expand Down
2 changes: 1 addition & 1 deletion extractous-core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extractous-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "extractous"
version = "0.1.4"
version = "0.1.5"
edition = "2021"

description = """
Expand Down
20 changes: 14 additions & 6 deletions extractous-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::env;
use std::fs;
use std::io;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;

Expand Down Expand Up @@ -34,8 +33,11 @@ fn main() {
// Try to find already built libs
match find_already_built_libs(&out_dir) {
Some(libs_dir) => {
// If the libs are already built, copy them to the output directory
copy_build_artifacts(&libs_dir, vec![&libs_out_dir], false);
// ignore if libs_dir/.. is the same as out_dir
if out_dir.join("libs") != libs_dir {
// If the libs are already built, copy them to the output directory
copy_build_artifacts(&libs_dir, vec![&libs_out_dir], false);
}
}
None => {
// Launch the gradle build
Expand All @@ -52,7 +54,12 @@ fn main() {
println!("cargo:rustc-link-search={}", libs_out_dir.display());

// Tell cargo to tell rustc to link the `tika_native` shared library.
println!("cargo:rustc-link-lib=dylib=tika_native");
let lib_tika_name = if cfg!(target_os = "windows") {
"libtika_native"
} else {
"tika_native"
};
println!("cargo:rustc-link-lib=dylib={}", lib_tika_name);
}

/// Searches for directories two levels up from `out_dir` and checks if any of them
Expand Down Expand Up @@ -121,6 +128,7 @@ fn gradle_build(
// Launch the gradle build
Command::new(gradlew)
.current_dir(&tika_native_dir)
.arg("--no-daemon")
.arg("nativeCompile")
.env("JAVA_HOME", graalvm_home)
.status()
Expand Down Expand Up @@ -290,7 +298,7 @@ pub fn install_graalvm_ce(install_dir: &PathBuf) -> PathBuf {
// in case of a download error
let mut buffer: Vec<u8> = vec![];
io::copy(&mut response.bytes()
.expect(&format!("Failed to download GraalVM JDK from {}", base_url))
.unwrap_or_else(|_| panic!("Failed to download GraalVM JDK from {}", base_url))
.as_ref(), &mut buffer
).unwrap();
//let mut out = fs::File::create(&archive_path).unwrap();
Expand Down Expand Up @@ -335,4 +343,4 @@ pub fn install_graalvm_ce(install_dir: &PathBuf) -> PathBuf {
}

install_dir.join(main_dir)
}
}
Loading

0 comments on commit c07969e

Please sign in to comment.