-
Notifications
You must be signed in to change notification settings - Fork 34
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
WIP: Implement basic add command #177
Conversation
Thanks! I should have more time later today to check this out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments related to how were implementing this and potentially some final steps. Besides what would be the remaining cleanup, this looks like a good first pass!
Thanks for helping out!
Cargo.toml
Outdated
|
||
serde_json = "1.0" | ||
reqwest = { version = "0.11", features = ["blocking", "json"] } | ||
typer = "0.1.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not using typer. but we are using serde_json and reqwests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay cool. Then we can remove this.
src/bin/huak/commands/add.rs
Outdated
let path = format!("https://pypi.org/pypi/{}/json", dependency.unwrap()); | ||
|
||
//info!("Requesting data from {}", path); | ||
let resp: reqwest::blocking::Response = reqwest::blocking::get(path)?; | ||
|
||
let json: PyPi = resp.json()?; | ||
println!("{:#?}", json); | ||
|
||
// Get the version | ||
|
||
let version = json.info.version; | ||
let name = json.info.name; | ||
let dep = PythonPackage{ | ||
name, | ||
version, | ||
}; | ||
|
||
//let cwd = cwd_buff.as_path(); | ||
let venv = Venv::default(); | ||
venv.install_package(&dep)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments on this part.
- Can we move this to
huak::ops::add
? In bin/huak/commands/ we're only adding a thin CLI layer and implementing all the operation logic as part of the lib. So you'd want to
let path = format!("https://pypi.org/pypi/{}/json", dependency.unwrap()); | |
//info!("Requesting data from {}", path); | |
let resp: reqwest::blocking::Response = reqwest::blocking::get(path)?; | |
let json: PyPi = resp.json()?; | |
println!("{:#?}", json); | |
// Get the version | |
let version = json.info.version; | |
let name = json.info.name; | |
let dep = PythonPackage{ | |
name, | |
version, | |
}; | |
//let cwd = cwd_buff.as_path(); | |
let venv = Venv::default(); | |
venv.install_package(&dep)?; | |
let project = Project::from(&cwd); | |
ops::add::add_dependency_to_project(&project)?; |
- If we don't need certain annotations because the compiler will imply them, then maybe we remove those too. I'm not sure if
PyPI
can be implied but I wonder if the Response can. - From the ops space, we want to standardize operations to execute on Projects vs Venvs. So you should be able to do the same thing here.
- Last thing would be adding to the Toml.
Also let's make sure to remove and prints/debug code before a merge.
Looks like we also need to make sure this passes the ci-rust action. |
I will update my branch from remote so that the repo is in sync with mainstream. Will look at the ci-rust actions too |
Hi @cnpryer after making the changes, i ran cargo run add typer, and it shows what it is in the screenshot, however I cannot see any file tracking installed dependency Any hint will be appreciated |
Hmm I'm not sure what you mean. Can you give me something to reproduce this with? |
Hi! I'm hoping to get to PyPI this week or next weekend the latest. How are you doing here? I see that you're on your master, so unfortunately I don't think I can help out unless I PR your master. Correct me if I'm wrong. It looks like you need a rebase. I would rebase when you can. I want to update pub struct PythonPackage {
string: String, // TODO: More like a view maybe.
pub name: String,
pub op: Option<String>,
pub version: Option<String>,
}
impl PythonPackage {
pub fn new(name: String, op: Option<String>, version: Option<String>) -> PythonPackage {
let string = py_package_string_from_parts(&name, &op, &version);
PythonPackage { string, name, op, version }
}
pub fn from(string: String) -> PythonPackage {
let (name, op, version) = py_package_from_string(string);
PythonPackage { string, name, op, version }
}
pub fn string(&self) -> &String {
&self.string
}
pub fn set_string(&mut self, name: &str, op: &str, version: &str) {
self.string = format!("{name}{op}{version}");
}
}
fn py_package_from_string(string: String) -> (String, Option<String>, Option<String>) {
("".to_string(), None, None)
}
fn py_package_string_from_parts(name: &str, op: &Option<String>, version: &Option<String>) -> String {
"".to_string()
} If we move to that I think it'd be straightfoward to wrap up your PR, unless I'm missing something. The
let dependency = match args.get_one::<String>("dependency") {
Some(d) => d,
None => {
return Err(CliError::new(
anyhow::format_err!("no dependency was provided"),
2,
))
}
};
I'll update this comment throughout the day if something changes. |
I have made an initial push of the changes made, though test implementation is still outstanding |
src/bin/huak/commands/add.rs
Outdated
@@ -1,6 +1,7 @@ | |||
use super::utils::subcommand; | |||
use clap::{value_parser, Arg, ArgMatches, Command}; | |||
use huak::errors::CliResult; | |||
use huak::ops::add::add_project_dependency; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use huak::ops::add::add_project_dependency; | |
use huak::ops; |
src/huak/ops/add.rs
Outdated
|
||
pub fn add_project_dependency( | ||
package: String, | ||
_dependency_is_dev: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_dependency_is_dev: bool, | |
_is_dev: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I added the new error pattern here. It's probably not correct yet, but at least gives you an idea how we can handle errors in the bin space as well (post rebase).
Let me know if you need any help. Maybe I'll have the PythonPackage
changes done for your test.
src/huak/ops/add.rs
Outdated
// Get the version | ||
let version = json.info.version; | ||
let name = json.info.name; | ||
let mut dep = PythonPackage::new(name.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be able to do
let dep = PythonPackage::new(name, None, version);
after the PythonPackage
rewrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good to go. It'll default the string to "name==version".
src/bin/huak/commands/add.rs
Outdated
let dependency = args.get_one::<String>("dependency"); | ||
add_project_dependency(dependency.unwrap().to_string(), false)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let dependency = args.get_one::<String>("dependency"); | |
add_project_dependency(dependency.unwrap().to_string(), false)?; | |
let dependency = match args.get_one::<String>("dependency") { | |
Some(d) => d, | |
None => { | |
return Err(CliError::new(HuakError::MissingArguments)) | |
} | |
}; | |
ops::add::add_project_dependency(dependency, false)?; |
I'm like 60% sure i got this right. I'll come back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only change I think is adding , 1)
to just return a basic exit code. A rebase will add status codes to CliError.
Btw if you need more interactive communication I set up a discord https://discord.gg/St3menxFZT |
This is draft PR for Issue #9