Skip to content

Commit a2c4f6e

Browse files
committed
meta
test skip non-linux importerror when nmcli not found
1 parent a53da2d commit a2c4f6e

File tree

8 files changed

+47
-32
lines changed

8 files changed

+47
-32
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 132
3+
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/

.travis.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ python:
1111

1212
matrix:
1313
include:
14+
- os: linux
15+
name: Integration install
16+
python: 3.7
17+
install:
18+
- python setup.py install
19+
- pip install mozloc[tests,full]
20+
script:
21+
- cd $HOME
22+
- python -m pytest $TRAVIS_BUILD_DIR/tests -r a -v
1423
- os: linux
1524
python: 3.7
1625
install: pip install -e .[tests,cov]
1726
script:
1827
- flake8
19-
- mypy . --ignore-missing-imports
20-
after_success:
21-
- pytest --cov
22-
- coveralls
23-
24-
install: pip install -e .[tests]
25-
26-
script: pytest -rsv
28+
- mypy .

LICENSE renamed to LICENSE.txt

File renamed without changes.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
[![Build Status](https://travis-ci.com/scivision/mozilla-location-wifi-python.svg?branch=master)](https://travis-ci.com/scivision/mozilla-location-wifi-python)
12
[![Python versions (PyPI)](https://img.shields.io/pypi/pyversions/mozilla-location-python.svg)](https://pypi.python.org/pypi/mozilla-location-python)
2-
[![Distribution format (PyPI)](https://img.shields.io/pypi/format/mozilla-location-python.svg)](https://pypi.python.org/pypi/mozilla-location-python)
33
[![PyPi Download stats](http://pepy.tech/badge/mozilla-location-python)](http://pepy.tech/project/mozilla-location-python)
44

55

66
# mozilla-location-python
77
Uses nmcli on Linux in a short, simple Mozilla Location Services with Wifi from Python.
88
Goal was to be as simple as possible.
99

10-
Note that a similar service with better accuracy is available from
10+
Note that a similar service with better accuracy is available from
1111
[Google](https://developers.google.com/maps/documentation/geolocation/intro).
1212
Let us know if you're interested.
1313

@@ -38,7 +38,7 @@ You can display your logged data in Google Earth or other KML value after conver
3838
with
3939

4040
pip install simplekml
41-
41+
4242
Note that your time MUST be in ISO 8601 format or some KML reading programs such as Google Earth will just show a blank file.
4343
E.g.
4444

mozloc/__init__.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
from io import StringIO
44
import pandas
55
import requests
6+
import shutil
67
from datetime import datetime
78
from time import sleep
89
from pathlib import Path
910
from typing import Dict, Any, Optional
10-
#
11+
12+
NMCLI = shutil.which('nmcli')
13+
if not NMCLI:
14+
raise ImportError('This program relies on NetworkManager via "nmcli"')
15+
1116
URL = 'https://location.services.mozilla.com/v1/geolocate?key=test'
12-
NMCMD = ['nmcli', '-g', 'SSID,BSSID,FREQ,SIGNAL', 'device', 'wifi'] # Debian stretch, Ubuntu 18.04
13-
NMLEG = ['nmcli', '-t', '-f', 'SSID,BSSID,FREQ,SIGNAL', 'device', 'wifi'] # ubuntu 16.04
14-
NMSCAN = ['nmcli', 'device', 'wifi', 'rescan']
17+
NMCMD = [NMCLI, '-g', 'SSID,BSSID,FREQ,SIGNAL', 'device', 'wifi'] # Debian stretch, Ubuntu 18.04
18+
NMLEG = [NMCLI, '-t', '-f', 'SSID,BSSID,FREQ,SIGNAL', 'device', 'wifi'] # ubuntu 16.04
19+
NMSCAN = [NMCLI, 'device', 'wifi', 'rescan']
1520
HEADER = 'time lat lon accuracy NumBSSIDs'
1621

1722
# %%
@@ -47,14 +52,10 @@ def logwifiloc(T: float, logfile: Path):
4752

4853
def nm_config_check():
4954
# %% check that NetworkManager CLI is available and WiFi is active
50-
try:
51-
ret = subprocess.check_output(['nmcli', '-t', 'radio', 'wifi'], universal_newlines=True, timeout=1.).strip().split(':')
52-
except FileNotFoundError:
53-
raise OSError('CUrrently this program relies on NetworkManager')
55+
ret = subprocess.check_output([NMCLI, '-t', 'radio', 'wifi'], universal_newlines=True, timeout=1.).strip().split(':')
5456

55-
assert 'enabled' in ret and 'disabled' not in ret, 'must enable WiFi, perhaps via nmcli radio wifi on'
56-
57-
# %%
57+
if 'enabled' not in ret and 'disabled' in ret:
58+
raise OSError('must enable WiFi, perhaps via nmcli radio wifi on')
5859

5960

6061
def get_nmcli() -> Optional[Dict[str, Any]]:

mypy.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[mypy]
2+
ignore_missing_imports = True
3+
strict_optional = False
4+
allow_redefinition = True
5+
show_error_context = False
6+
show_column_numbers = True

setup.cfg

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = mozilla-location-python
33
version = 0.5.1
44
author = Michael Hirsch, Ph.D.
5+
author_email = scivision@users.noreply.github.com
56
url = https://github.com/scivision/mozilla-location-wifi-python
67
description = Using Mozilla Location services, log location vs. time using WiFi or convert to KML.
78
keywords =
@@ -12,12 +13,14 @@ classifiers =
1213
Environment :: Console
1314
Intended Audience :: Information Technology
1415
Intended Audience :: System Administrators
15-
Operating System :: OS Independent
16+
Operating System :: POSIX :: Linux
1617
Programming Language :: Python :: 3.6
1718
Programming Language :: Python :: 3.7
19+
Programming Language :: Python :: 3.8
1820
Topic :: System :: Networking
1921
Topic :: Utilities
20-
license_file = LICENSE
22+
license_files =
23+
LICENSE.txt
2124
long_description = file: README.md
2225
long_description_content_type = text/markdown
2326

@@ -26,9 +29,10 @@ python_requires = >= 3.6
2629
setup_requires =
2730
setuptools >= 38.6
2831
pip >= 10
29-
twine >= 1.11
30-
include_package_data = True
3132
packages = find:
33+
scripts =
34+
csv2kml.py
35+
MozLoc.py
3236
install_requires =
3337
pandas
3438
requests
@@ -48,8 +52,3 @@ io =
4852
console_scripts =
4953
MozLoc = MozLoc:main
5054
csv2kml = csv2kml:main
51-
52-
53-
[flake8]
54-
max-line-length = 132
55-
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/

tests/test_all.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
#!/usr/bin/env python
22
import pytest
3-
import mozloc
43
import datetime
54
import subprocess
65

76

87
def test_nm_loc():
8+
mozloc = pytest.importorskip('mozloc')
9+
910
try:
1011
loc = mozloc.get_nmcli()
1112
except subprocess.CalledProcessError as e:
1213
pytest.xfail(f'problem with NMCLI API--old NMCLI version? {e}')
14+
1315
assert isinstance(loc, dict)
1416
assert isinstance(loc['t'], datetime.datetime)
1517

1618

1719
def test_nm_connection():
20+
mozloc = pytest.importorskip('mozloc')
21+
1822
try:
1923
mozloc.nm_config_check()
2024
except subprocess.CalledProcessError as e:

0 commit comments

Comments
 (0)