129
129
130
130
GE_REQUIRED = ["great_expectations>=0.15.41,<0.16.0" ]
131
131
132
- GO_REQUIRED = [
133
- "cffi~=1.15.0" ,
134
- ]
135
-
136
132
AZURE_REQUIRED = [
137
133
"azure-storage-blob>=0.37.0" ,
138
134
"azure-identity>=1.6.1" ,
@@ -316,93 +312,12 @@ def run(self):
316
312
file .write (filedata )
317
313
318
314
319
- def _generate_path_with_gopath ():
320
- go_path = subprocess .check_output (["go" , "env" , "GOPATH" ]).decode ("utf-8" )
321
- go_path = go_path .strip ()
322
- path_val = os .getenv ("PATH" )
323
- path_val = f"{ path_val } :{ go_path } /bin"
324
-
325
- return path_val
326
-
327
-
328
- def _ensure_go_and_proto_toolchain ():
329
- try :
330
- version = subprocess .check_output (["go" , "version" ])
331
- except Exception as e :
332
- raise RuntimeError ("Unable to find go toolchain" ) from e
333
-
334
- semver_string = re .search (r"go[\S]+" , str (version )).group ().lstrip ("go" )
335
- parts = semver_string .split ("." )
336
- if not (int (parts [0 ]) >= 1 and int (parts [1 ]) >= 16 ):
337
- raise RuntimeError (f"Go compiler too old; expected 1.16+ found { semver_string } " )
338
-
339
- path_val = _generate_path_with_gopath ()
340
-
341
- try :
342
- subprocess .check_call (["protoc-gen-go" , "--version" ], env = {"PATH" : path_val })
343
- subprocess .check_call (
344
- ["protoc-gen-go-grpc" , "--version" ], env = {"PATH" : path_val }
345
- )
346
- except Exception as e :
347
- raise RuntimeError ("Unable to find go/grpc extensions for protoc" ) from e
348
-
349
-
350
- class BuildGoProtosCommand (Command ):
351
- description = "Builds the proto files into Go files."
352
- user_options = []
353
-
354
- def initialize_options (self ):
355
- self .go_protoc = [
356
- sys .executable ,
357
- "-m" ,
358
- "grpc_tools.protoc" ,
359
- ] # find_executable("protoc")
360
- self .proto_folder = os .path .join (repo_root , "protos" )
361
- self .go_folder = os .path .join (repo_root , "go/protos" )
362
- self .sub_folders = PROTO_SUBDIRS
363
- self .path_val = _generate_path_with_gopath ()
364
-
365
- def finalize_options (self ):
366
- pass
367
-
368
- def _generate_go_protos (self , path : str ):
369
- proto_files = glob .glob (os .path .join (self .proto_folder , path ))
370
-
371
- try :
372
- subprocess .check_call (
373
- self .go_protoc
374
- + [
375
- "-I" ,
376
- self .proto_folder ,
377
- "--go_out" ,
378
- self .go_folder ,
379
- "--go_opt=module=github.com/feast-dev/feast/go/protos" ,
380
- "--go-grpc_out" ,
381
- self .go_folder ,
382
- "--go-grpc_opt=module=github.com/feast-dev/feast/go/protos" ,
383
- ]
384
- + proto_files ,
385
- env = {"PATH" : self .path_val },
386
- )
387
- except CalledProcessError as e :
388
- print (f"Stderr: { e .stderr } " )
389
- print (f"Stdout: { e .stdout } " )
390
-
391
- def run (self ):
392
- go_dir = Path (repo_root ) / "go" / "protos"
393
- go_dir .mkdir (exist_ok = True )
394
- for sub_folder in self .sub_folders :
395
- self ._generate_go_protos (f"feast/{ sub_folder } /*.proto" )
396
-
397
315
398
316
class BuildCommand (build_py ):
399
317
"""Custom build command."""
400
318
401
319
def run (self ):
402
320
self .run_command ("build_python_protos" )
403
- if os .getenv ("COMPILE_GO" , "false" ).lower () == "true" :
404
- _ensure_go_and_proto_toolchain ()
405
- self .run_command ("build_go_protos" )
406
321
407
322
self .run_command ("build_ext" )
408
323
build_py .run (self )
@@ -414,99 +329,10 @@ class DevelopCommand(develop):
414
329
def run (self ):
415
330
self .reinitialize_command ("build_python_protos" , inplace = 1 )
416
331
self .run_command ("build_python_protos" )
417
- if os .getenv ("COMPILE_GO" , "false" ).lower () == "true" :
418
- _ensure_go_and_proto_toolchain ()
419
- self .run_command ("build_go_protos" )
420
332
421
333
develop .run (self )
422
334
423
335
424
- class build_ext (_build_ext ):
425
- def finalize_options (self ) -> None :
426
- super ().finalize_options ()
427
- if os .getenv ("COMPILE_GO" , "false" ).lower () == "false" :
428
- self .extensions = [e for e in self .extensions if not self ._is_go_ext (e )]
429
-
430
- def _is_go_ext (self , ext : Extension ):
431
- return any (
432
- source .endswith (".go" ) or source .startswith ("github" )
433
- for source in ext .sources
434
- )
435
-
436
- def build_extension (self , ext : Extension ):
437
- print (f"Building extension { ext } " )
438
- if not self ._is_go_ext (ext ):
439
- # the base class may mutate `self.compiler`
440
- compiler = copy .deepcopy (self .compiler )
441
- self .compiler , compiler = compiler , self .compiler
442
- try :
443
- return _build_ext .build_extension (self , ext )
444
- finally :
445
- self .compiler , compiler = compiler , self .compiler
446
-
447
- bin_path = _generate_path_with_gopath ()
448
- go_env = json .loads (
449
- subprocess .check_output (["go" , "env" , "-json" ]).decode ("utf-8" ).strip ()
450
- )
451
-
452
- print (f"Go env: { go_env } " )
453
- print (f"CWD: { os .getcwd ()} " )
454
-
455
- destination = os .path .dirname (os .path .abspath (self .get_ext_fullpath (ext .name )))
456
- subprocess .check_call (
457
- ["go" , "install" , "golang.org/x/tools/cmd/goimports" ],
458
- env = {"PATH" : bin_path , ** go_env },
459
- )
460
- subprocess .check_call (
461
- ["go" , "get" , "github.com/go-python/gopy@v0.4.4" ],
462
- env = {"PATH" : bin_path , ** go_env },
463
- )
464
- subprocess .check_call (
465
- ["go" , "install" , "github.com/go-python/gopy" ],
466
- env = {"PATH" : bin_path , ** go_env },
467
- )
468
- subprocess .check_call (
469
- [
470
- "gopy" ,
471
- "build" ,
472
- "-output" ,
473
- destination ,
474
- "-vm" ,
475
- sys .executable ,
476
- "--build-tags" ,
477
- "cgo,ccalloc" ,
478
- "--dynamic-link=True" ,
479
- "-no-make" ,
480
- * ext .sources ,
481
- ],
482
- env = {
483
- "PATH" : bin_path ,
484
- "CGO_LDFLAGS_ALLOW" : ".*" ,
485
- ** go_env ,
486
- },
487
- )
488
-
489
- def copy_extensions_to_source (self ):
490
- build_py = self .get_finalized_command ("build_py" )
491
- for ext in self .extensions :
492
- fullname = self .get_ext_fullname (ext .name )
493
- modpath = fullname .split ("." )
494
- package = "." .join (modpath [:- 1 ])
495
- package_dir = build_py .get_package_dir (package )
496
-
497
- src_dir = dest_dir = package_dir
498
-
499
- if src_dir .startswith (PYTHON_CODE_PREFIX ):
500
- src_dir = package_dir [len (PYTHON_CODE_PREFIX ) :]
501
- src_dir = src_dir .lstrip ("/" )
502
-
503
- src_dir = os .path .join (self .build_lib , src_dir )
504
-
505
- # copy whole directory
506
- print (f"Copying from { src_dir } to { dest_dir } " )
507
- copy_tree (src_dir , dest_dir )
508
-
509
-
510
336
setup (
511
337
name = NAME ,
512
338
author = AUTHOR ,
@@ -537,7 +363,6 @@ def copy_extensions_to_source(self):
537
363
"mysql" : MYSQL_REQUIRED ,
538
364
"ge" : GE_REQUIRED ,
539
365
"hbase" : HBASE_REQUIRED ,
540
- "go" : GO_REQUIRED ,
541
366
"docs" : DOCS_REQUIRED ,
542
367
"cassandra" : CASSANDRA_REQUIRED ,
543
368
},
@@ -562,15 +387,7 @@ def copy_extensions_to_source(self):
562
387
],
563
388
cmdclass = {
564
389
"build_python_protos" : BuildPythonProtosCommand ,
565
- "build_go_protos" : BuildGoProtosCommand ,
566
390
"build_py" : BuildCommand ,
567
391
"develop" : DevelopCommand ,
568
- "build_ext" : build_ext ,
569
392
},
570
- ext_modules = [
571
- Extension (
572
- "feast.embedded_go.lib._embedded" ,
573
- ["github.com/feast-dev/feast/go/embedded" ],
574
- )
575
- ],
576
393
)
0 commit comments