Skip to content

Commit

Permalink
fix: set utf-8 encoding for Python
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Mar 21, 2021
1 parent a35a141 commit d9cefcc
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/grammars/python.coffee
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
GrammarUtils = require '../grammar-utils'

# https://github.com/atom-community/atom-script/issues/214#issuecomment-418766763
encodingSet = false
setEncoding: ->
if (!encodingSet)
process.env.PYTHONIOENCODING = 'utf-8'
encodingSet = true
return

exports.Python =
'Selection Based':
command: 'python'
args: (context) ->
setEncoding()
code = context.getCode()
tmpFile = GrammarUtils.createTempFileWithCode(code)
return ['-u', tmpFile]

'File Based':
command: 'python'
args: ({filepath}) -> ['-u', filepath]
args: ({filepath}) ->
setEncoding()
return ['-u', filepath]

exports.MagicPython = exports.Python

exports.Sage =
'Selection Based':
command: 'sage'
args: (context) ->
setEncoding()
code = context.getCode()
tmpFile = GrammarUtils.createTempFileWithCode(code)
return [tmpFile]

'File Based':
command: 'sage'
args: ({filepath}) -> [filepath]
args: ({filepath}) ->
setEncoding()
return [filepath]

0 comments on commit d9cefcc

Please sign in to comment.