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

[pull] main from mitsuhiko:main #31

Merged
merged 7 commits into from
Feb 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
This file contains tracks the changes landing in Rye. It includes changes
that were not yet released.

## 0.26.0
## 0.27.0

_Unreleased_

<!-- released start -->

## 0.26.0

Released on 2024-02-23

- `init` now supports `--script` and `--lib` to generate a script or library project. #738

- Fixed `rye config --show-path` abort with an error. #706

- Bumped `uv` to 0.1.7. #719, #740
- Bumped `uv` to 0.1.9. #719, #740, #746

- Bumped `ruff` to 0.2.2. #700

Expand All @@ -23,8 +31,6 @@ _Unreleased_

- Rename `rye tools list` flags: `-i, --include-scripts` to `-s, --include-scripts` and `-v, --version-show` to `-v, --include-version`. #722

<!-- released start -->

## 0.25.0

Released on 2024-02-19
Expand Down
53 changes: 1 addition & 52 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions artwork/badge.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"message": "Rye",
"logoSvg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><svg id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 250 250\"><defs><style>.cls-1{fill:#231f20;}</style></defs><path class=\"cls-1\" d=\"m125,0C55.96,0,0,55.96,0,125c0,56.49,37.47,104.21,88.91,119.7.12-1.93.29-4.22.51-6.96.27-3.29-1.48-8.17-3.98-10.04-27.8-20.8-36.81-42.97-30.26-77.03.31-1.63,2.33-2.24,3.48-1.05,7.51,7.78,12.86,12.69,20.71,21.82,11.68,13.59,16.22,29.57,14.8,47.82,1.27-5.54,3.11-11.02,3.72-16.63,2.52-23.15,8.07-45.07,25.27-62.07,4.43-4.38,9.78-8.58,15.5-10.76,15.08-5.75,30.76-10.06,40.95-24.37.83.51-4.7,19.47-5.64,23.58-6.72,22.84-4.37,23.96-12.35,46.35-5.27,14.77-16.63,25.05-32.55,29.15-15.67,4.03-24.47,14.58-26.66,30.2-.81,5.81-1.29,9.86-1.56,12.98,7.81,1.53,15.88,2.34,24.14,2.34,69.04,0,125-55.96,125-125S194.04,0,125,0Zm-12.07,140.26c-.25,2.16-1.5,5.25-3.18,7.17-6.02,6.86-11.51,19.21-14.77,35.69-5.91-18.24-26.63-34.42-34.1-47.99-2.57-4.67-.53-20.45,2.93-33.58,6.32-18.56,6.63-21.83,10.22-37.44,17.59,14.22,21.26,23.62,30.77,40.41,4.75,8.38,9.97,19.84,8.14,35.73Zm44.03-23.67c-16.52,6.74-26.72,10.6-37.25,18.95,2.63-14.1-6.27-30.66-11.84-43.19-.82-1.84,9.88-19.35,11.78-22.28,12.54-15.62,12.17-18.42,29.47-24.81,14.1-5.21,28.32-10.1,42.34-15.09-2.49,34.29-8.38,75.77-34.5,86.42Z\"/></svg>",
"logoWidth": 12,
"labelColor": "grey",
"color": "#261230"
"labelColor": "white",
"color": "#ADC541"
}
35 changes: 35 additions & 0 deletions docs/guide/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,38 @@ virtualenv is located and more.
```
rye show
```

## Executable projects

To generate a project that is aimed to provide an executable
script, use `rye init --script`:

```shell
rye init --script my-project
cd my-project
```

The following structure will be created:

```
.
├── .git
├── .gitignore
├── .python-version
├── README.md
├── pyproject.toml
└── src
└── my_project
└── __init__.py
└── __main__.py
```

The [`pyproject.toml`](pyproject.md) will be generated with a
[`[project.scripts]`](pyproject.md#projectscripts) section named `hello`
that points to the `main()` function of `__init__.py`. After you
synchronized your changes, you can run the script with `rye run my-project`.

```shell
rye sync
rye run hello
```
3 changes: 1 addition & 2 deletions rye/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rye"
version = "0.26.0"
version = "0.27.0"
edition = "2021"
license = "MIT"

Expand Down Expand Up @@ -62,7 +62,6 @@ home = "0.5.9"
ctrlc = "3.4.2"

[target."cfg(unix)".dependencies]
whattheshell = "1.0.1"
xattr = "1.3.1"

[target."cfg(windows)".dependencies]
Expand Down
78 changes: 46 additions & 32 deletions rye/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::pyproject::{latest_available_python_version, write_venv_marker};
use crate::sources::{get_download_url, PythonVersion, PythonVersionRequest};
use crate::utils::{
check_checksum, get_venv_python_bin, set_proxy_variables, symlink_file, unpack_archive,
CommandOutput,
CommandOutput, IoPathContext,
};

/// this is the target version that we want to fetch
Expand Down Expand Up @@ -57,7 +57,7 @@ unearth==0.14.0
urllib3==2.0.7
virtualenv==20.25.0
ruff==0.2.2
uv==0.1.7
uv==0.1.9
"#;

static FORCED_TO_UPDATE: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -92,10 +92,11 @@ pub fn ensure_self_venv_with_toolchain(
if output != CommandOutput::Quiet {
echo!("Detected outdated rye internals. Refreshing");
}
fs::remove_dir_all(&venv_dir).context("could not remove self-venv for update")?;
fs::remove_dir_all(&venv_dir)
.path_context(&venv_dir, "could not remove self-venv for update")?;
if pip_tools_dir.is_dir() {
fs::remove_dir_all(&pip_tools_dir)
.context("could not remove pip-tools for update")?;
.path_context(&pip_tools_dir, "could not remove pip-tools for update")?;
}
}
}
Expand Down Expand Up @@ -159,7 +160,9 @@ pub fn ensure_self_venv_with_toolchain(

do_update(output, &venv_dir, app_dir)?;

fs::write(venv_dir.join("tool-version.txt"), SELF_VERSION.to_string())?;
let tool_version_path = venv_dir.join("tool-version.txt");
fs::write(&tool_version_path, SELF_VERSION.to_string())
.path_context(tool_version_path, "could not write tool version")?;
FORCED_TO_UPDATE.store(true, atomic::Ordering::Relaxed);

Ok(venv_dir)
Expand Down Expand Up @@ -219,7 +222,7 @@ fn do_update(output: CommandOutput, venv_dir: &Path, app_dir: &Path) -> Result<(
}
let shims = app_dir.join("shims");
if !shims.is_dir() {
fs::create_dir_all(&shims).context("tried to create shim folder")?;
fs::create_dir_all(&shims).path_context(&shims, "tried to create shim folder")?;
}

// if rye is itself installed into the shims folder, we want to
Expand All @@ -237,47 +240,54 @@ fn do_update(output: CommandOutput, venv_dir: &Path, app_dir: &Path) -> Result<(
pub fn update_core_shims(shims: &Path, this: &Path) -> Result<(), Error> {
#[cfg(unix)]
{
let py_shim = shims.join("python");
let py3_shim = shims.join("python3");

// on linux we cannot symlink at all, as this will misreport. We will try to do
// hardlinks and if that fails, we fall back to copying the entire file over. This
// for instance is needed when the rye executable is placed on a different volume
// than ~/.rye/shims
if cfg!(target_os = "linux") {
fs::remove_file(shims.join("python")).ok();
if fs::hard_link(this, shims.join("python")).is_err() {
fs::copy(this, shims.join("python")).context("tried to copy python shim")?;
fs::remove_file(&py_shim).ok();
if fs::hard_link(this, &py_shim).is_err() {
fs::copy(this, &py_shim).path_context(&py_shim, "tried to copy python shim")?;
}
fs::remove_file(shims.join("python3")).ok();
if fs::hard_link(this, shims.join("python3")).is_err() {
fs::copy(this, shims.join("python2")).context("tried to copy python3 shim")?;
fs::remove_file(&py3_shim).ok();
if fs::hard_link(this, &py3_shim).is_err() {
fs::copy(this, &py3_shim).path_context(&py_shim, "tried to copy python3 shim")?;
}

// on other unices we always use symlinks
} else {
fs::remove_file(shims.join("python")).ok();
symlink_file(this, shims.join("python")).context("tried to symlink python shim")?;
fs::remove_file(shims.join("python3")).ok();
symlink_file(this, shims.join("python3")).context("tried to symlink python3 shim")?;
fs::remove_file(&py_shim).ok();
symlink_file(this, &py_shim).path_context(&py_shim, "tried to symlink python shim")?;
fs::remove_file(&py3_shim).ok();
symlink_file(this, &py3_shim)
.path_context(&py3_shim, "tried to symlink python3 shim")?;
}
}

#[cfg(windows)]
{
let py_shim = shims.join("python.exe");
let pyw_shim = shims.join("pythonw.exe");
let py3_shim = shims.join("python3.exe");

// on windows we need privileges to symlink. Not everyone might have that, so we
// fall back to hardlinks.
fs::remove_file(shims.join("python.exe")).ok();
if symlink_file(this, shims.join("python.exe")).is_err() {
fs::hard_link(this, shims.join("python.exe"))
.context("tried to symlink python shim")?;
fs::remove_file(&py_shim).ok();
if symlink_file(this, &py_shim).is_err() {
fs::hard_link(this, &py_shim).path_context(&py_shim, "tried to symlink python shim")?;
}
fs::remove_file(shims.join("python3.exe")).ok();
if symlink_file(this, shims.join("python3.exe")).is_err() {
fs::hard_link(this, shims.join("python3.exe"))
.context("tried to symlink python shim")?;
fs::remove_file(&py3_shim).ok();
if symlink_file(this, &py3_shim).is_err() {
fs::hard_link(this, &py3_shim)
.path_context(&py3_shim, "tried to symlink python3 shim")?;
}
fs::remove_file(shims.join("pythonw.exe")).ok();
if symlink_file(this, shims.join("pythonw.exe")).is_err() {
fs::hard_link(this, shims.join("pythonw.exe"))
.context("tried to symlink pythonw shim")?;
fs::remove_file(&pyw_shim).ok();
if symlink_file(this, &pyw_shim).is_err() {
fs::hard_link(this, &pyw_shim)
.path_context(&pyw_shim, "tried to symlink pythonw shim")?;
}
}

Expand Down Expand Up @@ -421,8 +431,7 @@ pub fn fetch(
return Ok(version);
}

fs::create_dir_all(&target_dir)
.with_context(|| format!("failed to create target folder {}", target_dir.display()))?;
fs::create_dir_all(&target_dir).path_context(&target_dir, "failed to create target folder")?;

if output == CommandOutput::Verbose {
echo!("download url: {}", url);
Expand All @@ -445,8 +454,13 @@ pub fn fetch(
if output != CommandOutput::Quiet {
echo!("{}", style("Unpacking").cyan());
}
unpack_archive(&archive_buffer, &target_dir, 1)
.with_context(|| format!("unpacking of downloaded tarball {} failed", &url))?;
unpack_archive(&archive_buffer, &target_dir, 1).with_context(|| {
format!(
"unpacking of downloaded tarball {} to '{}' failed",
&url,
target_dir.display()
)
})?;

if output != CommandOutput::Quiet {
echo!("{} {}", style("Downloaded").green(), version);
Expand Down
6 changes: 3 additions & 3 deletions rye/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use console::style;

use crate::bootstrap::ensure_self_venv;
use crate::pyproject::{locate_projects, PyProject};
use crate::utils::{get_venv_python_bin, CommandOutput};
use crate::utils::{get_venv_python_bin, CommandOutput, IoPathContext};

/// Builds a package for distribution.
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -53,10 +53,10 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
};

if out.exists() && cmd.clean {
for entry in fs::read_dir(&out)? {
for entry in fs::read_dir(&out).path_context(&out, "enumerate build output")? {
let path = entry?.path();
if path.is_file() {
fs::remove_file(path)?;
fs::remove_file(&path).path_context(&path, "clean build artifact")?;
}
}
}
Expand Down
Loading
Loading