Skip to content

Commit

Permalink
Python 3.12 compatibility (#164)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
howroyd committed Feb 11, 2024
1 parent f88b6cb commit 802bfb6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/ci.yml
Expand Up @@ -14,24 +14,20 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ["3"]
os: ["ubuntu-latest"]
include:
- {python: "3.8", os: "ubuntu-22.04"}
- {python: "3.9", os: "ubuntu-22.04"}
- {python: "3.10", os: "ubuntu-22.04"}
- {python: "3.11", os: "ubuntu-22.04"}
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
python -m pip install flake8
python -m pip install setuptools wheel
python -m pip install importlib_metadata
- name: Lint with flake8
run: |
Expand All @@ -41,7 +37,7 @@ jobs:
- name: Build and test
run: |
python setup.py sdist --formats=zip
pip install dist/pynmea2*.zip
pip install --find-links=./dist --no-index --no-build-isolation pynmea2
pytest
- name: Coveralls
env:
Expand Down
28 changes: 11 additions & 17 deletions README.md
@@ -1,32 +1,32 @@
pynmea2
=======
# pynmea2

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

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

The `pynmea2` homepage is located at http://github.com/Knio/pynmea2
The `pynmea2` homepage is located at <http://github.com/Knio/pynmea2>

### Compatibility
## Compatibility

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

![Python version](https://img.shields.io/pypi/pyversions/pynmea2.svg?style=flat)
[![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+)
[![Coverage status](https://img.shields.io/coveralls/github/Knio/pynmea2/master.svg?style=flat)](https://coveralls.io/r/Knio/pynmea2?branch=master)

### Installation
## Installation

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

pip install pynmea2
```bash
pip install pynmea2
```

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

Parsing
-------
## Parsing

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

Generating
----------
## Generating

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

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


and generate a NMEA string from a `NMEASentence` object:

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


File reading example
--------
## File reading example

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

Expand All @@ -129,9 +125,7 @@ for line in file.readlines():
continue
```


pySerial device example
---------
## `pySerial` device example

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

Expand Down
24 changes: 22 additions & 2 deletions setup.py
@@ -1,7 +1,24 @@
import importlib.machinery
import importlib.util

from setuptools import setup

import imp
_version = imp.load_source("pynmea2._version", "pynmea2/_version.py")

def load_source(modname, filename):
"""Load a source file and return its module object.
From: https://docs.python.org/3.12/whatsnew/3.12.html#imp
"""
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module

_version = load_source("pynmea2._version", "pynmea2/_version.py")

setup(
name='pynmea2',
Expand Down Expand Up @@ -29,6 +46,9 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Scientific/Engineering :: GIS',
'Topic :: Software Development :: Libraries :: Python Modules',
Expand Down

1 comment on commit 802bfb6

@kamiccolo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ufff, I believe with latest Py3 developments, python setup.py started doing weird things and produce strange wheels. It appears that pip install build && python -m build is the way (or one of the ways), also thinking of pip-tools.

Please sign in to comment.