forked from mindee/doctr
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to use doctr on AWS Lambda (mindee#1017)
- Loading branch information
Showing
7 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
AWS Lambda | ||
======================== | ||
|
||
AWS Lambda's (read more about Lambda https://aws.amazon.com/lambda/) security policy does not allow you to write anywhere outside `/tmp` directory. | ||
There are two things you need to do to make `doctr` work on lambda: | ||
1. Disable usage of `multiprocessing` package by setting `DOCTR_MULTIPROCESSING_DISABLE` enivronment variable to `TRUE`. You need to do this, because this package uses `/dev/shm` directory for shared memory. | ||
2. Change directory `doctr` uses for caching models. By default it's `~/.cache/doctr` which is outside of `/tmp` on AWS Lambda'. You can do this by setting `DOCTR_CACHE_DIR` enivronment variable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
from pathlib import PosixPath | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from doctr.utils.data import download_from_url | ||
|
||
|
||
@patch("doctr.utils.data._urlretrieve") | ||
@patch("pathlib.Path.mkdir") | ||
@patch.dict(os.environ, {"HOME": "/"}, clear=True) | ||
def test_download_from_url(mkdir_mock, urlretrieve_mock): | ||
download_from_url("test_url") | ||
urlretrieve_mock.assert_called_with("test_url", PosixPath("/.cache/doctr/test_url")) | ||
|
||
|
||
@patch.dict(os.environ, {"DOCTR_CACHE_DIR": "/test"}, clear=True) | ||
@patch("doctr.utils.data._urlretrieve") | ||
@patch("pathlib.Path.mkdir") | ||
def test_download_from_url_customizing_cache_dir(mkdir_mock, urlretrieve_mock): | ||
download_from_url("test_url") | ||
urlretrieve_mock.assert_called_with("test_url", PosixPath("/test/test_url")) | ||
|
||
|
||
@patch.dict(os.environ, {"HOME": "/"}, clear=True) | ||
@patch("pathlib.Path.mkdir", side_effect=OSError) | ||
@patch("logging.error") | ||
def test_download_from_url_error_creating_directory(logging_mock, mkdir_mock): | ||
with pytest.raises(OSError): | ||
download_from_url("test_url") | ||
logging_mock.assert_called_with( | ||
"Failed creating cache direcotry at /.cache/doctr." | ||
" You can change default cache directory using 'DOCTR_CACHE_DIR' environment variable if needed." | ||
) | ||
|
||
|
||
@patch.dict(os.environ, {"HOME": "/", "DOCTR_CACHE_DIR": "/test"}, clear=True) | ||
@patch("pathlib.Path.mkdir", side_effect=OSError) | ||
@patch("logging.error") | ||
def test_download_from_url_error_creating_directory_with_env_var(logging_mock, mkdir_mock): | ||
with pytest.raises(OSError): | ||
download_from_url("test_url") | ||
logging_mock.assert_called_with( | ||
"Failed creating cache direcotry at /test using path from 'DOCTR_CACHE_DIR' environment variable." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters