Skip to content

Commit

Permalink
Merge pull request #2421 from atom-community/python-encoding
Browse files Browse the repository at this point in the history
fix: set utf-8 encoding for Python
  • Loading branch information
aminya authored May 11, 2021
2 parents a672214 + eb4700d commit de01edd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/grammars/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

import GrammarUtils from "../grammar-utils"

// https://github.com/atom-community/atom-script/issues/214#issuecomment-418766763
let encodingSet = false
function setEncoding() {
if (!encodingSet) {
process.env.PYTHONIOENCODING = "utf-8"
encodingSet = true
}
}

export const Python = {
"Selection Based": {
command: "python",
args(context) {
setEncoding()
const code = context.getCode()
const tmpFile = GrammarUtils.createTempFileWithCode(code)
return ["-u", tmpFile]
Expand All @@ -15,6 +25,7 @@ export const Python = {
"File Based": {
command: "python",
args({ filepath }) {
setEncoding()
return ["-u", filepath]
},
},
Expand All @@ -26,6 +37,7 @@ export const Sage = {
"Selection Based": {
command: "sage",
args(context) {
setEncoding()
const code = context.getCode()
const tmpFile = GrammarUtils.createTempFileWithCode(code)
return [tmpFile]
Expand All @@ -35,6 +47,7 @@ export const Sage = {
"File Based": {
command: "sage",
args({ filepath }) {
setEncoding()
return [filepath]
},
},
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/issue_1166.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print ('汉语/漢語')

0 comments on commit de01edd

Please sign in to comment.