From 9f3000520980a2ff2faea57c289b434dc761c696 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Wed, 1 Oct 2025 13:22:43 -0700 Subject: [PATCH] chore: pgt_flags -> pgt_env, central website url, unify version --- Cargo.lock | 10 ++++++--- Cargo.toml | 2 +- crates/pgt_cli/Cargo.toml | 2 +- crates/pgt_cli/src/commands/clean.rs | 2 +- crates/pgt_cli/src/lib.rs | 6 +----- crates/pgt_configuration/Cargo.toml | 1 + crates/pgt_configuration/src/lib.rs | 11 ++++------ crates/pgt_diagnostics_categories/Cargo.toml | 1 + crates/{pgt_flags => pgt_env}/Cargo.toml | 4 ++-- crates/{pgt_flags => pgt_env}/src/lib.rs | 21 ++++++++++++++++--- crates/pgt_workspace/Cargo.toml | 1 + crates/pgt_workspace/src/configuration.rs | 5 +++-- docs/codegen/Cargo.toml | 2 +- docs/codegen/src/env_variables.rs | 2 +- xtask/codegen/Cargo.toml | 1 + .../codegen/src/generate_new_analyser_rule.rs | 4 +++- 16 files changed, 47 insertions(+), 28 deletions(-) rename crates/{pgt_flags => pgt_env}/Cargo.toml (72%) rename crates/{pgt_flags => pgt_env}/src/lib.rs (83%) diff --git a/Cargo.lock b/Cargo.lock index 48efd88ff..a754f873d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1298,7 +1298,7 @@ dependencies = [ "pgt_configuration", "pgt_console", "pgt_diagnostics", - "pgt_flags", + "pgt_env", "pgt_query", "pgt_query_ext", "pgt_statement_splitter", @@ -2786,7 +2786,7 @@ dependencies = [ "pgt_configuration", "pgt_console", "pgt_diagnostics", - "pgt_flags", + "pgt_env", "pgt_fs", "pgt_lsp", "pgt_text_edit", @@ -2840,6 +2840,7 @@ dependencies = [ "pgt_analyser", "pgt_console", "pgt_diagnostics", + "pgt_env", "pgt_text_size", "rustc-hash 2.1.0", "schemars", @@ -2885,6 +2886,7 @@ dependencies = [ name = "pgt_diagnostics_categories" version = "0.0.0" dependencies = [ + "pgt_env", "quote", "schemars", "serde", @@ -2901,7 +2903,7 @@ dependencies = [ ] [[package]] -name = "pgt_flags" +name = "pgt_env" version = "0.0.0" dependencies = [ "pgt_console", @@ -3222,6 +3224,7 @@ dependencies = [ "pgt_configuration", "pgt_console", "pgt_diagnostics", + "pgt_env", "pgt_fs", "pgt_hover", "pgt_lexer", @@ -5662,6 +5665,7 @@ dependencies = [ "pgt_analyse", "pgt_analyser", "pgt_diagnostics", + "pgt_env", "pgt_workspace", "proc-macro2", "pulldown-cmark", diff --git a/Cargo.toml b/Cargo.toml index b7963b865..485ac000b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ pgt_console = { path = "./crates/pgt_console", version = "0.0.0" pgt_diagnostics = { path = "./crates/pgt_diagnostics", version = "0.0.0" } pgt_diagnostics_categories = { path = "./crates/pgt_diagnostics_categories", version = "0.0.0" } pgt_diagnostics_macros = { path = "./crates/pgt_diagnostics_macros", version = "0.0.0" } -pgt_flags = { path = "./crates/pgt_flags", version = "0.0.0" } +pgt_env = { path = "./crates/pgt_env", version = "0.0.0" } pgt_fs = { path = "./crates/pgt_fs", version = "0.0.0" } pgt_hover = { path = "./crates/pgt_hover", version = "0.0.0" } pgt_lexer = { path = "./crates/pgt_lexer", version = "0.0.0" } diff --git a/crates/pgt_cli/Cargo.toml b/crates/pgt_cli/Cargo.toml index f2a3fa181..6c39107d5 100644 --- a/crates/pgt_cli/Cargo.toml +++ b/crates/pgt_cli/Cargo.toml @@ -24,7 +24,7 @@ pgt_analyse = { workspace = true } pgt_configuration = { workspace = true } pgt_console = { workspace = true } pgt_diagnostics = { workspace = true } -pgt_flags = { workspace = true } +pgt_env = { workspace = true } pgt_fs = { workspace = true } pgt_lsp = { workspace = true } pgt_text_edit = { workspace = true } diff --git a/crates/pgt_cli/src/commands/clean.rs b/crates/pgt_cli/src/commands/clean.rs index e401f3077..90bfb915c 100644 --- a/crates/pgt_cli/src/commands/clean.rs +++ b/crates/pgt_cli/src/commands/clean.rs @@ -1,6 +1,6 @@ use crate::commands::daemon::default_pgt_log_path; use crate::{CliDiagnostic, CliSession}; -use pgt_flags::pgt_env; +use pgt_env::pgt_env; use std::fs::{create_dir, remove_dir_all}; use std::path::PathBuf; diff --git a/crates/pgt_cli/src/lib.rs b/crates/pgt_cli/src/lib.rs index f8a042440..1e1199bde 100644 --- a/crates/pgt_cli/src/lib.rs +++ b/crates/pgt_cli/src/lib.rs @@ -10,7 +10,6 @@ use commands::check::CheckCommandPayload; use pgt_console::{ColorMode, Console}; use pgt_fs::OsFileSystem; use pgt_workspace::{App, DynRef, Workspace, WorkspaceRef}; -use std::env; mod changed; mod cli_options; @@ -32,10 +31,7 @@ pub use panic::setup_panic_handler; pub use reporter::{DiagnosticsPayload, Reporter, ReporterVisitor, TraversalSummary}; pub use service::{SocketTransport, open_transport}; -pub(crate) const VERSION: &str = match option_env!("PGT_VERSION") { - Some(version) => version, - None => env!("CARGO_PKG_VERSION"), -}; +pub(crate) use pgt_env::VERSION; /// Global context for an execution of the CLI pub struct CliSession<'app> { diff --git a/crates/pgt_configuration/Cargo.toml b/crates/pgt_configuration/Cargo.toml index 3bd685fa5..3912ed9d9 100644 --- a/crates/pgt_configuration/Cargo.toml +++ b/crates/pgt_configuration/Cargo.toml @@ -21,6 +21,7 @@ pgt_analyse = { workspace = true } pgt_analyser = { workspace = true } pgt_console = { workspace = true } pgt_diagnostics = { workspace = true } +pgt_env = { workspace = true } pgt_text_size = { workspace = true } rustc-hash = { workspace = true } schemars = { workspace = true, features = ["indexmap1"], optional = true } diff --git a/crates/pgt_configuration/src/lib.rs b/crates/pgt_configuration/src/lib.rs index 8cac0c3f2..2fe8b399a 100644 --- a/crates/pgt_configuration/src/lib.rs +++ b/crates/pgt_configuration/src/lib.rs @@ -1,7 +1,6 @@ //! This module contains the configuration of `postgrestools.jsonc` //! -//! The configuration is divided by "tool", and then it's possible to further customise it -//! by language. The language might further options divided by tool. +//! The configuration is divided by "tool". pub mod analyser; pub mod database; @@ -34,6 +33,7 @@ use files::{FilesConfiguration, PartialFilesConfiguration, partial_files_configu use migrations::{ MigrationsConfiguration, PartialMigrationsConfiguration, partial_migrations_configuration, }; +use pgt_env::PGT_WEBSITE; use plpgsql_check::{ PartialPlPgSqlCheckConfiguration, PlPgSqlCheckConfiguration, partial_pl_pg_sql_check_configuration, @@ -44,10 +44,7 @@ pub use typecheck::{ }; use vcs::VcsClientKind; -pub const VERSION: &str = match option_env!("PGT_VERSION") { - Some(version) => version, - None => "0.0.0", -}; +pub use pgt_env::VERSION; /// The configuration that is contained inside the configuration file. #[derive(Clone, Debug, Default, Deserialize, Eq, Partial, PartialEq, Serialize)] @@ -106,7 +103,7 @@ impl PartialConfiguration { /// Returns the initial configuration. pub fn init() -> Self { Self { - schema: Some(format!("https://pgtools.dev/schemas/{VERSION}/schema.json")), + schema: Some(format!("{}/schemas/{VERSION}/schema.json", PGT_WEBSITE)), extends: Some(StringSet::default()), files: Some(PartialFilesConfiguration { ignore: Some(Default::default()), diff --git a/crates/pgt_diagnostics_categories/Cargo.toml b/crates/pgt_diagnostics_categories/Cargo.toml index 5f86d4561..f0aa7a7e0 100644 --- a/crates/pgt_diagnostics_categories/Cargo.toml +++ b/crates/pgt_diagnostics_categories/Cargo.toml @@ -12,6 +12,7 @@ version = "0.0.0" [dependencies] +pgt_env = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } diff --git a/crates/pgt_flags/Cargo.toml b/crates/pgt_env/Cargo.toml similarity index 72% rename from crates/pgt_flags/Cargo.toml rename to crates/pgt_env/Cargo.toml index 6a96719c9..1a40f7e9f 100644 --- a/crates/pgt_flags/Cargo.toml +++ b/crates/pgt_env/Cargo.toml @@ -1,12 +1,12 @@ [package] authors.workspace = true categories.workspace = true -description = "" +description = "Environment variables and configuration for Postgres Tools" edition.workspace = true homepage.workspace = true keywords.workspace = true license.workspace = true -name = "pgt_flags" +name = "pgt_env" repository.workspace = true version = "0.0.0" diff --git a/crates/pgt_flags/src/lib.rs b/crates/pgt_env/src/lib.rs similarity index 83% rename from crates/pgt_flags/src/lib.rs rename to crates/pgt_env/src/lib.rs index 133df7776..918a6d1cd 100644 --- a/crates/pgt_flags/src/lib.rs +++ b/crates/pgt_env/src/lib.rs @@ -1,19 +1,34 @@ -//! A simple implementation of feature flags. +//! Environment variables and configuration constants for Postgres Tools. +//! +//! This module provides: +//! - Environment variable definitions for runtime configuration +//! - Static constants like version information and website URL +//! - Helper functions for checking build status use pgt_console::fmt::{Display, Formatter}; use pgt_console::{DebugDisplay, KeyValuePair, markup}; use std::env; -use std::ops::Deref; use std::sync::{LazyLock, OnceLock}; /// Returns `true` if this is an unstable build of Postgres Tools pub fn is_unstable() -> bool { - PGT_VERSION.deref().is_none() + VERSION == "0.0.0" } /// The internal version of Postgres Tools. This is usually supplied during the CI build pub static PGT_VERSION: LazyLock> = LazyLock::new(|| option_env!("PGT_VERSION")); +/// The version of Postgres Tools with fallback logic +pub const VERSION: &str = match option_env!("PGT_VERSION") { + Some(version) => version, + None => match option_env!("CARGO_PKG_VERSION") { + Some(pkg_version) => pkg_version, + None => "0.0.0", + }, +}; + +pub static PGT_WEBSITE: &str = "https://pgtools.dev"; + pub struct PgTEnv { pub pgt_log_path: PgTEnvVariable, pub pgt_log_prefix: PgTEnvVariable, diff --git a/crates/pgt_workspace/Cargo.toml b/crates/pgt_workspace/Cargo.toml index 19e1d3fe3..118d22fc3 100644 --- a/crates/pgt_workspace/Cargo.toml +++ b/crates/pgt_workspace/Cargo.toml @@ -24,6 +24,7 @@ pgt_completions = { workspace = true } pgt_configuration = { workspace = true } pgt_console = { workspace = true } pgt_diagnostics = { workspace = true } +pgt_env = { workspace = true } pgt_fs = { workspace = true, features = ["serde"] } pgt_hover = { workspace = true } pgt_lexer = { workspace = true } diff --git a/crates/pgt_workspace/src/configuration.rs b/crates/pgt_workspace/src/configuration.rs index 87e77b0ca..8b9556cc4 100644 --- a/crates/pgt_workspace/src/configuration.rs +++ b/crates/pgt_workspace/src/configuration.rs @@ -12,6 +12,7 @@ use pgt_configuration::{ VERSION, diagnostics::CantLoadExtendFile, push_to_analyser_rules, }; use pgt_console::markup; +use pgt_env::PGT_WEBSITE; use pgt_fs::{AutoSearchResult, ConfigName, FileSystem, OpenOptions}; use crate::{DynRef, WorkspaceError, settings::Settings}; @@ -186,9 +187,9 @@ pub fn create_config( configuration.schema = node_schema_path.to_str().map(String::from); } else if VERSION == "0.0.0" { // VERSION is 0.0.0 if it has not been explicitly set (e.g local dev, as fallback) - configuration.schema = Some("https://pgtools.dev/latest/schema.json".to_string()); + configuration.schema = Some(format!("{}/latest/schema.json", PGT_WEBSITE)); } else { - configuration.schema = Some(format!("https://pgtools.dev/{VERSION}/schema.json")); + configuration.schema = Some(format!("{}/{VERSION}/schema.json", PGT_WEBSITE)); } let contents = serde_json::to_string_pretty(&configuration) diff --git a/docs/codegen/Cargo.toml b/docs/codegen/Cargo.toml index bf650ac9b..86256d18b 100644 --- a/docs/codegen/Cargo.toml +++ b/docs/codegen/Cargo.toml @@ -21,7 +21,7 @@ serde_json = { workspace = true } pulldown-cmark = "0.12.2" pgt_configuration = { workspace = true, features = ["schema"] } -pgt_flags = { workspace = true } +pgt_env = { workspace = true } pgt_cli = { workspace = true } pgt_analyse = { workspace = true } pgt_analyser = { workspace = true } diff --git a/docs/codegen/src/env_variables.rs b/docs/codegen/src/env_variables.rs index fd21ed1b5..4ff5b412c 100644 --- a/docs/codegen/src/env_variables.rs +++ b/docs/codegen/src/env_variables.rs @@ -10,7 +10,7 @@ pub fn generate_env_variables(docs_dir: &Path) -> Result<()> { let mut content = vec![]; - let env = pgt_flags::pgt_env(); + let env = pgt_env::pgt_env(); writeln!(content, "\n",)?; diff --git a/xtask/codegen/Cargo.toml b/xtask/codegen/Cargo.toml index 758a3212d..92d9246f3 100644 --- a/xtask/codegen/Cargo.toml +++ b/xtask/codegen/Cargo.toml @@ -15,6 +15,7 @@ bpaf = { workspace = true, features = ["derive"] } pgt_analyse = { workspace = true } pgt_analyser = { workspace = true } pgt_diagnostics = { workspace = true } +pgt_env = { workspace = true } pgt_workspace = { workspace = true, features = ["schema"] } proc-macro2 = { workspace = true, features = ["span-locations"] } pulldown-cmark = { version = "0.12.2" } diff --git a/xtask/codegen/src/generate_new_analyser_rule.rs b/xtask/codegen/src/generate_new_analyser_rule.rs index 514886a71..3ad01129d 100644 --- a/xtask/codegen/src/generate_new_analyser_rule.rs +++ b/xtask/codegen/src/generate_new_analyser_rule.rs @@ -1,6 +1,7 @@ use biome_string_case::Case; use bpaf::Bpaf; use pgt_diagnostics::Severity; +use pgt_env::PGT_WEBSITE; use std::str::FromStr; use xtask::project_root; @@ -128,7 +129,8 @@ pub fn generate_new_analyser_rule( // We sort rules to reduce conflicts between contributions made in parallel. let rule_line = match category { Category::Lint => format!( - r#" "lint/{group}/{rule_name_camel}": "https://pgtools.dev/latest/rules/{kebab_case_rule}","# + r#" "lint/{group}/{rule_name_camel}": "{}/latest/rules/{kebab_case_rule}","#, + PGT_WEBSITE ), }; let lint_start = match category {