From 10baf51d4e9827ef0ff16244d6fb1e7f09c691cb Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 5 Dec 2022 17:46:59 +0800 Subject: [PATCH] Feature gate `maturin new` and `maturin init` commands under the `scaffolding` feature --- Cargo.toml | 21 ++++++++++++++++----- src/lib.rs | 2 ++ src/main.rs | 10 ++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 75c9dd954..bd05b3d52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,9 +68,9 @@ tracing = "0.1.36" tracing-subscriber = { version = "0.3.15", features = ["env-filter"], optional = true } # project scaffolding, maturin new/init -dialoguer = { version = "0.10.2", default-features = false } -console = "0.15.2" -minijinja = "0.26.0" +dialoguer = { version = "0.10.2", default-features = false, optional = true } +console = { version = "0.15.2", optional = true } +minijinja = { version = "0.26.0", optional = true } # upload bytesize = { version = "1.0.1", optional = true } @@ -88,18 +88,29 @@ rustversion = "1.0.9" trycmd = "0.14.0" [features] -default = ["cross-compile", "log", "upload", "rustls"] +default = ["full", "rustls"] + +full = ["cross-compile", "log", "scaffolding", "upload"] + +log = ["tracing-subscriber"] + upload = ["ureq", "multipart", "rpassword", "configparser", "bytesize"] password-storage = ["upload", "keyring"] -log = ["tracing-subscriber"] + rustls = ["ureq/tls", "cargo-xwin/rustls-tls"] native-tls = ["ureq/native-tls", "native-tls-crate", "cargo-xwin/native-tls"] + # cross compile using zig or xwin cross-compile = ["zig", "xwin"] zig = ["cargo-zigbuild"] xwin = ["cargo-xwin"] + +# project scaffolding +scaffolding = ["dialoguer", "console", "minijinja"] + # Internal feature to speed up the tests significantly faster-tests = [] + # Deprecated features, keep it now for compatibility human-panic = [] diff --git a/src/lib.rs b/src/lib.rs index c54c50947..ba34d97da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,7 @@ pub use crate::metadata::{Metadata21, WheelMetadata}; pub use crate::module_writer::{ write_dist_info, ModuleWriter, PathWriter, SDistWriter, WheelWriter, }; +#[cfg(feature = "scaffolding")] pub use crate::new_project::{init_project, new_project, GenerateProjectOptions}; pub use crate::pyproject_toml::PyProjectToml; pub use crate::python_interpreter::PythonInterpreter; @@ -49,6 +50,7 @@ mod cross_compile; mod develop; mod metadata; mod module_writer; +#[cfg(feature = "scaffolding")] mod new_project; mod project_layout; pub mod pyproject_toml; diff --git a/src/main.rs b/src/main.rs index b059a255e..3f4b378a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,9 +8,11 @@ use anyhow::{bail, Context, Result}; use cargo_zigbuild::Zig; use clap::{CommandFactory, Parser, Subcommand}; use maturin::{ - develop, init_project, new_project, write_dist_info, BridgeModel, BuildOptions, CargoOptions, - GenerateProjectOptions, PathWriter, PlatformTag, PythonInterpreter, Target, + develop, write_dist_info, BridgeModel, BuildOptions, CargoOptions, PathWriter, PlatformTag, + PythonInterpreter, Target, }; +#[cfg(feature = "scaffolding")] +use maturin::{init_project, new_project, GenerateProjectOptions}; #[cfg(feature = "upload")] use maturin::{upload_ui, PublishOpt}; use std::env; @@ -114,6 +116,7 @@ enum Opt { out: Option, }, /// Create a new cargo project in an existing directory + #[cfg(feature = "scaffolding")] #[command(name = "init")] InitProject { /// Project path @@ -122,6 +125,7 @@ enum Opt { options: GenerateProjectOptions, }, /// Create a new cargo project + #[cfg(feature = "scaffolding")] #[command(name = "new")] NewProject { /// Project path @@ -393,7 +397,9 @@ fn run() -> Result<()> { .context("Failed to build source distribution, pyproject.toml not found")?; } Opt::Pep517(subcommand) => pep517(subcommand)?, + #[cfg(feature = "scaffolding")] Opt::InitProject { path, options } => init_project(path, options)?, + #[cfg(feature = "scaffolding")] Opt::NewProject { path, options } => new_project(path, options)?, #[cfg(feature = "upload")] Opt::Upload { publish, files } => {