Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boto3 dependency, add venv/.venv to .gitignore #239

Merged
merged 8 commits into from
Jul 11, 2024
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ model_output/
/*.Rcheck/

# RStudio files
.Rproj.user/
.Rproj.user
flepiMoP.Rproj
*.Rproj

Expand Down Expand Up @@ -64,7 +64,8 @@ packrat/lib*/
dist/
SEIR.egg-info/
Outcomes.egg-info/
.Rproj.user
venv/
.venv/

# R package manuals
man/
Expand All @@ -74,3 +75,6 @@ flepimop/gempyor_pkg/get_value.prof
flepimop/gempyor_pkg/tests/seir/.coverage
flepimop/gempyor_pkg/tests/seir/.coverage.kojis-mbp-8.sph.ad.jhsph.edu.90615.974746
flepimop/gempyor_pkg/.coverage

# Environment variables
.env
4 changes: 3 additions & 1 deletion flepimop/gempyor_pkg/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ install_requires =
test =
pytest
mock

aws =
boto3
botocore

[options.entry_points]
console_scripts =
Expand Down
11 changes: 8 additions & 3 deletions flepimop/gempyor_pkg/src/gempyor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import subprocess
import shutil
import logging
import boto3
from gempyor import file_paths
from typing import List, Dict
from botocore.exceptions import ClientError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -509,12 +507,19 @@ def download_file_from_s3(name_map: Dict[str, str]) -> None:
>>> download_file_from_s3(name_map)
# This will raise a ValueError indicating the invalid S3 URI format.
"""
try:
import boto3
from botocore.exceptions import ClientError
except ModuleNotFoundError:
raise ModuleNotFoundError((
"No module named 'boto3', which is required for "
"gempyor.utils.download_file_from_s3. Please install the aws target."
))
s3 = boto3.client("s3")
first_output_filename = next(iter(name_map.values()))
output_dir = os.path.dirname(first_output_filename)
if not os.path.exists(output_dir):
os.makedirs(output_dir)

for s3_uri in name_map:
try:
if s3_uri.startswith("s3://"):
Expand Down
Loading