Skip to content

Commit eb4700d

Browse files
committed
fix: set utf-8 encoding for Python
1 parent 80bb364 commit eb4700d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/grammars/python.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
import GrammarUtils from "../grammar-utils"
44

5+
// https://github.com/atom-community/atom-script/issues/214#issuecomment-418766763
6+
let encodingSet = false
7+
function setEncoding() {
8+
if (!encodingSet) {
9+
process.env.PYTHONIOENCODING = "utf-8"
10+
encodingSet = true
11+
}
12+
}
13+
514
export const Python = {
615
"Selection Based": {
716
command: "python",
817
args(context) {
18+
setEncoding()
919
const code = context.getCode()
1020
const tmpFile = GrammarUtils.createTempFileWithCode(code)
1121
return ["-u", tmpFile]
@@ -15,6 +25,7 @@ export const Python = {
1525
"File Based": {
1626
command: "python",
1727
args({ filepath }) {
28+
setEncoding()
1829
return ["-u", filepath]
1930
},
2031
},
@@ -26,6 +37,7 @@ export const Sage = {
2637
"Selection Based": {
2738
command: "sage",
2839
args(context) {
40+
setEncoding()
2941
const code = context.getCode()
3042
const tmpFile = GrammarUtils.createTempFileWithCode(code)
3143
return [tmpFile]
@@ -35,6 +47,7 @@ export const Sage = {
3547
"File Based": {
3648
command: "sage",
3749
args({ filepath }) {
50+
setEncoding()
3851
return [filepath]
3952
},
4053
},

spec/fixtures/issue_1166.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print ('汉语/漢語')

0 commit comments

Comments
 (0)