Skip to content
This repository was archived by the owner on Feb 3, 2021. It is now read-only.

Commit 5761a36

Browse files
authored
Bug: set explicit file open encoding (#448)
* explicit file encoding * crlf->lf
1 parent dfbfead commit 5761a36

File tree

12 files changed

+24
-22
lines changed

12 files changed

+24
-22
lines changed

aztk/internal/cluster_data/node_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def add_file(self, file: str, zip_dir: str, binary: bool = True):
4747
return
4848
if isinstance(file, (str, bytes)):
4949
full_file_path = Path(file)
50-
with io.open(file, 'r') as f:
50+
with io.open(file, 'r', encoding='UTF-8') as f:
5151
if binary:
5252
self.zipf.write(file, os.path.join(zip_dir, full_file_path.name))
5353
else:
@@ -70,7 +70,7 @@ def add_dir(self, path: str, dest: str = None, exclude: List[str] = []):
7070
relative_folder = os.path.relpath(base, path)
7171
for file in files:
7272
if self._includeFile(file, exclude):
73-
with io.open(os.path.join(base, file), 'r') as f:
73+
with io.open(os.path.join(base, file), 'r', encoding='UTF-8') as f:
7474
self.zipf.writestr(os.path.join(dest, relative_folder, file), f.read().replace('\r\n', '\n'))
7575

7676
def _add_custom_scripts(self):
@@ -83,7 +83,7 @@ def _add_custom_scripts(self):
8383
new_file_name = str(index) + '_' + os.path.basename(custom_script.script)
8484
data.append(dict(script=new_file_name, runOn=str(custom_script.run_on)))
8585
try:
86-
with io.open(custom_script.script, 'r') as f:
86+
with io.open(custom_script.script, 'r', encoding='UTF-8') as f:
8787
self.zipf.writestr(
8888
os.path.join(CUSTOM_SCRIPT_FOLDER, new_file_name),
8989
f.read().replace('\r\n', '\n'))

aztk/models/plugins/plugin_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, target: str, local_path: str):
1313
# TODO handle folders?
1414

1515
def content(self):
16-
with open(self.local_path, "r") as f:
16+
with open(self.local_path, "r", encoding='UTF-8') as f:
1717
return f.read()
1818

1919

aztk/node_scripts/install/create_user.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def create_user(batch_client):
1616
print("No user to create.")
1717
return
1818

19-
with open(path) as file:
19+
with open(path, 'r', encoding='UTF-8') as file:
2020
user_conf = yaml.load(file.read())
2121

2222
try:
@@ -43,7 +43,8 @@ def decrypt_password(user_conf):
4343
tag = user_conf['tag']
4444

4545
# Read private key
46-
private_key = RSA.import_key(open(os.path.join(os.environ['DOCKER_WORKING_DIR'], 'id_rsa')).read())
46+
with open(os.path.join(os.environ['DOCKER_WORKING_DIR'], 'id_rsa'), encoding='UTF-8') as f:
47+
private_key = RSA.import_key(f.read())
4748
# Decrypt the session key with the public RSA key
4849
cipher_rsa = PKCS1_OAEP.new(private_key)
4950
session_key = cipher_rsa.decrypt(encrypted_aes_session_key)

aztk/node_scripts/install/plugins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _read_manifest_file(path=None):
1212
if not os.path.isfile(path):
1313
print("Plugins manifest file doesn't exist at {0}".format(path))
1414
else:
15-
with open(path, 'r') as stream:
15+
with open(path, 'r', encoding='UTF-8') as stream:
1616
try:
1717
custom_scripts = yaml.load(stream)
1818
except json.JSONDecodeError as err:
@@ -86,7 +86,7 @@ def _run_script(name: str, script_path: str = None, args: dict = None, env: dict
8686
if args is None:
8787
args = []
8888

89-
out_file = open(os.path.join(log_folder, '{0}.txt'.format(name)), 'w')
89+
out_file = open(os.path.join(log_folder, '{0}.txt'.format(name)), 'w', encoding='UTF-8')
9090
try:
9191
subprocess.call(
9292
[script_path] + args,

aztk/node_scripts/install/scripts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def _read_yaml_file(path=None):
99
if not os.path.isfile(path):
1010
print("Configuration file doesn't exist at {0}".format(path))
1111
else:
12-
with open(path, 'r') as stream:
12+
with open(path, 'r', encoding='UTF-8') as stream:
1313
try:
1414
custom_scripts = yaml.load(stream)
1515
except yaml.YAMLError as err:

aztk/node_scripts/install/spark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def setup_connection():
4343
master_node = get_node(master_node_id)
4444

4545
master_config_file = os.path.join(spark_conf_folder, "master")
46-
master_file = open(master_config_file, 'w')
46+
master_file = open(master_config_file, 'w', encoding='UTF-8')
4747

4848
print("Adding master node ip {0} to config file '{1}'".format(
4949
master_node.ip_address, master_config_file))
@@ -195,7 +195,7 @@ def copy_jars():
195195

196196
def parse_configuration_file(path_to_file: str):
197197
try:
198-
file = open(path_to_file, 'r')
198+
file = open(path_to_file, 'r', encoding='UTF-8')
199199
properties = {}
200200
for line in file:
201201
if (not line.startswith('#') and len(line) > 1):

aztk/node_scripts/job_submission.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def schedule_tasks(tasks_path):
2727
blob_client = config.blob_client
2828

2929
for task_definition in tasks_path:
30-
with open(task_definition, 'r') as stream:
30+
with open(task_definition, 'r', encoding='UTF-8') as stream:
3131
try:
3232
task = yaml.load(stream)
3333
except yaml.YAMLError as exc:

aztk/node_scripts/submit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def load_application(application_file_path):
124124
'''
125125
Read and parse the application from file
126126
'''
127-
with open(application_file_path) as f:
127+
with open(application_file_path, encoding='UTF-8') as f:
128128
application = yaml.load(f)
129129
return application
130130

@@ -176,7 +176,8 @@ def upload_error_log(error, application_file_path):
176176
application = load_application(application_file_path)
177177
blob_client = config.blob_client
178178

179-
with open(os.path.join(os.environ["AZ_BATCH_TASK_WORKING_DIR"], "error.log"), "w") as error_log:
179+
error_log_path = os.path.join(os.environ["AZ_BATCH_TASK_WORKING_DIR"], "error.log")
180+
with open(error_log_path, "w", encoding='UTF-8') as error_log:
180181
error_log.write(error)
181182

182183
upload_file_to_container(

aztk/utils/get_ssh_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ def __read_ssh_key_from_file(path: str) -> str:
2828
"""
2929
Read the content of the given file
3030
"""
31-
with open(os.path.expanduser(path), 'r') as content_file:
31+
with open(os.path.expanduser(path), 'r', encoding='UTF-8') as content_file:
3232
content = content_file.read()
3333
return content

aztk_cli/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _load_secrets_config(
4646
if not os.path.isfile(path):
4747
return None
4848

49-
with open(path, 'r') as stream:
49+
with open(path, 'r', encoding='UTF-8') as stream:
5050
try:
5151
return yaml.load(stream)
5252
except yaml.YAMLError as err:
@@ -129,7 +129,7 @@ def read_cluster_config(
129129
if not os.path.isfile(path):
130130
return
131131

132-
with open(path, 'r') as stream:
132+
with open(path, 'r', encoding='UTF-8') as stream:
133133
try:
134134
config_dict = yaml.load(stream)
135135
except yaml.YAMLError as err:
@@ -224,7 +224,7 @@ def _read_config_file(
224224
if not os.path.isfile(path):
225225
return
226226

227-
with open(path, 'r') as stream:
227+
with open(path, 'r', encoding='UTF-8') as stream:
228228
try:
229229
config = yaml.load(stream)
230230
except yaml.YAMLError as err:
@@ -359,7 +359,7 @@ def _read_config_file(
359359
if not path or not os.path.isfile(path):
360360
return
361361

362-
with open(path, 'r') as stream:
362+
with open(path, 'r', encoding='UTF-8') as stream:
363363
try:
364364
config = yaml.load(stream)
365365
except yaml.YAMLError as err:

0 commit comments

Comments
 (0)