Skip to content

Commit 9b4e7e5

Browse files
committed
fix ssh config file not found
1 parent 969dec9 commit 9b4e7e5

File tree

5 files changed

+87
-60
lines changed

5 files changed

+87
-60
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: [3.6, 3.7, 3.8, 3.9]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install flake8 pytest
30+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31+
- name: Lint with flake8
32+
run: |
33+
# stop the build if there are Python syntax errors or undefined names
34+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
35+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
36+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37+
- name: Test with pytest
38+
run: |
39+
pytest
40+
41+
# This workflow will upload a Python Package using Twine when a release is created
42+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
43+
44+
name: Upload Python Package
45+
46+
on:
47+
release:
48+
types: [created]
49+
50+
jobs:
51+
deploy:
52+
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- uses: actions/checkout@v2
57+
- name: Set up Python
58+
uses: actions/setup-python@v2
59+
with:
60+
python-version: '3.x'
61+
- name: Install dependencies
62+
run: |
63+
python -m pip install --upgrade pip
64+
pip install setuptools wheel twine
65+
- name: Build and publish
66+
env:
67+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
68+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
69+
run: |
70+
python setup.py sdist bdist_wheel
71+
twine upload dist/*

ssh_utilities/utils.py

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
from paramiko.config import SSHConfig
1111
from tqdm import tqdm
1212
from tqdm.utils import _term_move_up
13+
from fnmatch import translate
1314

1415
from .exceptions import CalledProcessError
1516

1617
if TYPE_CHECKING:
1718
from .typeshed import _CMD
1819

1920
__all__ = ["ProgressBar", "bytes_2_human_readable", "CompletedProcess",
20-
"lprint", "for_all_methods", "glob2re", "file_filter",
21-
"config_parser", "context_timeit", "NullContext"]
21+
"lprint", "for_all_methods", "file_filter", "config_parser",
22+
"context_timeit", "NullContext"]
2223

2324

2425
_CompletedProcess = TypeVar("_CompletedProcess", str, bytes)
@@ -253,14 +254,14 @@ class file_filter:
253254
def __init__(self, include: Optional[str], exclude: Optional[str]) -> None:
254255

255256
if include and exclude:
256-
self._inc = re.compile(glob2re(include))
257-
self._exc = re.compile(glob2re(exclude))
257+
self._inc = re.compile(translate(include))
258+
self._exc = re.compile(translate(exclude))
258259
self.match = self._match_both
259260
elif include and not exclude:
260-
self._inc = re.compile(glob2re(include))
261+
self._inc = re.compile(translate(include))
261262
self.match = self._match_inc
262263
elif not include and exclude:
263-
self._exc = re.compile(glob2re(exclude))
264+
self._exc = re.compile(translate(exclude))
264265
self.match = self._match_exc
265266
elif not include and not exclude:
266267
self.match = self._match_none
@@ -287,52 +288,6 @@ def __call__(self, filename: str) -> bool:
287288
return self.match(filename)
288289

289290

290-
def glob2re(patern): # NOSONAR
291-
"""Translate a shell PATTERN to a regular expression.
292-
293-
There is no way to quote meta-characters.
294-
295-
Parameters
296-
----------
297-
patern: str
298-
shell glob pattern
299-
300-
References
301-
----------
302-
https://stackoverflow.com/questions/27726545/python-glob-but-against-a-list-of-strings-rather-than-the-filesystem
303-
"""
304-
i, n = 0, len(patern)
305-
res = ''
306-
while i < n:
307-
c = patern[i]
308-
i += 1
309-
if c == '*':
310-
res = res + '.*'
311-
elif c == '?':
312-
res = res + '.'
313-
elif c == '[':
314-
j = i
315-
if j < n and patern[j] == '!':
316-
j += 1
317-
if j < n and patern[j] == ']':
318-
j += 1
319-
while j < n and patern[j] != ']':
320-
j += 1
321-
if j >= n:
322-
res += '\\['
323-
else:
324-
stuff = patern[i:j].replace('\\', '\\\\')
325-
i = j + 1
326-
if stuff[0] == '!':
327-
stuff = '^' + stuff[1:]
328-
elif stuff[0] == '^':
329-
stuff = '\\' + stuff
330-
res = '%s[%s]' % (res, stuff)
331-
else:
332-
res = res + re.escape(c)
333-
return '(?ms)' + res + '\Z' # noqa
334-
335-
336291
def config_parser(config_path: Union["Path", str]) -> SSHConfig:
337292
"""Parses ssh config file.
338293
@@ -350,7 +305,10 @@ def config_parser(config_path: Union["Path", str]) -> SSHConfig:
350305
config_path = Path(config_path).expanduser()
351306

352307
config = SSHConfig()
353-
config.parse(config_path.open())
308+
try:
309+
config.parse(config_path.open())
310+
except FileNotFoundError:
311+
pass
354312

355313
return config
356314

ssh_utilities/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.7.0"
1+
__version__ = "0.7.1"

tests/test_local_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"""
88

99
import logging
10-
import sys
11-
from unittest import TestCase, main
1210
import os
11+
import sys
1312
from pathlib import Path
13+
from unittest import TestCase, main
1414

1515
from ssh_utilities import Connection
1616

tests/test_ssh_path.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
"""
1212

1313
import logging
14-
from ssh_utilities.constants import CONFIG_PATH
15-
import sys
16-
from unittest import TestCase, main
1714
import os
15+
import sys
1816
from pathlib import Path
19-
import subprocess
17+
from unittest import TestCase, main
2018

2119
from ssh_utilities import Connection
2220

0 commit comments

Comments
 (0)