Skip to content

Commit 158c27e

Browse files
fixed issue #391 (#396)
* fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391 * fixed issue #391
1 parent e1030a0 commit 158c27e

15 files changed

+3709
-2673
lines changed

.github/workflows/pylint.yml

+23-15
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,43 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
os: [ubuntu-latest, windows-latest]
17-
python-version: [3.7, 3.8, 3.9]
18-
exclude:
19-
- os: windows-latest
20-
python-version: 3.8
16+
os: [ubuntu-latest]
17+
python-version: [3.7.12, 3.8.12, 3.9.12]
2118

2219
steps:
2320
- uses: actions/checkout@v2
2421
- name: Set up Python ${{ matrix.python-version }}
2522
uses: actions/setup-python@v2
2623
with:
2724
python-version: ${{ matrix.python-version }}
25+
- name: Validate version
26+
run: |
27+
$pythonVersion = (python --version)
28+
if ("Python ${{ matrix.python-version }}" -ne "$pythonVersion"){
29+
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python-version }}"
30+
exit 1
31+
}
32+
$pythonVersion
33+
shell: pwsh
34+
2835
- name: Install dependencies
2936
run: |
30-
python -m pip install --upgrade pip
31-
pip install pylint
32-
pip install -r requirements.txt
33-
pip install -r development.txt
34-
pip install .
37+
sudo python -m pip install --upgrade pip
38+
sudo python -m pip install pylint
39+
sudo python -m pip install -r requirements.txt
40+
sudo python -m pip install -r development.txt
41+
sudo python setup.py install
3542
3643
- name: Analysing the code with pylint
3744
run: |
38-
pylint `ls -R|grep .py$|xargs`
45+
sudo find . -type f -name "*.py" | xargs pylint | grep .
3946
4047
- name: Run black tool
4148
run: |
42-
pip install -U black;
43-
black --check --exclude=docs/* .
49+
sudo python -m pip install -U black;
50+
sudo black --check --exclude="docs|build|tests|samples|venv" .
4451
45-
- name: Run unit tests
52+
- name: Run unit test
4653
run: |
47-
nosetests -v --with-coverage --cover-package=jnpr.jsnapy --cover-inclusive -a unit
54+
cd tests/unit
55+
sudo nosetests -v --with-coverage --cover-package=jnpr.jsnapy --cover-inclusive -a unit

lib/jnpr/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# All rights reserved.
44
#
55

6-
__import__('pkg_resources').declare_namespace(__name__)
6+
__import__("pkg_resources").declare_namespace(__name__)

lib/jnpr/jsnapy/__init__.py

+34-19
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,53 @@
1616
except NameError:
1717
FileNotFoundError = IOError
1818

19+
1920
class DirStore:
2021
custom_dir = None
2122

23+
2224
# Function added by @gcasella
2325
# To check if the user is currently running the installation inside of a virtual environment that was installed using the `python3 -m venv venv` command.
2426
def venv_check():
2527

26-
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
28+
if hasattr(sys, "real_prefix") or (
29+
hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix
30+
):
2731
return True
2832
else:
2933
return False
3034

31-
def get_config_location(file='jsnapy.cfg'):
35+
36+
def get_config_location(file="jsnapy.cfg"):
3237
p_locations = []
33-
if 'JSNAPY_HOME' in os.environ:
34-
p_locations = [os.environ['JSNAPY_HOME']]
38+
if "JSNAPY_HOME" in os.environ:
39+
p_locations = [os.environ["JSNAPY_HOME"]]
3540

3641
# Modified by @gcasella to use the function created on lines 22-29.
3742
if venv_check() is True:
38-
p_locations.extend([os.path.join(os.path.expanduser("~"), '.jsnapy'),
39-
os.path.join(sys.prefix, 'etc', 'jsnapy')])
40-
elif 'win32' in sys.platform:
4143
p_locations.extend(
42-
[os.path.join(os.path.expanduser("~"), '.jsnapy'),
43-
os.path.join(os.path.expanduser('~'), 'jsnapy')])
44+
[
45+
os.path.join(os.path.expanduser("~"), ".jsnapy"),
46+
os.path.join(sys.prefix, "etc", "jsnapy"),
47+
]
48+
)
49+
elif "win32" in sys.platform:
50+
p_locations.extend(
51+
[
52+
os.path.join(os.path.expanduser("~"), ".jsnapy"),
53+
os.path.join(os.path.expanduser("~"), "jsnapy"),
54+
]
55+
)
4456
else:
45-
p_locations.extend([os.path.join(os.path.expanduser("~"), '.jsnapy'),
46-
'/etc/jsnapy'])
57+
p_locations.extend(
58+
[os.path.join(os.path.expanduser("~"), ".jsnapy"), "/etc/jsnapy"]
59+
)
4760

4861
for loc in p_locations:
4962
possible_location = os.path.join(loc, file)
5063
if os.path.isfile(possible_location):
5164
return loc
52-
raise FileNotFoundError('Could not locate %s' % file)
65+
raise FileNotFoundError("Could not locate %s" % file)
5366

5467

5568
def get_path(section, value):
@@ -60,11 +73,13 @@ def get_path(section, value):
6073
# 'log_file_path': '/var/log/jsnapy'})
6174
custom_dir = DirStore.custom_dir
6275
if custom_dir:
63-
paths = {'config_file_path': '',
64-
'snapshot_path': 'snapshots',
65-
'test_file_path': 'testfiles'}
66-
if custom_dir.startswith('~/'):
67-
custom_dir = os.path.join(os.path.expanduser('~'), custom_dir[2:])
76+
paths = {
77+
"config_file_path": "",
78+
"snapshot_path": "snapshots",
79+
"test_file_path": "testfiles",
80+
}
81+
if custom_dir.startswith("~/"):
82+
custom_dir = os.path.join(os.path.expanduser("~"), custom_dir[2:])
6883
complete_paths = {}
6984
for p in paths:
7085
complete_paths[p] = os.path.join(custom_dir, paths[p])
@@ -73,8 +88,8 @@ def get_path(section, value):
7388
config = configparser.ConfigParser()
7489
config_location = get_config_location()
7590
if config_location is None:
76-
raise Exception('Config file not found')
77-
config_location = os.path.join(config_location, 'jsnapy.cfg')
91+
raise Exception("Config file not found")
92+
config_location = os.path.join(config_location, "jsnapy.cfg")
7893
config.read(config_location)
7994
path = config.get(section, value)
8095
return path

0 commit comments

Comments
 (0)