Skip to content

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Jun 17, 2025

I was looking into uv tool not supporting version files, and noticed this implementation was confusing and skipped handling like a tracing log if --no-config excludes selection a file. I've refactored it in preparation for the next change.

@zanieb zanieb added the internal A refactor or improvement that is not user-facing label Jun 17, 2025
}
Ok(None)
fn find_global(options: &DiscoveryOptions<'_>) -> Option<PathBuf> {
let user_config_dir = user_uv_config_dir()?;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why this was passed in previously.

user_config_working_directory: impl AsRef<Path>,
options: &DiscoveryOptions<'_>,
) -> Result<Option<Self>, std::io::Error> {
if !options.no_config {
Copy link
Member Author

Choose a reason for hiding this comment

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

We'll respect the no_config logic above instead, which has a message for when it's applied.

@zanieb zanieb marked this pull request as ready for review June 17, 2025 16:57
// First, try to find a local version file.
let local = Self::find_nearest(&working_directory, options);
if local.is_none() {
// Log where we searched for the file, if not found
Copy link
Member Author

Choose a reason for hiding this comment

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

These messages are just indented, we don't want to show them when no_local is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by just indented?

Copy link
Member Author

Choose a reason for hiding this comment

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

The code is literally indented, there are no changes otherwise.

@zanieb
Copy link
Member Author

zanieb commented Jun 18, 2025

Example usage in the tool install change at #14112

let (python_request, explicit_python_request) = if let Some(request) = python.as_deref() {
(Some(PythonRequest::parse(request)), true)
} else {
// Discover a global Python version pin, if no request was made
(
PythonVersionFile::discover(
// TODO(zanieb): We don't use the directory, should we expose another interface?
// Should `no_local` be implied by `None` here?
&*CWD,
&VersionFileDiscoveryOptions::default()
// TODO(zanieb): Propagate `no_config` from the global options to here
.with_no_config(false)
.with_no_local(true),
)
.await?
.and_then(PythonVersionFile::into_version),
false,
)
};

@oconnor663 oconnor663 self-requested a review June 18, 2025 23:43
let user_config_dir = user_uv_config_dir()?;
Self::find_in_directory(&user_config_dir, options)
.into_iter()
.find(|path| path.is_file())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this last is_file check redundant with the same check done inside find_in_directory?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure seems like it, not sure why that was there — I'll remove it.

}
};

let version_file = if global {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the previous behavior was that a global pin would only be updated if --global is set, but with the changes in this PR, it gets updated by default if no local pin is found. Is that intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, good point. Confusingly, python_pin_global_use_local_if_available should provide test coverage for this and is passing?

Copy link
Member Author

@zanieb zanieb Jun 19, 2025

Choose a reason for hiding this comment

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

This is because we only read from this file. For construction of a new file, we use this

// TODO(zanieb): Allow updating the discovered version file with an `--update` flag.
let new = if global {
let Some(config_dir) = user_uv_config_dir() else {
return Err(anyhow::anyhow!("No user-level config directory found."));
};
fs_err::tokio::create_dir_all(&config_dir).await?;
PythonVersionFile::new(config_dir.join(PYTHON_VERSION_FILENAME))
.with_versions(vec![request])
} else {
PythonVersionFile::new(project_dir.join(PYTHON_VERSION_FILENAME))
.with_versions(vec![request])
};

Copy link
Member Author

@zanieb zanieb Jun 19, 2025

Choose a reason for hiding this comment

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

The previous code was just superfluous

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah never mind, I was misunderstanding the change to PythonVersionFile::discover. I thought the "fall back to global if nothing local is found" behavior was new, but it's not new.

@zanieb zanieb temporarily deployed to uv-test-registries June 19, 2025 16:47 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-publish June 19, 2025 16:47 — with GitHub Actions Inactive
@zanieb zanieb requested a review from oconnor663 June 20, 2025 15:36
@zanieb zanieb force-pushed the zb/ref-version-file branch from 262fd1a to b521759 Compare June 20, 2025 19:43
@zanieb zanieb temporarily deployed to uv-test-registries June 20, 2025 19:46 — with GitHub Actions Inactive
@zanieb zanieb merged commit 1dbe750 into main Jun 20, 2025
87 checks passed
@zanieb zanieb deleted the zb/ref-version-file branch June 20, 2025 20:31
zanieb added a commit that referenced this pull request Jun 21, 2025
I was looking into `uv tool` not supporting version files, and noticed
this implementation was confusing and skipped handling like a tracing
log if `--no-config` excludes selection a file. I've refactored it in
preparation for the next change.
zanieb added a commit that referenced this pull request Jun 26, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
zanieb added a commit that referenced this pull request Jul 2, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
jtfmumm pushed a commit that referenced this pull request Jul 8, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
charliermarsh pushed a commit that referenced this pull request Jul 11, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
charliermarsh pushed a commit that referenced this pull request Jul 11, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
zanieb added a commit that referenced this pull request Jul 14, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
zanieb added a commit that referenced this pull request Jul 16, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
zanieb added a commit that referenced this pull request Jul 17, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
zanieb added a commit that referenced this pull request Jul 17, 2025
While reviewing #14107, @oconnor663
pointed out a bug where we allow `uv python pin --rm` to delete the
global pin without the `--global` flag. I think that shouldn't be
allowed? I'm not 100% certain though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user-facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants