Skip to content

Commit 2d601bb

Browse files
authored
Merge pull request #35 from ChannelFinder/pre-commit-ruff
Modernize: Add pre-commit, ruff linting and formatting, remove python 2 support
2 parents 7f2979f + dcb548d commit 2d601bb

23 files changed

+2934
-1871
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,41 @@
33

44
name: Python package
55

6-
on:
7-
push:
8-
branches: [ "master" ]
9-
pull_request:
10-
branches: [ "master" ]
6+
on: [push, pull_request]
117

128
jobs:
13-
test:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v3
14+
- uses: pre-commit/[email protected]
15+
build:
1416

15-
runs-on: ubuntu-20.04
17+
runs-on: ubuntu-20.04 # 3.6 is not supported by Ubuntu 22.04
1618
strategy:
1719
fail-fast: false
1820
matrix:
19-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
21+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
2022

23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
python -m pip install .
33+
test:
34+
35+
runs-on: ubuntu-latest
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] # testcontainers is not supported on <3.9
40+
needs: build
2141
steps:
2242
- uses: actions/checkout@v4
2343
- name: Set up Python ${{ matrix.python-version }}
@@ -34,4 +54,4 @@ jobs:
3454
run: docker image prune -af
3555
- name: Test with pytest
3656
run: |
37-
python -m unittest discover -v -s test -p "test*.py"
57+
python -m unittest discover -v -s test -p "test*.py"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
*.pyc
33
build/
44
*.egg-info/
5-
.vscode
5+
.vscode

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
# Ruff version.
9+
rev: v0.9.0
10+
hooks:
11+
# Run the linter.
12+
- id: ruff
13+
args: [ --fix ]
14+
# Run the formatter.
15+
- id: ruff-format

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ A python client library for ChannelFinder.
66

77
The python channelfinder client library can be configured by setting up a `channelfinderapi.conf` file in the following locations
88

9-
`/etc/channelfinderapi.conf`
10-
`~/.channelfinderapi.conf`
11-
`channelfinderapi.conf`
9+
`/etc/channelfinderapi.conf`
10+
`~/.channelfinderapi.conf`
11+
`channelfinderapi.conf`
1212

13-
The example preferences:
13+
The example preferences:
1414

1515
```
16-
cat ~/channelfinderapi.conf
17-
[DEFAULT]
18-
BaseURL=http://localhost:8080/ChannelFinder
19-
username=MyUserName
20-
password=MyPassword
16+
cat ~/channelfinderapi.conf
17+
[DEFAULT]
18+
BaseURL=http://localhost:8080/ChannelFinder
19+
username=MyUserName
20+
password=MyPassword
2121
```
22-
22+
2323
## Development
2424

2525
To install with dependancies for testing.
@@ -38,4 +38,4 @@ To run all tests:
3838

3939
```bash
4040
python -m unittest discover -v -s test -p "test*.py"
41-
```
41+
```

channelfinder/CFDataTypes.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@
1010
"""
1111

1212

13-
from ._conf import PYTHON3
14-
15-
if PYTHON3:
16-
# cmp function is gone in Python 3.
17-
# Define for backward compatibility
18-
def cmp(a, b):
19-
return (a > b) - (a < b)
13+
def cmp(a, b):
14+
return (a > b) - (a < b)
2015

2116

2217
class Channel(object):
2318
# TODO
2419
# updated the properties data structure by splitting it into 2 dict
25-
20+
2621
# All the attributes are private and read only in an attempt to make the channel object immutable
2722
Name = property(lambda self: self.__Name)
2823
Owner = property(lambda self: self.__Owner)
@@ -42,7 +37,7 @@ def __init__(self, name, owner, properties=None, tags=None):
4237
self.__Owner = str(owner).strip()
4338
self.Properties = properties
4439
self.Tags = tags
45-
40+
4641
## TODO don't recreate the dictionary with every get
4742
def getProperties(self):
4843
"""
@@ -85,10 +80,10 @@ def __init__(self, name, owner, value=None):
8580
self.Value = value
8681
if self.Value:
8782
str(value).strip()
88-
89-
def __cmp__(self, *arg, **kwargs):
83+
84+
def __cmp__(self, *arg, **kwargs):
9085
if arg[0] is None:
91-
return 1
86+
return 1
9287
return cmp((self.Name, self.Value), (arg[0].Name, arg[0].Value))
9388

9489

@@ -99,7 +94,7 @@ def __init__(self, name, owner):
9994
"""
10095
self.Name = str(name).strip()
10196
self.Owner = str(owner).strip()
102-
97+
10398
def __cmp__(self, *arg, **kwargs):
10499
if arg[0] is None:
105100
return 1

0 commit comments

Comments
 (0)