Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit on stdout rather than stderr for most cases #342

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ that were not yet released.

_Unreleased_

- Rye now emits most messages, most of the time to stdout rather than stderr. #342

- `rye add` now accepts `--pin` to let one override the type of pin to use. #341

- Added `rye config` to read and manipulate the `config.toml` file. #339
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rye/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT"
[dependencies]
age = "0.9.1"
anyhow = { version = "1.0.70", features = ["backtrace"] }
clap = { version = "4.2.2", default-features = false, features = ["derive", "usage", "wrap_help", "std"] }
clap = { version = "4.3.5", default-features = false, features = ["derive", "usage", "wrap_help", "std"] }
clap_complete = "4.2.1"
console = "0.15.7"
curl = { version = "0.4.44", features = ["ssl", "static-curl", "static-ssl"] }
Expand Down
30 changes: 15 additions & 15 deletions rye/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn ensure_self_venv(output: CommandOutput) -> Result<PathBuf, Error> {
return Ok(venv_dir);
} else {
if output != CommandOutput::Quiet {
eprintln!("detected outdated rye internals. Refreshing");
echo!("detected outdated rye internals. Refreshing");
}
fs::remove_dir_all(&venv_dir).context("could not remove self-venv for update")?;
if pip_tools_dir.is_dir() {
Expand All @@ -87,7 +87,7 @@ pub fn ensure_self_venv(output: CommandOutput) -> Result<PathBuf, Error> {
}

if output != CommandOutput::Quiet {
eprintln!("Bootstrapping rye internals");
echo!("Bootstrapping rye internals");
}

let version = ensure_self_toolchain(output).with_context(|| {
Expand Down Expand Up @@ -136,7 +136,7 @@ pub fn ensure_self_venv(output: CommandOutput) -> Result<PathBuf, Error> {

fn do_update(output: CommandOutput, venv_dir: &Path, app_dir: &Path) -> Result<(), Error> {
if output != CommandOutput::Quiet {
eprintln!("Upgrading pip");
echo!("Upgrading pip");
}
let venv_bin = venv_dir.join(VENV_BIN);

Expand Down Expand Up @@ -164,7 +164,7 @@ fn do_update(output: CommandOutput, venv_dir: &Path, app_dir: &Path) -> Result<(
.arg("-r")
.arg(req_file.path());
if output != CommandOutput::Quiet {
eprintln!("Installing internal dependencies");
echo!("Installing internal dependencies");
}
if output == CommandOutput::Verbose {
pip_install_cmd.arg("--verbose");
Expand Down Expand Up @@ -288,7 +288,7 @@ fn ensure_self_toolchain(output: CommandOutput) -> Result<PythonVersion, Error>
.collect::<Vec<_>>();

if let Some(version) = possible_versions.into_iter().min() {
eprintln!(
echo!(
"Found a compatible python version: {}",
style(&version).cyan()
);
Expand All @@ -306,7 +306,7 @@ pub fn fetch(
let py_bin = get_toolchain_python_bin(&version)?;
if py_bin.is_file() {
if output == CommandOutput::Verbose {
eprintln!("Python version already downloaded. Skipping.");
echo!("Python version already downloaded. Skipping.");
}
return Ok(version);
}
Expand All @@ -320,11 +320,11 @@ pub fn fetch(
let target_dir = get_canonical_py_path(&version)?;
let target_py_bin = get_toolchain_python_bin(&version)?;
if output == CommandOutput::Verbose {
eprintln!("target dir: {}", target_dir.display());
echo!("target dir: {}", target_dir.display());
}
if target_dir.is_dir() && target_py_bin.is_file() {
if output == CommandOutput::Verbose {
eprintln!("Python version already downloaded. Skipping.");
echo!("Python version already downloaded. Skipping.");
}
return Ok(version);
}
Expand All @@ -333,28 +333,28 @@ pub fn fetch(
.with_context(|| format!("failed to create target folder {}", target_dir.display()))?;

if output == CommandOutput::Verbose {
eprintln!("download url: {}", url);
echo!("download url: {}", url);
}
if output != CommandOutput::Quiet {
eprintln!("{} {}", style("Downloading").cyan(), version);
echo!("{} {}", style("Downloading").cyan(), version);
}
let archive_buffer = download_url(url, output)?;

if let Some(sha256) = sha256 {
if output != CommandOutput::Quiet {
eprintln!("{}", style("Checking checksum").cyan());
echo!("{}", style("Checking checksum").cyan());
}
check_checksum(&archive_buffer, sha256)
.with_context(|| format!("hash check of {} failed", &url))?;
} else if output != CommandOutput::Quiet {
eprintln!("Checksum check skipped (no hash available)");
echo!("Checksum check skipped (no hash available)");
}

unpack_archive(&archive_buffer, &target_dir, 1)
.with_context(|| format!("unpacking of downloaded tarball {} failed", &url))?;

if output != CommandOutput::Quiet {
eprintln!("{} Downloaded {}", style("success:").green(), version);
echo!("{} Downloaded {}", style("success:").green(), version);
}

Ok(version)
Expand Down Expand Up @@ -452,13 +452,13 @@ fn validate_shared_libraries(py: &Path) -> Result<(), Error> {
}

missing.sort();
eprintln!(
echo!(
"{}: detected missing shared librar{} required by Python:",
style("error").red(),
if missing.len() == 1 { "y" } else { "ies" }
);
for lib in missing {
eprintln!(" - {}", style(lib).yellow());
echo!(" - {}", style(lib).yellow());
}
bail!(
"Python installation is unable to run on this machine due to missing libraries.\n\
Expand Down
14 changes: 6 additions & 8 deletions rye/src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::str::FromStr;

use anyhow::{anyhow, bail, Context, Error};
use clap::{Parser, ValueEnum};
use console::style;
use pep440_rs::{Operator, Version, VersionSpecifier, VersionSpecifiers};
use pep508_rs::{Requirement, VersionOrUrl};
use serde::Deserialize;
Expand Down Expand Up @@ -266,9 +265,8 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
)
.unwrap_or_default();
if let Some(pre) = all_pre_matches.into_iter().next() {
eprintln!(
"{}: {} ({}) was found considering pre-releases. Pass --pre to allow use.",
style("warning").red(),
warn!(
"{} ({}) was found considering pre-releases. Pass --pre to allow use.",
pre.name,
pre.version.unwrap_or_default()
);
Expand All @@ -285,9 +283,9 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
}
} else {
if output != CommandOutput::Quiet {
eprintln!("Available package versions:");
echo!("Available package versions:");
for pkg in all_matches {
eprintln!(
echo!(
" {} ({}) requires Python {}",
pkg.name,
pkg.version.unwrap_or_default(),
Expand All @@ -297,7 +295,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
.map_or("unknown", |x| x as &str)
);
}
eprintln!("A possible solution is to raise the version in `requires-python` in `pyproject.toml`.");
echo!("A possible solution is to raise the version in `requires-python` in `pyproject.toml`.");
}
bail!(
"did not find a version of package '{}' compatible with this version of Python.",
Expand Down Expand Up @@ -341,7 +339,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {

if output != CommandOutput::Quiet {
for ref requirement in added {
println!(
echo!(
"Added {} as {} dependency",
format_requirement(requirement),
&dep_kind
Expand Down
2 changes: 1 addition & 1 deletion rye/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {

for project in projects {
if output != CommandOutput::Quiet {
eprintln!("building {}", style(project.normalized_name()?).cyan());
echo!("building {}", style(project.normalized_name()?).cyan());
}

let mut build_cmd = Command::new(get_venv_python_bin(&venv));
Expand Down
6 changes: 3 additions & 3 deletions rye/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
let doc = Arc::make_mut(&mut config).doc_mut();

if cmd.show_path {
println!("{}", config.path().display());
echo!("{}", config.path().display());
return Ok(());
}

Expand Down Expand Up @@ -166,11 +166,11 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
match cmd.format {
None => {
for line in read_as_string {
println!("{}", line);
echo!("{}", line);
}
}
Some(Format::Json) => {
println!("{}", serde_json::to_string_pretty(&read_as_json)?);
echo!("{}", serde_json::to_string_pretty(&read_as_json)?);
}
}

Expand Down
9 changes: 3 additions & 6 deletions rye/src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
.map_err(|msg| anyhow!("invalid version specifier: {}", msg))?
.contains(&py.clone().into())
{
eprintln!(
"{} conflicted python version with project's requires-python, will auto fix it.",
style("warning:").red()
);
warn!("conflicted python version with project's requires-python, will auto fix it.");
requires_python = format!(">= {}.{}", py.major, py.minor.unwrap_or_default());
}

Expand Down Expand Up @@ -282,12 +279,12 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
}
}

eprintln!(
echo!(
"{} Initialized project in {}",
style("success:").green(),
dir.display()
);
eprintln!(" Run `rye sync` to get started");
echo!(" Run `rye sync` to get started");

Ok(())
}
2 changes: 1 addition & 1 deletion rye/src/cli/make_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
let mut requirement = Requirement::from_str(&requirement_str)
.with_context(|| format!("unable to parse requirement '{}'", requirement_str))?;
cmd.req_extras.apply_to_requirement(&mut requirement)?;
println!("{}", format_requirement(&requirement));
echo!("{}", format_requirement(&requirement));
}

Ok(())
Expand Down
12 changes: 6 additions & 6 deletions rye/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn execute() -> Result<(), Error> {
return Ok(());
}

let args = Args::parse();
let args = Args::try_parse()?;
let cmd = if args.version {
return print_version();
} else if let Some(cmd) = args.command {
Expand Down Expand Up @@ -117,14 +117,14 @@ pub fn execute() -> Result<(), Error> {
}

fn print_version() -> Result<(), Error> {
eprintln!("rye {}", env!("CARGO_PKG_VERSION"));
eprintln!("commit: {}", TESTAMENT.commit);
eprintln!(
echo!("rye {}", env!("CARGO_PKG_VERSION"));
echo!("commit: {}", TESTAMENT.commit);
echo!(
"platform: {} ({})",
std::env::consts::OS,
std::env::consts::ARCH
);
eprintln!("self-python: {}", SELF_PYTHON_TARGET_VERSION);
eprintln!("symlink support: {}", symlinks_supported());
echo!("self-python: {}", SELF_PYTHON_TARGET_VERSION);
echo!("symlink support: {}", symlinks_supported());
Ok(())
}
2 changes: 1 addition & 1 deletion rye/src/cli/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
}
}

eprintln!("pinned {} in {}", to_write, version_file.display());
echo!("pinned {} in {}", to_write, version_file.display());

Ok(())
}
2 changes: 1 addition & 1 deletion rye/src/cli/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {

maybe_decrypt(&secret, cmd.yes)?
} else {
eprintln!("No access token found, generate one at: https://pypi.org/manage/account/token/");
echo!("No access token found, generate one at: https://pypi.org/manage/account/token/");
let token = if !cmd.yes {
prompt_for_token()?
} else {
Expand Down
2 changes: 1 addition & 1 deletion rye/src/cli/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> {

if output != CommandOutput::Quiet {
for requirement in removed_packages {
println!("Removed {}", format_requirement(&requirement));
echo!("Removed {}", format_requirement(&requirement));
}
}

Expand Down
6 changes: 4 additions & 2 deletions rye/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use console::style;

use crate::pyproject::{PyProject, Script};
use crate::sync::{sync, SyncOptions};
use crate::tui::redirect_to_stderr;
use crate::utils::{exec_spawn, success_status};

/// Runs a command installed into this package.
Expand All @@ -33,6 +34,7 @@ enum Cmd {
}

pub fn execute(cmd: Args) -> Result<(), Error> {
let _guard = redirect_to_stderr(true);
let pyproject = PyProject::load_or_discover(cmd.pyproject.as_deref())?;

// make sure we have the minimal virtualenv.
Expand Down Expand Up @@ -143,9 +145,9 @@ fn list_scripts(pyproject: &PyProject) -> Result<(), Error> {
scripts.sort_by(|a, b| a.0.to_ascii_lowercase().cmp(&b.0.to_ascii_lowercase()));
for (name, script) in scripts {
if matches!(script, Script::External(_)) {
println!("{}", name);
echo!("{}", name);
} else {
println!("{} ({})", name, style(script).dim());
echo!("{} ({})", name, style(script).dim());
}
}
Ok(())
Expand Down