Skip to content

Commit 8dbca2b

Browse files
committedJan 10, 2025
Remove to_posix_path function and related tests
1 parent 047edfe commit 8dbca2b

File tree

2 files changed

+1
-53
lines changed

2 files changed

+1
-53
lines changed
 

‎samcli/local/docker/utils.py

-35
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
"""
44

55
import logging
6-
import os
7-
import pathlib
86
import platform
9-
import posixpath
107
import random
11-
import re
128
import socket
139

1410
import docker
@@ -20,37 +16,6 @@
2016
LOG = logging.getLogger(__name__)
2117

2218

23-
def to_posix_path(code_path):
24-
"""
25-
Change the code_path to be of unix-style if running on windows when supplied with an absolute windows path.
26-
27-
Parameters
28-
----------
29-
code_path : str
30-
Directory in the host operating system that should be mounted within the container.
31-
Returns
32-
-------
33-
str
34-
Posix equivalent of absolute windows style path.
35-
Examples
36-
--------
37-
>>> to_posix_path('/Users/UserName/sam-app')
38-
/Users/UserName/sam-app
39-
>>> to_posix_path('C:\\\\Users\\\\UserName\\\\AppData\\\\Local\\\\Temp\\\\mydir')
40-
/c/Users/UserName/AppData/Local/Temp/mydir
41-
"""
42-
43-
return (
44-
re.sub(
45-
"^([A-Za-z])+:",
46-
lambda match: posixpath.sep + match.group().replace(":", "").lower(),
47-
pathlib.PureWindowsPath(code_path).as_posix(),
48-
)
49-
if os.name == "nt"
50-
else code_path
51-
)
52-
53-
5419
def find_free_port(network_interface: str, start: int = 5000, end: int = 9000) -> int:
5520
"""
5621
Utility function which scans through a port range in a randomized manner

‎tests/unit/local/docker/test_utils.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,10 @@
88
from unittest.mock import patch, Mock
99

1010
from samcli.lib.utils.architecture import ARM64, InvalidArchitecture, X86_64
11-
from samcli.local.docker.utils import to_posix_path, find_free_port, get_rapid_name, get_docker_platform, get_image_arch
11+
from samcli.local.docker.utils import find_free_port, get_rapid_name, get_docker_platform, get_image_arch
1212
from samcli.local.docker.exceptions import NoFreePortsError
1313

1414

15-
class TestPosixPath(TestCase):
16-
def setUp(self):
17-
self.ntpath = "C:\\Users\\UserName\\AppData\\Local\\Temp\\temp1337"
18-
self.posixpath = "/c/Users/UserName/AppData/Local/Temp/temp1337"
19-
self.current_working_dir = os.getcwd()
20-
21-
@patch("samcli.local.docker.utils.os")
22-
def test_convert_posix_path_if_windows_style_path(self, mock_os):
23-
mock_os.name = "nt"
24-
self.assertEqual(self.posixpath, to_posix_path(self.ntpath))
25-
26-
@patch("samcli.local.docker.utils.os")
27-
def test_do_not_convert_posix_path(self, mock_os):
28-
mock_os.name = "posix"
29-
self.assertEqual(self.current_working_dir, to_posix_path(self.current_working_dir))
30-
31-
3215
class TestFreePorts(TestCase):
3316
@parameterized.expand([("0.0.0.0",), ("127.0.0.1",)])
3417
@patch("samcli.local.docker.utils.socket")

0 commit comments

Comments
 (0)
Failed to load comments.