Skip to content

Commit 1156624

Browse files
change to using bin bindings for maturin and PyO3
1 parent 59462df commit 1156624

File tree

4 files changed

+108
-14
lines changed

4 files changed

+108
-14
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
uses: PyO3/maturin-action@v1
4949
with:
5050
target: ${{ matrix.platform.target }}
51-
args: --release --out dist --find-interpreter --features extension-module
51+
args: --release --out dist --find-interpreter
5252
sccache: "true"
5353
manylinux: auto
5454

@@ -82,7 +82,7 @@ jobs:
8282
uses: PyO3/maturin-action@v1
8383
with:
8484
target: ${{ matrix.platform.target }}
85-
args: --release --out dist --find-interpreter --features extension-module
85+
args: --release --out dist --find-interpreter
8686
manylinux: musllinux_1_2
8787

8888
- name: Upload wheels
@@ -112,7 +112,7 @@ jobs:
112112
uses: PyO3/maturin-action@v1
113113
with:
114114
target: ${{ matrix.platform.target }}
115-
args: --release --out dist --find-interpreter --features extension-module
115+
args: --release --out dist --find-interpreter
116116
sccache: "true"
117117

118118
- name: Upload wheels
@@ -141,7 +141,7 @@ jobs:
141141
uses: PyO3/maturin-action@v1
142142
with:
143143
target: ${{ matrix.platform.target }}
144-
args: --release --out dist --find-interpreter --features extension-module
144+
args: --release --out dist --find-interpreter
145145
sccache: "true"
146146

147147
- name: Upload wheels

crates/djls/Cargo.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@ name = "djls"
33
version = "5.2.0-alpha"
44
edition = "2021"
55

6-
[lib]
6+
[[bin]]
77
name = "djls"
8-
crate-type = ["cdylib"]
8+
path = "src/main.rs"
99

1010
[features]
11-
extension-module = [
12-
"djls-server/extension-module",
13-
"djls-project/extension-module",
14-
"pyo3/extension-module"
15-
]
1611
default = []
1712

1813
[dependencies]

crates/djls/src/main.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
mod commands;
2+
3+
use crate::commands::Serve;
4+
use anyhow::Result;
5+
use clap::{Parser, Subcommand};
6+
use pyo3;
7+
use std::process::ExitCode;
8+
9+
#[derive(Parser)]
10+
#[command(name = "djls")]
11+
#[command(version, about, long_about = None)]
12+
pub struct Cli {
13+
#[command(subcommand)]
14+
command: Command,
15+
16+
#[command(flatten)]
17+
args: Args,
18+
}
19+
20+
#[derive(Debug, Subcommand)]
21+
enum Command {
22+
/// Start the LSP server
23+
Serve(Serve),
24+
}
25+
26+
#[derive(Parser)]
27+
pub struct Args {
28+
#[command(flatten)]
29+
global: GlobalArgs,
30+
}
31+
32+
#[derive(Parser, Debug, Clone)]
33+
struct GlobalArgs {
34+
/// Do not print any output.
35+
#[arg(global = true, long, short, conflicts_with = "verbose")]
36+
pub quiet: bool,
37+
38+
/// Use verbose output.
39+
#[arg(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "quiet")]
40+
pub verbose: u8,
41+
}
42+
43+
async fn run() -> Result<ExitCode> {
44+
let cli = Cli::parse();
45+
46+
match cli.command {
47+
Command::Serve(_serve) => djls_server::serve().await?,
48+
}
49+
50+
Ok(ExitCode::SUCCESS)
51+
}
52+
53+
fn main() -> ExitCode {
54+
// Initialize Python interpreter
55+
pyo3::prepare_freethreaded_python();
56+
57+
let runtime = tokio::runtime::Runtime::new().unwrap();
58+
let local = tokio::task::LocalSet::new();
59+
let exit_code = local.block_on(&runtime, async move {
60+
tokio::select! {
61+
// The main CLI program
62+
result = run() => {
63+
match result {
64+
Ok(code) => code,
65+
Err(e) => {
66+
eprintln!("Error: {}", e);
67+
if let Some(source) = e.source() {
68+
eprintln!("Caused by: {}", source);
69+
}
70+
ExitCode::FAILURE
71+
}
72+
}
73+
}
74+
// Ctrl+C handling
75+
_ = tokio::signal::ctrl_c() => {
76+
println!("\nReceived Ctrl+C, shutting down...");
77+
// Cleanup code here if needed
78+
ExitCode::from(130) // Standard Ctrl+C exit code
79+
}
80+
// SIGTERM handling (Unix only)
81+
_ = async {
82+
#[cfg(unix)]
83+
{
84+
use tokio::signal::unix::{signal, SignalKind};
85+
let mut term = signal(SignalKind::terminate()).unwrap();
86+
term.recv().await;
87+
}
88+
#[cfg(not(unix))]
89+
{
90+
// On non-unix platforms, this future never completes
91+
std::future::pending::<()>().await;
92+
}
93+
} => {
94+
println!("\nReceived termination signal, shutting down...");
95+
ExitCode::from(143) // Standard SIGTERM exit code
96+
}
97+
}
98+
});
99+
100+
exit_code
101+
}

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ classifiers = [
6868
"Topic :: Text Editors :: Integrated Development Environments (IDE)"
6969
]
7070

71-
[project.scripts]
72-
djls = "djls:entrypoint"
73-
7471
[project.urls]
7572
Documentation = "https://django-language-server.readthedocs.io/"
7673
Issues = "https://github.com/joshuadavidthomas/django-language-server/issues"
@@ -110,6 +107,7 @@ indent_size = 2
110107

111108
[tool.maturin]
112109
manifest-path = "crates/djls/Cargo.toml"
110+
bindings = "bin"
113111
strip = true
114112
include = [
115113
{ path = "LICENSE", format = "sdist" },

0 commit comments

Comments
 (0)