Missing added_in on new env vars (#16217)

## Summary

Adds the version for environment variables added in
https://github.com/astral-sh/uv/pull/16040 and
https://github.com/astral-sh/uv/pull/16125. as these were in-flight
before documentation versioning was added.

Adds ability to emit a compiler error when added in is missing for
improved reporting to the developer.

e.g. example for the ones fixed in this PR

```shell
error: missing #[attr_added_in("x.y.z")] on `UV_UPLOAD_HTTP_TIMEOUT`
       note: env vars for an upcoming release should be annotated with `#[attr_added_in("next release")]`
   --> crates\uv-static\src\env_vars.rs:593:15
    |
593 |     pub const UV_UPLOAD_HTTP_TIMEOUT: &'static str = "UV_UPLOAD_HTTP_TIMEOUT";
    |               ^^^^^^^^^^^^^^^^^^^^^^

error: missing #[attr_added_in("x.y.z")] on `UV_WORKING_DIRECTORY`
       note: env vars for an upcoming release should be annotated with `#[attr_added_in("next release")]`
    --> crates\uv-static\src\env_vars.rs:1087:15
     |
1087 |     pub const UV_WORKING_DIRECTORY: &'static str = "UV_WORKING_DIRECTORY";
     |               ^^^^^^^^^^^^^^^^^^^^
error: could not compile `uv-static` (lib) due to 2 previous errors
```
This commit is contained in:
samypr100 2025-10-10 09:55:09 -04:00 committed by GitHub
parent ea5a09215b
commit d5dd43aa18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 5 deletions

View file

@ -1,7 +1,8 @@
mod options_metadata;
use proc_macro::TokenStream;
use quote::quote;
use quote::{quote, quote_spanned};
use syn::spanned::Spanned;
use syn::{Attribute, DeriveInput, ImplItem, ItemImpl, LitStr, parse_macro_input};
#[proc_macro_derive(OptionsMetadata, attributes(option, doc, option_group))]
@ -109,14 +110,14 @@ pub fn attribute_env_vars_metadata(_attr: TokenStream, input: TokenStream) -> To
return None;
};
let name = lit.value();
Some((name, doc, added_in))
Some((name, doc, added_in, item.ident.span()))
}
ImplItem::Fn(item) if !is_hidden(&item.attrs) => {
// Extract the environment variable patterns.
if let Some(pattern) = get_env_var_pattern_from_attr(&item.attrs) {
let doc = get_doc_comment(&item.attrs);
let added_in = get_added_in(&item.attrs);
Some((pattern, doc, added_in))
Some((pattern, doc, added_in, item.sig.span()))
} else {
None // Skip if pattern extraction fails.
}
@ -125,8 +126,25 @@ pub fn attribute_env_vars_metadata(_attr: TokenStream, input: TokenStream) -> To
})
.collect();
// Look for missing attr_added_in and issue a compiler error if any are found.
let added_in_errors: Vec<_> = constants
.iter()
.filter_map(|(name, _, added_in, span)| {
added_in.is_none().then_some({
let msg = format!(
"missing #[attr_added_in(\"x.y.z\")] on `{name}`\nnote: env vars for an upcoming release should be annotated with `#[attr_added_in(\"next release\")]`"
);
quote_spanned! {*span => compile_error!(#msg); }
})
})
.collect();
if !added_in_errors.is_empty() {
return quote! { #ast #(#added_in_errors)* }.into();
}
let struct_name = &ast.self_ty;
let pairs = constants.iter().map(|(name, doc, added_in)| {
let pairs = constants.iter().map(|(name, doc, added_in, _span)| {
if let Some(added_in) = added_in {
quote! { (#name, #doc, Some(#added_in)) }
} else {

View file

@ -1,6 +1,5 @@
//! Environment variables used or supported by uv.
//! Used to generate `docs/reference/environment.md`.
//! NOTICE: Upcoming release functionality should be documented with `#[attr_added_in("0.9.1")]`.
use uv_macros::{attr_added_in, attr_env_var_pattern, attr_hidden, attribute_env_vars_metadata};
/// Declares all environment variable used throughout `uv` and its crates.
@ -591,6 +590,7 @@ impl EnvVars {
pub const NO_PROXY: &'static str = "NO_PROXY";
/// Timeout (in seconds) for only upload HTTP requests. (default: 900 s)
#[attr_added_in("0.9.1")]
pub const UV_UPLOAD_HTTP_TIMEOUT: &'static str = "UV_UPLOAD_HTTP_TIMEOUT";
/// Timeout (in seconds) for HTTP requests. (default: 30 s)
@ -1085,6 +1085,7 @@ impl EnvVars {
pub const UV_PROJECT: &'static str = "UV_PROJECT";
/// Equivalent to the `--directory` command-line argument.
#[attr_added_in("0.9.1")]
pub const UV_WORKING_DIRECTORY: &'static str = "UV_WORKING_DIRECTORY";
/// Disable GitHub-specific requests that allow uv to skip `git fetch` in some circumstances.

View file

@ -652,6 +652,7 @@ Used ephemeral environments like CI to install uv to a specific path while preve
the installer from modifying shell profiles or environment variables.
### `UV_UPLOAD_HTTP_TIMEOUT`
<small class="added-in">added in `0.9.1`</small>
Timeout (in seconds) for only upload HTTP requests. (default: 900 s)
@ -670,6 +671,7 @@ created by `uv venv`.
Note that `setuptools` and `wheel` are not included in Python 3.12+ environments.
### `UV_WORKING_DIRECTORY`
<small class="added-in">added in `0.9.1`</small>
Equivalent to the `--directory` command-line argument.