@@ -114,6 +114,13 @@ class CopiedArtifact:
114114}
115115
116116
117+ def _env_truthy (value : Optional [str ]) -> bool :
118+ """Return True when an environment variable value reads as enabled/truthy."""
119+ if value is None :
120+ return False
121+ return value .strip ().lower () not in ("" , "0" , "false" , "no" , "off" )
122+
123+
117124def _normalize_machine (machine : str ) -> str :
118125 normalized = machine .lower ().replace ("-" , "_" )
119126 aliases = {
@@ -392,6 +399,11 @@ class RustArtifactConfig(BaseModel):
392399 model_config = ConfigDict (extra = "ignore" , populate_by_name = True )
393400
394401 name : Optional [str ] = Field (default = None , description = "Cargo artifact name used for exact artifact discovery and errors." )
402+ skip_if_env : Optional [str ] = Field (
403+ default = None ,
404+ alias = "skip-if-env" ,
405+ description = "Skip building and packaging this artifact when the named environment variable is set to a truthy value." ,
406+ )
395407 manifest : Optional [Path ] = Field (default = None , description = "Path to Cargo.toml, relative to the hook path unless absolute." )
396408 build_type : Optional [BuildType ] = Field (default = None , alias = "build-type" )
397409 profile : Optional [str ] = Field (default = None , description = "Cargo profile for this artifact." )
@@ -651,9 +663,12 @@ def shared_data(self) -> dict[str, str]:
651663 def resolved_target (self ) -> Optional [ResolvedTarget ]:
652664 return self ._resolved_target
653665
666+ def _artifact_skipped (self , artifact : RustArtifactConfig ) -> bool :
667+ return artifact .skip_if_env is not None and _env_truthy (environ .get (artifact .skip_if_env ))
668+
654669 def _configured_artifacts (self ) -> list [RustArtifactConfig ]:
655670 if self .artifacts :
656- return list ( self .artifacts )
671+ return [ artifact for artifact in self .artifacts if not self . _artifact_skipped ( artifact )]
657672 return [RustArtifactConfig (destination = f"{ self .module } /{{python_extension_name}}" )]
658673
659674 def _artifact_label (self , artifact : RustArtifactConfig ) -> str :
0 commit comments