Skip to content

Commit

Permalink
Change to project-only
Browse files Browse the repository at this point in the history
  • Loading branch information
ischaojie committed Jun 14, 2023
1 parent fe8ca16 commit e9c5722
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 70 deletions.
18 changes: 7 additions & 11 deletions rye/src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,14 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
Some(ver) => ver.format_simple(),
None => "".to_string(),
};
let dep_kind = if !pyproject_toml.workspace_only() {
if cmd.dev {
DependencyKind::Dev
} else if cmd.excluded {
DependencyKind::Excluded
} else if let Some(ref section) = cmd.optional {
DependencyKind::Optional(section.into())
} else {
DependencyKind::Normal
}
} else {
let dep_kind = if cmd.dev {
DependencyKind::Dev
} else if cmd.excluded {
DependencyKind::Excluded
} else if let Some(ref section) = cmd.optional {
DependencyKind::Optional(section.into())
} else {
DependencyKind::Normal
};

for str_requirement in cmd.requirements {
Expand Down
7 changes: 3 additions & 4 deletions rye/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
let venv = ensure_self_venv(output)?;
let project = PyProject::load_or_discover(cmd.pyproject.as_deref())?;

if project.workspace_only() {
bail!("building is not supported for workspace-only projects");
}

let out = match cmd.out {
Some(path) => path,
None => project.workspace_path().join("dist"),
Expand Down Expand Up @@ -100,6 +96,9 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
}

for project in projects {
if project.project_only() {
continue;
}
if output != CommandOutput::Quiet {
eprintln!("building {}", style(project.normalized_name()?).cyan());
}
Expand Down
45 changes: 20 additions & 25 deletions rye/src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ pub struct Args {
/// Set "Private :: Do Not Upload" classifier, used for private projects
#[arg(long)]
private: bool,
/// Only workspace, not a package.
/// Only a project, not a package.
#[arg(long)]
workspace_only: bool,
project_only: bool,
}

/// The pyproject.toml template
Expand Down Expand Up @@ -94,6 +94,9 @@ build-backend = "pdm.backend"
[tool.rye]
managed = true
{%- if project_only %}
project-only = true
{%- endif %}
{%- if build_system == "hatchling" %}
Expand All @@ -103,11 +106,6 @@ allow-direct-references = true
"#;

const WORKSPACE_ONLY_TOML_TEMPLATE: &str = r#"[tool.rye]
managed = true
workspace-only = true
"#;

/// The template for the readme file.
const README_TEMPLATE: &str = r#"# {{ name }}
Expand Down Expand Up @@ -245,24 +243,21 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
};

let private = cmd.private;
let rv = if cmd.workspace_only {
env.render_named_str("pyproject.json", WORKSPACE_ONLY_TOML_TEMPLATE, context!())
} else {
env.render_named_str(
"pyproject.json",
TOML_TEMPLATE,
context! {
name,
version,
author,
requires_python,
license,
with_readme,
build_system,
private,
},
)
}?;
let rv = env.render_named_str(
"pyproject.json",
TOML_TEMPLATE,
context! {
name,
version,
author,
requires_python,
license,
with_readme,
build_system,
private,
project_only => cmd.project_only,
},
)?;
fs::write(&toml, rv).context("failed to write pyproject.toml")?;

let src_dir = dir.join("src");
Expand Down
4 changes: 0 additions & 4 deletions rye/src/cli/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
let venv = ensure_self_venv(output)?;
let project = PyProject::discover()?;

if project.workspace_only() {
bail!("publishing is not supported for workspace-only projects");
}

// Get the files to publish.
let files = match cmd.dist {
Some(paths) => paths,
Expand Down
14 changes: 5 additions & 9 deletions rye/src/cli/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
let requirement = Requirement::from_str(&str_requirement)?;
if let Some(removed) = pyproject_toml.remove_dependency(
&requirement,
if !pyproject_toml.workspace_only() {
if cmd.dev {
DependencyKind::Dev
} else if let Some(ref section) = cmd.optional {
DependencyKind::Optional(section.into())
} else {
DependencyKind::Normal
}
} else {
if cmd.dev {
DependencyKind::Dev
} else if let Some(ref section) = cmd.optional {
DependencyKind::Optional(section.into())
} else {
DependencyKind::Normal
},
)? {
removed_packages.push(removed);
Expand Down
5 changes: 1 addition & 4 deletions rye/src/cli/version.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use crate::pyproject::PyProject;
use anyhow::{anyhow, bail, Error};
use anyhow::{anyhow, Error};
use clap::{Parser, ValueEnum};
use console::style;
use pep440_rs::Version;
Expand All @@ -25,9 +25,6 @@ pub enum Bump {

pub fn execute(cmd: Args) -> Result<(), Error> {
let mut pyproject_toml = PyProject::discover()?;
if pyproject_toml.workspace_only() {
bail!("get or set version is not supported for workspace-only projects");
}
match cmd.version {
Some(version) => {
let version =
Expand Down
4 changes: 2 additions & 2 deletions rye/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn update_workspace_lockfile(
for pyproject_result in workspace.iter_projects() {
let pyproject = pyproject_result?;
let rel_url = make_relative_url(&pyproject.root_path(), &workspace.path())?;
if !workspace.workspace_only() {
if !pyproject.project_only() {
let applicable_extras =
format_project_extras(features_by_project.as_ref(), &pyproject)?;
writeln!(local_req_file, "-e {}{}", rel_url, applicable_extras)?;
Expand Down Expand Up @@ -263,7 +263,7 @@ pub fn update_single_project_lockfile(
eprintln!("Generating {} lockfile: {}", lock_mode, lockfile.display());
}
let mut req_file = NamedTempFile::new()?;
if !pyproject.workspace_only() {
if !pyproject.project_only() {
let features_by_project = collect_workspace_features(lock_options);
let applicable_extras = format_project_extras(features_by_project.as_ref(), pyproject)?;
writeln!(
Expand Down
15 changes: 4 additions & 11 deletions rye/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,6 @@ impl Workspace {
pub fn rye_managed(&self) -> bool {
is_rye_managed(&self.doc)
}

pub fn workspace_only(&self) -> bool {
is_workspace_only(&self.doc)
}
}

/// Check if recurse should be skipped into directory with this name
Expand Down Expand Up @@ -876,11 +872,8 @@ impl PyProject {
}

/// Is this only a workspace, not a package?
pub fn workspace_only(&self) -> bool {
match self.workspace {
Some(ref workspace) => workspace.workspace_only(),
None => is_workspace_only(&self.doc),
}
pub fn project_only(&self) -> bool {
is_project_only(&self.doc)
}
}

Expand Down Expand Up @@ -1119,10 +1112,10 @@ fn is_rye_managed(doc: &Document) -> bool {
.unwrap_or(false)
}

fn is_workspace_only(doc: &Document) -> bool {
fn is_project_only(doc: &Document) -> bool {
doc.get("tool")
.and_then(|x| x.get("rye"))
.and_then(|x| x.get("workspace-only"))
.and_then(|x| x.get("project-only"))
.and_then(|x| x.as_bool())
.unwrap_or(false)
}
Expand Down

0 comments on commit e9c5722

Please sign in to comment.