mirror of
https://github.com/docker/compose.git
synced 2025-07-21 20:54:32 +02:00
Convert paths to unicode in get_config_path_from_options if needed
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
94defc159a
commit
0f00aa4098
@ -49,14 +49,17 @@ def get_config_from_options(base_dir, options):
|
|||||||
|
|
||||||
|
|
||||||
def get_config_path_from_options(base_dir, options, environment):
|
def get_config_path_from_options(base_dir, options, environment):
|
||||||
|
def unicode_paths(paths):
|
||||||
|
return [p.decode('utf-8') if isinstance(p, six.binary_type) else p for p in paths]
|
||||||
|
|
||||||
file_option = options.get('--file')
|
file_option = options.get('--file')
|
||||||
if file_option:
|
if file_option:
|
||||||
return file_option
|
return unicode_paths(file_option)
|
||||||
|
|
||||||
config_files = environment.get('COMPOSE_FILE')
|
config_files = environment.get('COMPOSE_FILE')
|
||||||
if config_files:
|
if config_files:
|
||||||
pathsep = environment.get('COMPOSE_PATH_SEPARATOR', os.pathsep)
|
pathsep = environment.get('COMPOSE_PATH_SEPARATOR', os.pathsep)
|
||||||
return config_files.split(pathsep)
|
return unicode_paths(config_files.split(pathsep))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
# ~*~ encoding: utf-8 ~*~
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import six
|
||||||
|
|
||||||
from compose.cli.command import get_config_path_from_options
|
from compose.cli.command import get_config_path_from_options
|
||||||
from compose.config.environment import Environment
|
from compose.config.environment import Environment
|
||||||
@ -55,3 +57,20 @@ class TestGetConfigPathFromOptions(object):
|
|||||||
def test_no_path(self):
|
def test_no_path(self):
|
||||||
environment = Environment.from_env_file('.')
|
environment = Environment.from_env_file('.')
|
||||||
assert not get_config_path_from_options('.', {}, environment)
|
assert not get_config_path_from_options('.', {}, environment)
|
||||||
|
|
||||||
|
def test_unicode_path_from_options(self):
|
||||||
|
paths = [b'\xe5\xb0\xb1\xe5\x90\x83\xe9\xa5\xad/docker-compose.yml']
|
||||||
|
opts = {'--file': paths}
|
||||||
|
environment = Environment.from_env_file('.')
|
||||||
|
assert get_config_path_from_options(
|
||||||
|
'.', opts, environment
|
||||||
|
) == ['就吃饭/docker-compose.yml']
|
||||||
|
|
||||||
|
@pytest.mark.skipif(six.PY3, reason='Env values in Python 3 are already Unicode')
|
||||||
|
def test_unicode_path_from_env(self):
|
||||||
|
with mock.patch.dict(os.environ):
|
||||||
|
os.environ['COMPOSE_FILE'] = b'\xe5\xb0\xb1\xe5\x90\x83\xe9\xa5\xad/docker-compose.yml'
|
||||||
|
environment = Environment.from_env_file('.')
|
||||||
|
assert get_config_path_from_options(
|
||||||
|
'.', {}, environment
|
||||||
|
) == ['就吃饭/docker-compose.yml']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user