diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..3550a30f2 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 6d9e2d3b9..a25501119 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -2,12 +2,6 @@ name: Testing on: workflow_call: jobs: - rust: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@v6 - - name: Perform tests for rust modules - run: cargo test python: runs-on: ubuntu-24.04 strategy: diff --git a/.gitignore b/.gitignore index 177afcfba..32205f776 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,6 @@ requirements.* /scripts/ .dmypy.json tmp -.envrc +.direnv **/.DS_Store +result diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 2b687658d..000000000 --- a/Cargo.lock +++ /dev/null @@ -1,172 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "indoc" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" -dependencies = [ - "rustversion", -] - -[[package]] -name = "libc" -version = "0.2.183" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" - -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" - -[[package]] -name = "portable-atomic" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" - -[[package]] -name = "proc-macro2" -version = "1.0.106" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "pyo3" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab53c047fcd1a1d2a8820fe84f05d6be69e9526be40cb03b73f86b6b03e6d87d" -dependencies = [ - "indoc", - "libc", - "memoffset", - "once_cell", - "portable-atomic", - "pyo3-build-config", - "pyo3-ffi", - "pyo3-macros", - "unindent", -] - -[[package]] -name = "pyo3-build-config" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b455933107de8642b4487ed26d912c2d899dec6114884214a0b3bb3be9261ea6" -dependencies = [ - "target-lexicon", -] - -[[package]] -name = "pyo3-ffi" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c85c9cbfaddf651b1221594209aed57e9e5cff63c4d11d1feead529b872a089" -dependencies = [ - "libc", - "pyo3-build-config", -] - -[[package]] -name = "pyo3-macros" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5b10c9bf9888125d917fb4d2ca2d25c8df94c7ab5a52e13313a07e050a3b02" -dependencies = [ - "proc-macro2", - "pyo3-macros-backend", - "quote", - "syn", -] - -[[package]] -name = "pyo3-macros-backend" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b51720d314836e53327f5871d4c0cfb4fb37cc2c4a11cc71907a86342c40f9" -dependencies = [ - "heck", - "proc-macro2", - "pyo3-build-config", - "quote", - "syn", -] - -[[package]] -name = "quote" -version = "1.0.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rust" -version = "0.1.0" -dependencies = [ - "pyo3", -] - -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - -[[package]] -name = "syn" -version = "2.0.117" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "target-lexicon" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" - -[[package]] -name = "unicode-ident" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" - -[[package]] -name = "unindent" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index aa440645a..000000000 --- a/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "rust" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -name = "rust" -path = "rust/lib.rs" -crate-type = ["cdylib"] - -[dependencies] -pyo3 = "0.27.1" diff --git a/Dockerfile b/Dockerfile index 86f9c6de8..1b8c5a67a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,10 +12,6 @@ RUN apt-get update && \ RUN python -m venv --upgrade-deps /opt/venv -# Install the Rust toolchain -RUN curl https://sh.rustup.rs -sSf | bash -s -- -y -ENV PATH="/opt/venv/bin:/root/.cargo/bin:${PATH}" - # Install uv 0.10.9 COPY --from=ghcr.io/astral-sh/uv:0.10.9 /uv /uvx /bin/ @@ -50,7 +46,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \ # Uninstall dependencies from pyproject.toml:build-system.requires RUN --mount=type=cache,target=/root/.cache/uv \ - uv pip uninstall setuptools setuptools-scm setuptools-rust wheel + uv pip uninstall setuptools setuptools-scm wheel FROM registry-1.docker.io/library/python:${PYTHON_VERSION}-slim AS prod diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 81ba8b93f..000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include Cargo.toml -recursive-include rust * diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..61f0d1fcb --- /dev/null +++ b/flake.lock @@ -0,0 +1,99 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1774709303, + "narHash": "sha256-D3Q07BbIA2KnTcSXIqqu9P586uWxN74zNoCH3h2ESHg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "8110df5ad7abf5d4c0f6fb0f8f978390e77f9685", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pyproject-build-systems": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "pyproject-nix": [ + "pyproject-nix" + ], + "uv2nix": [ + "uv2nix" + ] + }, + "locked": { + "lastModified": 1773870109, + "narHash": "sha256-ZoTdqZP03DcdoyxvpFHCAek4bkPUTUPUF3oCCgc3dP4=", + "owner": "pyproject-nix", + "repo": "build-system-pkgs", + "rev": "b6e74f433b02fa4b8a7965ee24680f4867e2926f", + "type": "github" + }, + "original": { + "owner": "pyproject-nix", + "repo": "build-system-pkgs", + "type": "github" + } + }, + "pyproject-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1774498001, + "narHash": "sha256-wTfdyzzrmpuqt4TQQNqilF91v0m5Mh1stNy9h7a/WK4=", + "owner": "pyproject-nix", + "repo": "pyproject.nix", + "rev": "794afa6eb588b498344f2eaa36ab1ceb7e6b0b09", + "type": "github" + }, + "original": { + "owner": "pyproject-nix", + "repo": "pyproject.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "pyproject-build-systems": "pyproject-build-systems", + "pyproject-nix": "pyproject-nix", + "uv2nix": "uv2nix" + } + }, + "uv2nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "pyproject-nix": [ + "pyproject-nix" + ] + }, + "locked": { + "lastModified": 1774929536, + "narHash": "sha256-dMTjy8hu4XFAdNHdcLtCryN3SHqSUFHHqDLep+3b2v4=", + "owner": "pyproject-nix", + "repo": "uv2nix", + "rev": "5d0e883867b1cf53263fcf1bfd34542d40abf5a9", + "type": "github" + }, + "original": { + "owner": "pyproject-nix", + "repo": "uv2nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..0a45a8025 --- /dev/null +++ b/flake.nix @@ -0,0 +1,123 @@ +{ + description = "logprep allows to collect, process and forward log messages from various data sources"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + pyproject-nix = { + url = "github:pyproject-nix/pyproject.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + uv2nix = { + url = "github:pyproject-nix/uv2nix"; + inputs.pyproject-nix.follows = "pyproject-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + pyproject-build-systems = { + url = "github:pyproject-nix/build-system-pkgs"; + inputs.pyproject-nix.follows = "pyproject-nix"; + inputs.uv2nix.follows = "uv2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + nixpkgs, + pyproject-nix, + uv2nix, + pyproject-build-systems, + ... + }: + let + inherit (nixpkgs) lib; + forAllSystems = lib.genAttrs lib.systems.flakeExposed; + + workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; }; + + overlay = workspace.mkPyprojectOverlay { + sourcePreference = "wheel"; + }; + + editableOverlay = workspace.mkEditablePyprojectOverlay { + root = "$REPO_ROOT"; + }; + + pythonSets = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + python = lib.head (pyproject-nix.lib.util.filterPythonInterpreters { + inherit (workspace) requires-python; + inherit (pkgs) pythonInterpreters; + }); + + in + (pkgs.callPackage pyproject-nix.build.packages { + inherit python; + }).overrideScope + ( + lib.composeManyExtensions [ + pyproject-build-systems.overlays.wheel + overlay + ] + ) + ); + in + { + devShells = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + pythonSet = pythonSets.${system}.overrideScope editableOverlay; + virtualenv = pythonSet.mkVirtualEnv "logprep-dev-env" workspace.deps.all; + in + { + default = pkgs.mkShell { + packages = [ + virtualenv + pkgs.uv + pkgs.kubernetes-helm + pkgs.basedpyright + ]; + + env = { + UV_NO_SYNC = "1"; + UV_PYTHON = pythonSet.python.interpreter; + UV_PYTHON_DOWNLOADS = "never"; + }; + + shellHook = '' + unset PYTHONPATH + export REPO_ROOT=$(git rev-parse --show-toplevel) + ''; + }; + } + ); + + packages = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + logprep = pythonSets.${system}.mkVirtualEnv "logprep-env" workspace.deps.default; + in + { + default = logprep; + + docker = pkgs.dockerTools.buildImage { + name = "logprep"; + tag = "latest"; + + copyToRoot = logprep; + + config = { + Cmd = [ "logprep"]; + }; + }; + } + ); + }; +} diff --git a/pyproject.toml b/pyproject.toml index b032b282c..9b8a378a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,6 @@ requires = [ "setuptools>=82.0.0", "setuptools-scm>=9.2.2", "wheel", - "setuptools-rust", ] build-backend = "setuptools.build_meta" @@ -14,13 +13,6 @@ packages = ["logprep"] [tool.setuptools_scm] fallback_version = "0.0.0" -[[tool.setuptools-rust.ext-modules]] -# Private Rust extension module to be nested into the Python package -target = "rust" # The last part of the name (e.g. "_lib") has to match lib.name in Cargo.toml, -# but you can add a prefix to nest it inside of a Python package. -path = "Cargo.toml" # Default value, can be omitted -binding = "PyO3" # Default value, can be omitted - [project] name = "logprep" description = "Logprep allows to collect, process and forward log messages from various data sources." @@ -156,11 +148,6 @@ profile = "black" build = "cp311-* cp312-* cp313-* cp314-*" skip = "*pp* *i686-unknown-linux-musl*" -[tool.cibuildwheel.linux] -archs = "x86_64 i686 aarch64" -before-build = "curl -sSf https://sh.rustup.rs | sh -s -- -y" -environment = 'PATH=$HOME/.cargo/bin:$PATH' - [tool.pylint.MAIN] ignore = ".venv" fail-under = 9.5 diff --git a/rust/.gitignore b/rust/.gitignore deleted file mode 100644 index c8f044299..000000000 --- a/rust/.gitignore +++ /dev/null @@ -1,72 +0,0 @@ -/target - -# Byte-compiled / optimized / DLL files -__pycache__/ -.pytest_cache/ -*.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -.venv/ -env/ -bin/ -build/ -develop-eggs/ -dist/ -eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -include/ -man/ -venv/ -*.egg-info/ -.installed.cfg -*.egg - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt -pip-selfcheck.json - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.cache -nosetests.xml -coverage.xml - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Rope -.ropeproject - -# Django stuff: -*.log -*.pot - -.DS_Store - -# Sphinx documentation -docs/_build/ - -# PyCharm -.idea/ - -# VSCode -.vscode/ - -# Pyenv -.python-version diff --git a/rust/lib.rs b/rust/lib.rs deleted file mode 100644 index de1024aff..000000000 --- a/rust/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -mod tests; -use pyo3::prelude::*; - -/// Formats the sum of two numbers as string. -#[pyfunction] -fn sum_as_string(a: usize, b: usize) -> PyResult { - Ok((a + b).to_string()) -} - -/// A Python module implemented in Rust. -#[pymodule] -fn rust(m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; - Ok(()) -} diff --git a/rust/tests/mod.rs b/rust/tests/mod.rs deleted file mode 100644 index d84a168fa..000000000 --- a/rust/tests/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[cfg(test)] -#[test] -fn it_works() { - assert_eq!("4", "4"); -} diff --git a/tests/unit/rust/__init__.py b/tests/unit/rust/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/unit/rust/test_rust.py b/tests/unit/rust/test_rust.py deleted file mode 100644 index 9bf95b675..000000000 --- a/tests/unit/rust/test_rust.py +++ /dev/null @@ -1,5 +0,0 @@ -import rust - - -def test_example(): - assert rust.sum_as_string(1, 2) == "3"