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

Allow rye publish working outside of project #910

Merged
merged 3 commits into from
Mar 20, 2024
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
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)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write_credentials will be called in line 150, this call is not necessary.


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
"###);
}