Skip to content

Commit bba2e68

Browse files
committed
fix python binding's entry point
1 parent 12729b8 commit bba2e68

File tree

8 files changed

+17
-25
lines changed

8 files changed

+17
-25
lines changed

bindings/node/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ This script runs a simple test to ensure the native module was built correctly.
5858
| `build.rs` | The cargo-specific build script used when compiling the binding. |
5959
| `Cargo.toml` | Metadata about the binding's rust package (which _is not_ intended to be published to crates.io). |
6060
| `package.json` | Metadata about the npm package (platform agnostic). |
61+
| `cli.js` | The executable script invoked as a Command Line Interface. |
6162
| `index.d.ts` | The generated TypeScript typing info the describes the exposing functionality in the built native module. |
6263
| `index.js` | The generated script that delegates which platform-specific package to import. |
6364
| `cpp-linter.x-y-z.node` | Then native module built for a specific platform (where `x-y-z` denotes the platform's name using compilation target). |
6465

6566
Hidden files and folders are not described in the table above.
6667
If they are not ignored by a gitignore specification, then they should be considered
67-
important for maintenance or distribution.
68+
important only for maintenance or distribution.

bindings/python/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ cpp-linter -help
4646

4747
| Name | Description |
4848
|-----:|:------------|
49-
| `cpp_linter` | The pure python sources that wrap the rust binding. Typing information is located here. |
5049
| `src` | The location for all rust sources related to binding the cpp-linter library. |
5150
| `Cargo.toml` | Metadata about the binding's rust package (which _is not_ intended to be published to crates.io). |
51+
| `../../cpp_linter.pyi` | The typing stubs for the package (located in repo root). |
5252
| `../../pyproject.toml` | Metadata about the python package (located in repo root). |
5353
| `requirements-dev.txt` | The dependencies used in development (not needed for runtime/production). |
5454

5555
Hidden files and folders are not described in the table above.
5656
If they are not ignored by a gitignore specification, then they should be considered
57-
important for maintenance or distribution.
57+
important only for maintenance or distribution.

bindings/python/cpp_linter/__init__.py

-14
This file was deleted.

bindings/python/cpp_linter/cpp_linter.pyi

-3
This file was deleted.

bindings/python/cpp_linter/py.typed

Whitespace-only changes.

bindings/python/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
use pyo3::{exceptions::PyOSError, prelude::*};
2+
use std::env;
23
use tokio::runtime::Builder;
34

45
use ::cpp_linter::run::run_main;
56

67
/// A wrapper for the ``::cpp_linter::run::run_main()```
78
#[pyfunction]
8-
fn main(args: Vec<String>) -> PyResult<()> {
9+
#[pyo3(signature = (args = None))]
10+
fn main(args: Option<Vec<String>>) -> PyResult<()> {
11+
// exclude path to python interpreter
12+
let args = args.unwrap_or(env::args().collect::<Vec<String>>()[1..].to_vec());
913
Builder::new_multi_thread()
1014
.enable_all()
1115
.build()

cpp-linter/src/run.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ fn probe_ssl_certs() {
3232
/// The idea here is that all functionality is implemented in Rust. However, passing
3333
/// command line arguments is done differently in Python, node.js, or Rust.
3434
///
35-
/// - In python, the `sys.argv` list is passed from the `cpp_linter.main()`
36-
/// function to rust via the `cpp_linter.main()` binding (which wraps [`run_main()`]).
37-
/// - In node.js, the `process.argv` array is passed from `cli.js` module to
38-
/// rust via `index.node` module's `main()` (which wraps([`run_main()`])).
35+
/// - In python, the CLI arguments list is optionally passed to the binding's
36+
/// `cpp_linter.main()` function (which wraps [`run_main()`]). If no args are passed,
37+
/// then `cpp_linter.main()` uses [`std::env::args`] without the leading path to the
38+
/// python interpreter removed.
39+
/// - In node.js, the `process.argv` array (without the leading path to the node
40+
/// interpreter removed) is passed from `cli.js` module to rust via `index.node`
41+
/// module's `main()` (which wraps([`run_main()`])).
3942
/// - In rust, the [`std::env::args`] is passed to [`run_main()`] in the binary
4043
/// source `main.rs`.
4144
///

cpp_linter.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def main(args: list[str] | None = None) -> int: ...

0 commit comments

Comments
 (0)