Skip to content

Commit 4b6fa85

Browse files
committed
Refactor repo's files
This is intended to allow calling both rust lib and python lib "cpp-linter" when installing with cargo or pip. Also when using python, the entry point script is now the same as it is in v1.x: `cpp_linter.main()`.
1 parent 4f9b912 commit 4b6fa85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+65
-104
lines changed

.github/workflows/build-docs.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ jobs:
3434
- name: Install mdbook
3535
uses: taiki-e/install-action@v2
3636
with:
37-
tool: mdbook,cargo-binstall
37+
tool: mdbook,cargo-binstall,just
3838
- name: Install mdbook plugins
3939
run: cargo binstall -y mdbook-alerts
4040
- name: Build book
41-
run: mdbook build docs
41+
run: just docs-build
4242
- name: Upload docs build as artifact
4343
uses: actions/upload-artifact@v4
4444
with:
@@ -63,7 +63,11 @@ jobs:
6363
with:
6464
path: ~/.cargo
6565
key: ${{ runner.os }}-docs-cargo-${{ hashFiles('Cargo.lock') }}
66-
- run: cargo doc --no-deps --manifest-path cpp-linter-lib/Cargo.toml
66+
- name: Install mdbook
67+
uses: taiki-e/install-action@v2
68+
with:
69+
tool: just
70+
- run: just docs-rs
6771
- name: upload rustdoc build as artifact
6872
uses: actions/upload-artifact@v4
6973
with:

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ repos:
33
rev: v4.6.0
44
hooks:
55
- id: trailing-whitespace
6-
exclude: cpp-linter-lib/tests/.*\.(?:patch|diff)
6+
exclude: cpp-linter/tests/.*\.(?:patch|diff)
77
- id: end-of-file-fixer
88
- id: check-docstring-first
99
- id: check-added-large-files

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
22

33
[workspace]
4-
members = ["cpp-linter-lib", "cpp-linter-py", "docs"]
4+
members = ["cpp-linter", "py-binding", "docs"]
55
resolver = "2"
66

77
[workspace.package]

cpp-linter-py/cpp_linter/__init__.py

-8
This file was deleted.

cpp-linter-py/cpp_linter/entry_point.py

-29
This file was deleted.

cpp-linter-py/src/lib.rs

-25
This file was deleted.
File renamed without changes.

cpp-linter-lib/Cargo.toml renamed to cpp-linter/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cpp-linter-lib"
2+
name = "cpp-linter"
33
edition = "2021"
44
repository = "https://github.com/cpp-linter/cpp_linter_rs/tree/main/cpp-linter-lib"
55
readme = "README.md"
File renamed without changes.
File renamed without changes.

cpp-linter-lib/src/common_fs/mod.rs renamed to cpp-linter/src/common_fs/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ mod test {
279279

280280
#[test]
281281
fn normalize_no_root() {
282-
let src = PathBuf::from("../cpp-linter-lib");
282+
let src = PathBuf::from("../cpp-linter");
283283
let mut cur_dir = current_dir().unwrap();
284284
cur_dir = cur_dir
285285
.strip_prefix(current_dir().unwrap().parent().unwrap())
File renamed without changes.
File renamed without changes.
File renamed without changes.

cpp-linter-lib/src/main.rs renamed to cpp-linter/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// This crate is the binary executable's entrypoint.
33
use std::env;
44

5-
use cpp_linter_lib::run::run_main;
5+
use ::cpp_linter::run::run_main;
66

77
/// This function simply forwards CLI args to [`run_main()`].
88
#[tokio::main]
File renamed without changes.
File renamed without changes.

cpp-linter-lib/tests/comments.rs renamed to cpp-linter/tests/comments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use chrono::Utc;
2-
use cpp_linter_lib::cli::{LinesChangedOnly, ThreadComments};
3-
use cpp_linter_lib::run::run_main;
2+
use cpp_linter::cli::{LinesChangedOnly, ThreadComments};
3+
use cpp_linter::run::run_main;
44
use mockito::Matcher;
55
use std::{env, fmt::Display, io::Write, path::Path};
66
use tempfile::NamedTempFile;
File renamed without changes.
File renamed without changes.
File renamed without changes.

cpp-linter-lib/tests/paginated_changed_files.rs renamed to cpp-linter/tests/paginated_changed_files.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use common::{create_test_space, mock_server};
44
use mockito::Matcher;
55
use tempfile::{NamedTempFile, TempDir};
66

7-
use cpp_linter_lib::{
7+
use cpp_linter::{
88
common_fs::FileFilter,
99
rest_api::{github_api::GithubApiClient, RestApiClient},
1010
};

cpp-linter-lib/tests/reviews.rs renamed to cpp-linter/tests/reviews.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use chrono::Utc;
2-
use cpp_linter_lib::{
2+
use cpp_linter::{
33
cli::LinesChangedOnly,
44
rest_api::{COMMENT_MARKER, USER_OUTREACH},
55
run::run_main,

docs/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ homepage.workspace = true
99
license.workspace = true
1010

1111
[dependencies]
12-
cpp-linter-lib = { path = "../cpp-linter-lib" }
12+
cpp-linter = { path = "../cpp-linter" }
1313
clap = "4.5.17"
1414
mdbook = "0.4.40"
1515
semver = "1.0.23"

docs/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use semver::{Version, VersionReq};
1212
use std::io;
1313
use std::process;
1414

15-
extern crate cpp_linter_lib;
15+
extern crate cpp_linter;
1616

1717
use cli_gen_lib::CliGen;
1818

@@ -82,7 +82,7 @@ mod cli_gen_lib {
8282
use mdbook::book::Book;
8383
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
8484

85-
use cpp_linter_lib::cli;
85+
use cpp_linter::cli;
8686

8787
pub struct CliGen;
8888

justfile

+4-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
11
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
22

3-
# activate python venv
4-
[group("python")]
5-
[windows]
6-
venv:
7-
./.env/Scripts/activate
8-
9-
# activate python venv
10-
[group("python")]
11-
[linux]
12-
venv:
13-
. ./.env/bin/activate
14-
15-
# install python bindings
16-
[group("python")]
17-
py-dev:
18-
maturin dev --manifest-path cpp-linter-py/Cargo.toml
19-
203
# run the test suite
214
[group("code coverage")]
225
test arg='':
236
cargo llvm-cov --no-report \
24-
nextest --manifest-path cpp-linter-lib/Cargo.toml \
7+
nextest --manifest-path cpp-linter/Cargo.toml \
258
--lib --tests --color always {{ arg }}
269

2710
# Clear previous test build artifacts
@@ -60,17 +43,17 @@ docs-build open='':
6043
# rust docs
6144
[group("docs")]
6245
docs-rs open='':
63-
cargo doc --no-deps --lib --manifest-path cpp-linter-lib/Cargo.toml {{ open }}
46+
cargo doc --no-deps --lib --manifest-path cpp-linter/Cargo.toml {{ open }}
6447

6548
# run cpp-linter native binary
6649
[group("bin")]
6750
run *args:
68-
cargo run --bin cpp-linter --manifest-path cpp-linter-lib/Cargo.toml -- {{ args }}
51+
cargo run --bin cpp-linter --manifest-path cpp-linter/Cargo.toml -- {{ args }}
6952

7053
# build the native binary
7154
[group("bin")]
7255
build *args='':
73-
cargo build --bin cpp-linter --manifest-path cpp-linter-lib/Cargo.toml {{ args }}
56+
cargo build --bin cpp-linter --manifest-path cpp-linter/Cargo.toml {{ args }}
7457

7558
# run clippy and rustfmt
7659
lint:
File renamed without changes.

cpp-linter-py/Cargo.toml renamed to py-binding/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ crate-type = ["cdylib"]
1717

1818
[dependencies]
1919
pyo3 = { version = "0.22.3", features = ["extension-module"] }
20-
cpp-linter-lib = { path = "../cpp-linter-lib" }
20+
cpp-linter = { path = "../cpp-linter" }
2121
tokio = "1.40.0"
2222

2323
[features]
24-
openssl-vendored = ["cpp-linter-lib/openssl-vendored"]
24+
openssl-vendored = ["cpp-linter/openssl-vendored"]

py-binding/cpp_linter/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# type: ignore
2+
# ruff: noqa: F405 F403
3+
import sys
4+
from .cpp_linter import *
5+
6+
__doc__ = cpp_linter.__doc__
7+
if hasattr(cpp_linter, "__all__"):
8+
__all__ = list(filter(lambda x: x != "main", cpp_linter.__all__))
9+
10+
11+
def main():
12+
"""The main entrypoint for the python frontend. See our rust docs for more info on
13+
the backend (implemented in rust)"""
14+
sys.exit(cpp_linter.main(sys.argv))

cpp-linter-py/pyproject.toml renamed to py-binding/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ classifiers = [
3333
dynamic = ["version"]
3434

3535
[project.scripts]
36-
cpp-linter = "cpp_linter.entry_point:main"
36+
cpp-linter = "cpp_linter:main"
3737

3838
[project.urls]
3939
source = "https://github.com/cpp-linter/cpp-linter"
File renamed without changes.

py-binding/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use pyo3::prelude::*;
2+
use tokio::runtime::Builder;
3+
4+
use ::cpp_linter::run::run_main;
5+
6+
/// A wrapper for the ``::cpp_linter::run::run_main()```
7+
#[pyfunction]
8+
fn main(args: Vec<String>) -> PyResult<i32> {
9+
Builder::new_multi_thread()
10+
.enable_all()
11+
.build()
12+
.unwrap()
13+
.block_on(async { Ok(run_main(args).await) })
14+
}
15+
16+
/// The python binding for the cpp_linter package. It only exposes a ``main()`` function
17+
/// that is used as the entrypoint script.
18+
#[pymodule]
19+
fn cpp_linter(m: &Bound<'_, PyModule>) -> PyResult<()> {
20+
m.add_function(wrap_pyfunction!(main, m)?)?;
21+
Ok(())
22+
}

0 commit comments

Comments
 (0)