简体   繁体   中英

Indentation errors with scons / SConscript files

I'm trying to write a SConscript file so that I can use scons to build Go code. The SConscript file is pretty simple; its just a starter file:

def gc(source, target, env, for_signature):
   targets = target[0]
   sources = " ".join(str(s) for s in source)
   print(sources)
   return 'go build {}'.format(sources)


go_compiler = Builder(
   generator=gc,
   src_suffix='.go',
)

# Create environment
env = Environment(
   BUILDERS={'Go': go_compiler, }
)

# Build programs
main_package = env.Go(target='helloworld', source='helloworld.go')

But I keep getting this error:

# scons
scons: Reading SConscript files ...
  File "/root/repo/SConstruct", line 5

    print(sources)

    ^

IndentationError: unexpected indent

I tried switching between python v2.7 and 3.7, rewriting the code in various different ways, but I kept hitting the same issue. I even tried writing several fragments of the above code inside a python interpreter and the syntax and indentation were fine.

I had copied/pasted some of this code from online. Turns out there was some embedded tabs, but my editor was using spaces. So several lines were inconsistently indented. I spend hours looking at this, so I figured I would share my mistake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM