Skip to content

Commit 802bfb6

Browse files
authored
Python 3.12 compatibility (#164)
* Removed depreciated `imp` and replaced with `importlib` * Updated meta classifiers to include newer Python versions * Added Python3.12 into github workflow action * Updated workflow to test all versions we say we do * Tidied mixed markup styles * Assed Windows and MacOS to tests * Updated depreciated setup-python action to v5 * Adding Python3.12 to Action * Removed my test branch from Actions
1 parent f88b6cb commit 802bfb6

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,20 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
python: ["3"]
18-
os: ["ubuntu-latest"]
19-
include:
20-
- {python: "3.8", os: "ubuntu-22.04"}
21-
- {python: "3.9", os: "ubuntu-22.04"}
22-
- {python: "3.10", os: "ubuntu-22.04"}
23-
- {python: "3.11", os: "ubuntu-22.04"}
17+
os: [ubuntu-latest, windows-latest, macos-latest]
18+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
2419
steps:
25-
- uses: actions/checkout@v3
26-
- name: Set up Python ${{ matrix.python }}
27-
uses: actions/setup-python@v3
20+
- uses: actions/checkout@v4
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v5
2823
with:
29-
python-version: ${{ matrix.python }}
24+
python-version: ${{ matrix.python-version }}
3025
- name: Install dependencies
3126
run: |
3227
python -m pip install --upgrade pip
3328
python -m pip install pytest
3429
python -m pip install flake8
30+
python -m pip install setuptools wheel
3531
python -m pip install importlib_metadata
3632
- name: Lint with flake8
3733
run: |
@@ -41,7 +37,7 @@ jobs:
4137
- name: Build and test
4238
run: |
4339
python setup.py sdist --formats=zip
44-
pip install dist/pynmea2*.zip
40+
pip install --find-links=./dist --no-index --no-build-isolation pynmea2
4541
pytest
4642
- name: Coveralls
4743
env:

README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
pynmea2
2-
=======
1+
# pynmea2
32

43
`pynmea2` is a python library for the [NMEA 0183](http://en.wikipedia.org/wiki/NMEA_0183) protocol
54

65
`pynmea2` is based on [`pynmea`](https://code.google.com/p/pynmea/) by Becky Lewis
76

8-
The `pynmea2` homepage is located at http://github.com/Knio/pynmea2
7+
The `pynmea2` homepage is located at <http://github.com/Knio/pynmea2>
98

10-
### Compatibility
9+
## Compatibility
1110

1211
`pynmea2` is compatable with Python 2.7 and Python 3.4+
1312

1413
![Python version](https://img.shields.io/pypi/pyversions/pynmea2.svg?style=flat)
1514
[![Build status](https://github.com/Knio/pynmea2/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Knio/pynmea2/actions/workflows/ci.yml?query=branch%3Amaster+)
1615
[![Coverage status](https://img.shields.io/coveralls/github/Knio/pynmea2/master.svg?style=flat)](https://coveralls.io/r/Knio/pynmea2?branch=master)
1716

18-
### Installation
17+
## Installation
1918

2019
The recommended way to install `pynmea2` is with
2120
[pip](http://pypi.python.org/pypi/pip/):
2221

23-
pip install pynmea2
22+
```bash
23+
pip install pynmea2
24+
```
2425

2526
[![PyPI version](https://img.shields.io/pypi/v/pynmea2.svg?style=flat)](https://pypi.org/project/pynmea2/)
2627
[![PyPI downloads](https://img.shields.io/pypi/dm/pynmea2.svg?style=flat)](https://pypi.org/project/pynmea2/)
2728

28-
Parsing
29-
-------
29+
## Parsing
3030

3131
You can parse individual NMEA sentences using the `parse(data, check=False)` function, which takes a string containing a
3232
NMEA 0183 sentence and returns a `NMEASentence` object. Note that the leading '$' is optional and trailing whitespace is ignored when parsing a sentence.
@@ -91,8 +91,7 @@ For example, `latitude` and `longitude` properties exist as helpers to access th
9191
"-19°29′02.7000″"
9292
```
9393

94-
Generating
95-
----------
94+
## Generating
9695

9796
You can create a `NMEASentence` object by calling the constructor with talker, message type, and data fields:
9897

@@ -101,17 +100,14 @@ You can create a `NMEASentence` object by calling the constructor with talker, m
101100
>>> msg = pynmea2.GGA('GP', 'GGA', ('184353.07', '1929.045', 'S', '02410.506', 'E', '1', '04', '2.6', '100.00', 'M', '-33.9', 'M', '', '0000'))
102101
```
103102

104-
105103
and generate a NMEA string from a `NMEASentence` object:
106104

107105
```python
108106
>>> str(msg)
109107
'$GPGGA,184353.07,1929.045,S,02410.506,E,1,04,2.6,100.00,M,-33.9,M,,0000*6D'
110108
```
111109

112-
113-
File reading example
114-
--------
110+
## File reading example
115111

116112
See [examples/read_file.py](/examples/read_file.py)
117113

@@ -129,9 +125,7 @@ for line in file.readlines():
129125
continue
130126
```
131127

132-
133-
pySerial device example
134-
---------
128+
## `pySerial` device example
135129

136130
See [examples/read_serial.py](/examples/read_serial.py)
137131

setup.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
import importlib.machinery
2+
import importlib.util
3+
14
from setuptools import setup
25

3-
import imp
4-
_version = imp.load_source("pynmea2._version", "pynmea2/_version.py")
6+
7+
def load_source(modname, filename):
8+
"""Load a source file and return its module object.
9+
10+
From: https://docs.python.org/3.12/whatsnew/3.12.html#imp
11+
"""
12+
loader = importlib.machinery.SourceFileLoader(modname, filename)
13+
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
14+
module = importlib.util.module_from_spec(spec)
15+
# The module is always executed and not cached in sys.modules.
16+
# Uncomment the following line to cache the module.
17+
# sys.modules[module.__name__] = module
18+
loader.exec_module(module)
19+
return module
20+
21+
_version = load_source("pynmea2._version", "pynmea2/_version.py")
522

623
setup(
724
name='pynmea2',
@@ -29,6 +46,9 @@
2946
'Programming Language :: Python :: 3.7',
3047
'Programming Language :: Python :: 3.8',
3148
'Programming Language :: Python :: 3.9',
49+
'Programming Language :: Python :: 3.10',
50+
'Programming Language :: Python :: 3.11',
51+
'Programming Language :: Python :: 3.12',
3252
'Programming Language :: Python :: Implementation :: PyPy',
3353
'Topic :: Scientific/Engineering :: GIS',
3454
'Topic :: Software Development :: Libraries :: Python Modules',

0 commit comments

Comments
 (0)