1111PACKAGE_OUT_REL = "golf/_endpoints.py"
1212
1313
14- def render_endpoints ():
14+ def render_endpoints (require_env_vars : bool = True ):
1515 """Render the endpoints template with environment variables."""
1616 tpl_path = pathlib .Path (TEMPLATE_REL )
1717 if not tpl_path .exists ():
1818 raise FileNotFoundError (f"Template not found: { tpl_path } " )
1919
20- # Require environment variables - no defaults with real URLs
20+ # Get environment variables
2121 platform_url = os .environ .get ("GOLF_PLATFORM_API_URL" )
2222 otel_url = os .environ .get ("GOLF_OTEL_ENDPOINT" )
2323
24- if not platform_url or not otel_url :
24+ # For production builds, require environment variables
25+ # For development/editable installs, use fallback values
26+ if require_env_vars and (not platform_url or not otel_url ):
2527 raise SystemExit (
2628 "Missing required environment variables for URL injection:\n "
2729 " GOLF_PLATFORM_API_URL\n "
2830 " GOLF_OTEL_ENDPOINT\n "
2931 "Set these before building the package."
3032 )
3133
34+ # Use environment variables if available, otherwise fallback to development URLs
3235 values = {
33- "PLATFORM_API_URL" : platform_url ,
34- "OTEL_ENDPOINT" : otel_url ,
36+ "PLATFORM_API_URL" : platform_url or "http://localhost:8000/api/resources" ,
37+ "OTEL_ENDPOINT" : otel_url or "http://localhost:4318/v1/traces" ,
3538 }
3639
3740 try :
@@ -49,8 +52,8 @@ def run(self):
4952 # First run the normal build
5053 super ().run ()
5154
52- # Then render endpoints into the build_lib
53- rendered = render_endpoints ()
55+ # Then render endpoints into the build_lib (require env vars for production builds)
56+ rendered = render_endpoints (require_env_vars = True )
5457 out_file = pathlib .Path (self .build_lib ) / PACKAGE_OUT_REL
5558 out_file .parent .mkdir (parents = True , exist_ok = True )
5659 out_file .write_text (rendered , encoding = "utf-8" )
@@ -64,8 +67,8 @@ def run(self):
6467 # Run normal develop command first
6568 super ().run ()
6669
67- # Generate a working copy file for editable installs
68- rendered = render_endpoints ()
70+ # Generate a working copy file for editable installs (use fallback URLs if env vars missing)
71+ rendered = render_endpoints (require_env_vars = False )
6972 # For editable installs, write into the source tree so imports work
7073 src_file = pathlib .Path ("src" ) / PACKAGE_OUT_REL
7174 src_file .parent .mkdir (parents = True , exist_ok = True )
0 commit comments