Skip to content

Commit 82f7342

Browse files
committed
place config in helper function
1 parent 48e52bd commit 82f7342

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

silnlp/common/environment.py

+14-24
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,7 @@ def copy_pt_project_from_bucket(self, name: Union[str, Path], patterns: Union[st
174174
raise Exception(
175175
f"No paratext project name is given. Data still in the cache directory of {self.pt_projects_dir}"
176176
)
177-
config = Config(
178-
s3={"addressing_style": "path"},
179-
retries={"mode": "adaptive", "max_attempts": 10},
180-
connect_timeout=600,
181-
read_timeout=600,
182-
)
177+
config = generate_s3_config()
183178
s3 = boto3.resource("s3", config=config)
184179
data_bucket = s3.Bucket(str(self.data_dir).strip("\\/"))
185180
len_silnlp_path = len(pt_projects_path)
@@ -213,12 +208,7 @@ def copy_experiment_from_bucket(self, name: Union[str, Path], patterns: Union[st
213208
raise Exception(
214209
f"No experiment name is given. Data still in the cache directory of {self.mt_experiments_dir}"
215210
)
216-
config = Config(
217-
s3={"addressing_style": "path"},
218-
retries={"mode": "adaptive", "max_attempts": 10},
219-
connect_timeout=600,
220-
read_timeout=600,
221-
)
211+
config = generate_s3_config()
222212
s3 = boto3.resource("s3", config=config)
223213
data_bucket = s3.Bucket(str(self.data_dir).strip("\\/"))
224214
len_silnlp_path = len(experiments_path)
@@ -251,12 +241,7 @@ def copy_experiment_to_bucket(self, name: str, patterns: Union[str, Sequence[str
251241
f"No experiment name is given. Data still in the temp directory of {self.mt_experiments_dir}"
252242
)
253243
experiment_path = str(self.mt_dir.relative_to(self.data_dir) / "experiments") + "/"
254-
config = Config(
255-
s3={"addressing_style": "path"},
256-
retries={"mode": "adaptive", "max_attempts": 10},
257-
connect_timeout=600,
258-
read_timeout=600,
259-
)
244+
config = generate_s3_config()
260245
s3 = boto3.resource("s3", config=config)
261246
data_bucket = s3.Bucket(str(self.data_dir).strip("\\/"))
262247
temp_folder = str(self.mt_experiments_dir / name)
@@ -300,12 +285,7 @@ def download_if_s3_paths(paths: Iterable[S3Path]) -> List[Path]:
300285
if not s3_setup:
301286
temp_root = Path(tempfile.TemporaryDirectory().name)
302287
temp_root.mkdir()
303-
config = Config(
304-
s3={"addressing_style": "path"},
305-
retries={"mode": "adaptive", "max_attempts": 10},
306-
connect_timeout=600,
307-
read_timeout=600,
308-
)
288+
config = generate_s3_config()
309289
s3 = boto3.resource("s3", config=config)
310290
data_bucket = s3.Bucket(str(SIL_NLP_ENV.data_dir).strip("\\/"))
311291
s3_setup = True
@@ -357,4 +337,14 @@ def get_env_path(name: str, default: str = ".") -> str:
357337
return path
358338

359339

340+
def generate_s3_config() -> Config:
341+
s3_config = Config(
342+
s3={"addressing_style": "path"},
343+
retries={"mode": "adaptive", "max_attempts": 10},
344+
connect_timeout=600,
345+
read_timeout=600,
346+
)
347+
return s3_config
348+
349+
360350
SIL_NLP_ENV = SilNlpEnv()

0 commit comments

Comments
 (0)