mirror of
				https://github.com/astral-sh/uv.git
				synced 2025-10-31 12:06:13 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									ea5a09215b
								
							
						
					
					
						commit
						d5dd43aa18
					
				
					 3 changed files with 26 additions and 5 deletions
				
			
		|  | @ -1,7 +1,8 @@ | ||||||
| mod options_metadata; | mod options_metadata; | ||||||
| 
 | 
 | ||||||
| use proc_macro::TokenStream; | 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}; | use syn::{Attribute, DeriveInput, ImplItem, ItemImpl, LitStr, parse_macro_input}; | ||||||
| 
 | 
 | ||||||
| #[proc_macro_derive(OptionsMetadata, attributes(option, doc, option_group))] | #[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; |                     return None; | ||||||
|                 }; |                 }; | ||||||
|                 let name = lit.value(); |                 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) => { |             ImplItem::Fn(item) if !is_hidden(&item.attrs) => { | ||||||
|                 // Extract the environment variable patterns.
 |                 // Extract the environment variable patterns.
 | ||||||
|                 if let Some(pattern) = get_env_var_pattern_from_attr(&item.attrs) { |                 if let Some(pattern) = get_env_var_pattern_from_attr(&item.attrs) { | ||||||
|                     let doc = get_doc_comment(&item.attrs); |                     let doc = get_doc_comment(&item.attrs); | ||||||
|                     let added_in = get_added_in(&item.attrs); |                     let added_in = get_added_in(&item.attrs); | ||||||
|                     Some((pattern, doc, added_in)) |                     Some((pattern, doc, added_in, item.sig.span())) | ||||||
|                 } else { |                 } else { | ||||||
|                     None // Skip if pattern extraction fails.
 |                     None // Skip if pattern extraction fails.
 | ||||||
|                 } |                 } | ||||||
|  | @ -125,8 +126,25 @@ pub fn attribute_env_vars_metadata(_attr: TokenStream, input: TokenStream) -> To | ||||||
|         }) |         }) | ||||||
|         .collect(); |         .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 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 { |         if let Some(added_in) = added_in { | ||||||
|             quote! { (#name, #doc, Some(#added_in)) } |             quote! { (#name, #doc, Some(#added_in)) } | ||||||
|         } else { |         } else { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,5 @@ | ||||||
| //! Environment variables used or supported by uv.
 | //! Environment variables used or supported by uv.
 | ||||||
| //! Used to generate `docs/reference/environment.md`.
 | //! 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}; | 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.
 | /// Declares all environment variable used throughout `uv` and its crates.
 | ||||||
|  | @ -591,6 +590,7 @@ impl EnvVars { | ||||||
|     pub const NO_PROXY: &'static str = "NO_PROXY"; |     pub const NO_PROXY: &'static str = "NO_PROXY"; | ||||||
| 
 | 
 | ||||||
|     /// Timeout (in seconds) for only upload HTTP requests. (default: 900 s)
 |     /// 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"; |     pub const UV_UPLOAD_HTTP_TIMEOUT: &'static str = "UV_UPLOAD_HTTP_TIMEOUT"; | ||||||
| 
 | 
 | ||||||
|     /// Timeout (in seconds) for HTTP requests. (default: 30 s)
 |     /// Timeout (in seconds) for HTTP requests. (default: 30 s)
 | ||||||
|  | @ -1085,6 +1085,7 @@ impl EnvVars { | ||||||
|     pub const UV_PROJECT: &'static str = "UV_PROJECT"; |     pub const UV_PROJECT: &'static str = "UV_PROJECT"; | ||||||
| 
 | 
 | ||||||
|     /// Equivalent to the `--directory` command-line argument.
 |     /// Equivalent to the `--directory` command-line argument.
 | ||||||
|  |     #[attr_added_in("0.9.1")] | ||||||
|     pub const UV_WORKING_DIRECTORY: &'static str = "UV_WORKING_DIRECTORY"; |     pub const UV_WORKING_DIRECTORY: &'static str = "UV_WORKING_DIRECTORY"; | ||||||
| 
 | 
 | ||||||
|     /// Disable GitHub-specific requests that allow uv to skip `git fetch` in some circumstances.
 |     /// Disable GitHub-specific requests that allow uv to skip `git fetch` in some circumstances.
 | ||||||
|  |  | ||||||
|  | @ -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. | the installer from modifying shell profiles or environment variables. | ||||||
| 
 | 
 | ||||||
| ### `UV_UPLOAD_HTTP_TIMEOUT` | ### `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) | 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. | Note that `setuptools` and `wheel` are not included in Python 3.12+ environments. | ||||||
| 
 | 
 | ||||||
| ### `UV_WORKING_DIRECTORY` | ### `UV_WORKING_DIRECTORY` | ||||||
|  | <small class="added-in">added in `0.9.1`</small> | ||||||
| 
 | 
 | ||||||
| Equivalent to the `--directory` command-line argument. | Equivalent to the `--directory` command-line argument. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 samypr100
						samypr100