From c9775947f9725b17f896351083ddd2cef123adc9 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Thu, 2 Nov 2023 14:55:35 -0400 Subject: [PATCH] Make keyring a submodule of secrets sdk Signed-off-by: Timothy Johnson --- .github/workflows/secrets-sdk.yml | 26 +++++++++---------- .vscode/settings.json | 1 + requirements.txt | 1 + .../secrets_for_zowe_sdk}/.gitignore | 0 .../secrets_for_zowe_sdk}/Cargo.lock | 0 .../secrets_for_zowe_sdk}/Cargo.toml | 0 .../zowe/secrets_for_zowe_sdk/__init__.py | 0 .../secrets_for_zowe_sdk}/pyproject.toml | 2 +- .../secrets_for_zowe_sdk}/src/lib.rs | 22 +++++++++++----- 9 files changed, 31 insertions(+), 21 deletions(-) rename src/secrets/{src/keyring => zowe/secrets_for_zowe_sdk}/.gitignore (100%) rename src/secrets/{src/keyring => zowe/secrets_for_zowe_sdk}/Cargo.lock (100%) rename src/secrets/{src/keyring => zowe/secrets_for_zowe_sdk}/Cargo.toml (100%) delete mode 100644 src/secrets/zowe/secrets_for_zowe_sdk/__init__.py rename src/secrets/{src/keyring => zowe/secrets_for_zowe_sdk}/pyproject.toml (89%) rename src/secrets/{src/keyring => zowe/secrets_for_zowe_sdk}/src/lib.rs (65%) diff --git a/.github/workflows/secrets-sdk.yml b/.github/workflows/secrets-sdk.yml index c37aa745..0ba04740 100644 --- a/.github/workflows/secrets-sdk.yml +++ b/.github/workflows/secrets-sdk.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - target: [x86_64, x86, aarch64, armv7, s390x, ppc64le] + target: [x86_64, x86, aarch64, armv7, s390x] fail-fast: false steps: - uses: actions/checkout@v3 @@ -36,11 +36,11 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.target }} - args: --release --out dist --interpreter python3.{7..12} + args: --release --out dist --interpreter python3.{7..12} --skip-auditwheel sccache: "true" manylinux: auto docker-options: -e PKG_CONFIG_SYSROOT_DIR -e PKG_CONFIG_PATH - working-directory: src/secrets/src/keyring + working-directory: src/secrets/zowe/secrets_for_zowe_sdk before-script-linux: | if command -v yum &> /dev/null; then yum update && yum install -y libsecret-devel.${{ env.CROSS_DEB_ARCH }} pkgconfig @@ -55,7 +55,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: wheels - path: src/secrets/src/keyring/dist + path: src/secrets/zowe/secrets_for_zowe_sdk/dist windows: runs-on: windows-latest @@ -73,14 +73,14 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.target }} - args: --release --out dist --find-interpreter + args: --release --out dist --interpreter python3.{7..12} sccache: "true" - working-directory: src/secrets/src/keyring + working-directory: src/secrets/zowe/secrets_for_zowe_sdk - name: Upload wheels uses: actions/upload-artifact@v3 with: name: wheels - path: src/secrets/src/keyring/dist + path: src/secrets/zowe/secrets_for_zowe_sdk/dist macos: runs-on: macos-latest @@ -97,14 +97,14 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.target }} - args: --release --out dist --find-interpreter + args: --release --out dist --interpreter python3.{7..12} sccache: "true" - working-directory: src/secrets/src/keyring + working-directory: src/secrets/zowe/secrets_for_zowe_sdk - name: Upload wheels uses: actions/upload-artifact@v3 with: name: wheels - path: src/secrets/src/keyring/dist + path: src/secrets/zowe/secrets_for_zowe_sdk/dist sdist: runs-on: ubuntu-latest @@ -115,12 +115,12 @@ jobs: with: command: sdist args: --out dist - working-directory: src/secrets/src/keyring + working-directory: src/secrets/zowe/secrets_for_zowe_sdk - name: Upload sdist uses: actions/upload-artifact@v3 with: name: wheels - path: src/secrets/src/keyring/dist + path: src/secrets/zowe/secrets_for_zowe_sdk/dist # release: # name: Release @@ -138,4 +138,4 @@ jobs: # with: # command: upload # args: --non-interactive --skip-existing * - # working-directory: src/secrets/src/keyring + # working-directory: src/secrets/zowe/secrets_for_zowe_sdk diff --git a/.vscode/settings.json b/.vscode/settings.json index baf3b191..414fbd92 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "editor.formatOnSave": true, "python.formatting.provider": "black", + "rust-analyzer.linkedProjects": ["./src/secrets/src/keyring/Cargo.toml"], "[python]": { "editor.codeActionsOnSave": { "source.organizeImports": true diff --git a/requirements.txt b/requirements.txt index c685de39..050d602a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ isort jsonschema==4.17.3 keyring lxml==4.9.3 +maturin mccabe==0.6.1 nose2==0.10.0 pycodestyle==2.6.0 diff --git a/src/secrets/src/keyring/.gitignore b/src/secrets/zowe/secrets_for_zowe_sdk/.gitignore similarity index 100% rename from src/secrets/src/keyring/.gitignore rename to src/secrets/zowe/secrets_for_zowe_sdk/.gitignore diff --git a/src/secrets/src/keyring/Cargo.lock b/src/secrets/zowe/secrets_for_zowe_sdk/Cargo.lock similarity index 100% rename from src/secrets/src/keyring/Cargo.lock rename to src/secrets/zowe/secrets_for_zowe_sdk/Cargo.lock diff --git a/src/secrets/src/keyring/Cargo.toml b/src/secrets/zowe/secrets_for_zowe_sdk/Cargo.toml similarity index 100% rename from src/secrets/src/keyring/Cargo.toml rename to src/secrets/zowe/secrets_for_zowe_sdk/Cargo.toml diff --git a/src/secrets/zowe/secrets_for_zowe_sdk/__init__.py b/src/secrets/zowe/secrets_for_zowe_sdk/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/secrets/src/keyring/pyproject.toml b/src/secrets/zowe/secrets_for_zowe_sdk/pyproject.toml similarity index 89% rename from src/secrets/src/keyring/pyproject.toml rename to src/secrets/zowe/secrets_for_zowe_sdk/pyproject.toml index 0fc19cf2..e78b6e8f 100644 --- a/src/secrets/src/keyring/pyproject.toml +++ b/src/secrets/zowe/secrets_for_zowe_sdk/pyproject.toml @@ -3,7 +3,7 @@ requires = ["maturin>=1.3,<2.0"] build-backend = "maturin" [project] -name = "keyring" +name = "zowe.secrets_for_zowe_sdk" requires-python = ">=3.7" classifiers = [ "Programming Language :: Rust", diff --git a/src/secrets/src/keyring/src/lib.rs b/src/secrets/zowe/secrets_for_zowe_sdk/src/lib.rs similarity index 65% rename from src/secrets/src/keyring/src/lib.rs rename to src/secrets/zowe/secrets_for_zowe_sdk/src/lib.rs index 6348178f..88205fe4 100644 --- a/src/secrets/src/keyring/src/lib.rs +++ b/src/secrets/zowe/secrets_for_zowe_sdk/src/lib.rs @@ -1,5 +1,5 @@ use pyo3::exceptions::PyValueError; -use pyo3::prelude::*; +use pyo3::{prelude::*, py_run}; extern crate secrets_core; use secrets_core::*; @@ -50,11 +50,19 @@ fn find_credentials(service: String) -> PyResult> { /// A Python module implemented in Rust. #[pymodule] -fn keyring_test(_py: Python, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(get_password, m)?)?; - m.add_function(wrap_pyfunction!(set_password, m)?)?; - m.add_function(wrap_pyfunction!(delete_password, m)?)?; - m.add_function(wrap_pyfunction!(find_password, m)?)?; - m.add_function(wrap_pyfunction!(find_credentials, m)?)?; +fn zowe_secrets_for_zowe_sdk(py: Python, module: &PyModule) -> PyResult<()> { + let submodule = PyModule::new(py, "zowe.secrets_for_zowe_sdk.keyring")?; + submodule.add_function(wrap_pyfunction!(get_password, submodule)?)?; + submodule.add_function(wrap_pyfunction!(set_password, submodule)?)?; + submodule.add_function(wrap_pyfunction!(delete_password, submodule)?)?; + submodule.add_function(wrap_pyfunction!(find_password, submodule)?)?; + submodule.add_function(wrap_pyfunction!(find_credentials, submodule)?)?; + // Hack from https://github.com/PyO3/pyo3/issues/1517 + py_run!( + py, + submodule, + "import sys; sys.modules['zowe.secrets_for_zowe_sdk.keyring'] = submodule" + ); + module.add_submodule(submodule)?; Ok(()) }