-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new install command * Snapshots * Fix tests
- Loading branch information
Showing
14 changed files
with
248 additions
and
80 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
crates/huak-cli/tests/snapshots/r#mod__tests__install_help.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: crates/huak-cli/tests/mod.rs | ||
info: | ||
program: huak | ||
args: | ||
- install | ||
- "--help" | ||
--- | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
Install a Python package (defaults to $HOME/.huak/bin) | ||
|
||
Usage: huak install [OPTIONS] <PACKAGE> | ||
|
||
Arguments: | ||
<PACKAGE> The Python package to install | ||
|
||
Options: | ||
--python-version <PYTHON_VERSION> | ||
The Python version to use. TODO(cnpryer): https://github.com/cnpryer/huak/issues/850 | ||
--package-index-url <PACKAGE_INDEX_URL> | ||
The package index to use. TODO(cnpryer): Deps (document this) [default: https://pypi.python.org/simple] | ||
-q, --quiet | ||
|
||
--no-color | ||
|
||
-h, --help | ||
Print help | ||
|
||
----- stderr ----- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,51 @@ | ||
use crate::HuakResult; | ||
use huak_python_manager::{RequestedVersion, Version}; | ||
use huak_toolchain::{Channel, LocalTool, LocalToolchain}; | ||
use pep508_rs::Requirement; | ||
|
||
use super::toolchain::{add_tool_to_toolchain, install_minimal_toolchain}; | ||
use crate::{Config, Error, HuakResult}; | ||
|
||
// TODO(cnpryer): https://github.com/cnpryer/huak/issues/850 | ||
pub fn _install() -> HuakResult<()> { | ||
todo!() | ||
pub fn install( | ||
package: &Requirement, | ||
python_version: Option<RequestedVersion>, | ||
_package_index_url: &str, | ||
config: &Config, | ||
) -> HuakResult<()> { | ||
// TODO(cnpryer): Since we're treating the bin dir as a toolchain that'd mean Huak home is | ||
// the root of that toolchain (given toolchain bins are standard at roots). | ||
let Some(home) = config.home.as_ref() else { | ||
return Err(Error::HuakHomeNotFound); | ||
}; | ||
|
||
// TODO(cnpryer): Smarter installs | ||
if home.join("bin").join(&package.name).exists() { | ||
return config | ||
.terminal() | ||
.print_warning(format!("'{}' is already installed", &package.name)); | ||
} | ||
|
||
if !home.join("bin").exists() { | ||
std::fs::create_dir_all(home)?; | ||
|
||
// TODO(cnpryer): https://github.com/cnpryer/huak/issues/871 | ||
let channel = python_version | ||
.map(|it| { | ||
Channel::Version(Version { | ||
major: it.major, | ||
minor: it.minor, | ||
patch: it.patch, | ||
}) | ||
}) | ||
.unwrap_or_default(); | ||
|
||
install_minimal_toolchain(home, channel, config)?; | ||
} | ||
|
||
// TODO(cnpryer): Toolchains have names. The bin directory is used as a toolchain | ||
// but there's no intention behind a toolchain named 'bin'. | ||
let bin = LocalToolchain::new(home); | ||
let package = LocalTool::from_spec(package.name.clone(), package.to_string()); | ||
|
||
add_tool_to_toolchain(&package, &bin, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.