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

eliminate use of __file__ in boto3.session #4445

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions boto3/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# language governing permissions and limitations under the License.

import copy
import os
from importlib.resources import path

import botocore.session
from botocore.client import Config
Expand Down Expand Up @@ -127,9 +127,9 @@ def _setup_loader(self):
Setup loader paths so that we can load resources.
"""
self._loader = self._session.get_component('data_loader')
self._loader.search_paths.append(
os.path.join(os.path.dirname(__file__), 'data')
)
# NOTE: this context manager is leaked, there's no good place to clean it up
data_path = path(__package__, "data").__enter__()
self._loader.search_paths.append(str(data_path))

def get_available_services(self):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from importlib.resources import path
from unittest.mock import patch

import boto3.session
from tests import unittest

Expand Down Expand Up @@ -45,3 +48,9 @@ def test_get_available_regions(self):
regions = self.session.get_available_regions('s3')
assert isinstance(regions, list)
assert regions

def test_loader_search_path(self):
with patch.object(boto3.session, '__file__', None):
session = boto3.session.Session()
with path(boto3, "data") as data_path:
assert str(data_path) in session._loader.search_paths