Skip to content

Commit

Permalink
Allow rye publish working outside of project (#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 authored Mar 20, 2024
1 parent 1d6476f commit 41131a7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ site
__pycache__
.idea
token.txt
dist
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ _Unreleased_

<!-- released start -->

- Allow `rye publish` working outside of project. #910

## 0.30.0

Released on 2024-03-19
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 @@ -13,7 +13,7 @@ use crate::utils::{get_venv_python_bin, CommandOutput, IoPathContext};
/// Builds a package for distribution.
#[derive(Parser, Debug)]
pub struct Args {
/// Build an sdist
/// Build a sdist
#[arg(long)]
sdist: bool,
/// Build a wheel
Expand Down
14 changes: 7 additions & 7 deletions rye/src/cli/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ pub struct Args {
pub fn execute(cmd: Args) -> Result<(), Error> {
let output = CommandOutput::from_quiet_and_verbose(cmd.quiet, cmd.verbose);
let venv = ensure_self_venv(output)?;
let project = PyProject::discover()?;

if project.is_virtual() {
bail!("virtual packages cannot be published");
}

// Get the files to publish.
let files = match cmd.dist {
Some(paths) => paths,
None => vec![project.workspace_path().join("dist").join("*")],
None => {
let project = PyProject::discover()?;
if project.is_virtual() {
bail!("virtual packages cannot be published");
}
vec![project.workspace_path().join("dist").join("*")]
}
};

// a. Get token from arguments and offer encryption, then store in credentials file.
Expand Down Expand Up @@ -115,7 +116,6 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
let maybe_encrypted = maybe_encrypt(&secret, cmd.yes)?;
let maybe_encoded = maybe_encode(&secret, &maybe_encrypted);
credentials[repository]["token"] = Item::Value(maybe_encoded.expose_secret().into());
write_credentials(&credentials)?;

secret
} else if let Some(token) = credentials
Expand Down
31 changes: 31 additions & 0 deletions rye/tests/test_publish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::common::{rye_cmd_snapshot, Space};

mod common;

#[test]
fn test_publish_outside_project() {
let space = Space::new();
space.init("my-project");

let status = space.rye_cmd().arg("build").status().unwrap();
assert!(status.success());

// Publish outside the project.
// Since we provide a fake token, the failure is expected.
rye_cmd_snapshot!(space
.rye_cmd()
.arg("publish")
.arg("--yes")
.arg("--token")
.arg("fake-token")
.arg("--quiet")
.current_dir(space.project_path().parent().unwrap())
.arg(space.project_path().join("dist").join("*")), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
error: failed to publish files
"###);
}

0 comments on commit 41131a7

Please sign in to comment.