Skip to content

Commit dede6bf

Browse files
committed
Update packaging, drop use of "six"
1 parent 15baeb7 commit dede6bf

File tree

7 files changed

+127
-186
lines changed

7 files changed

+127
-186
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
name: ci
2+
23
on: [push, pull_request]
34

45
jobs:
5-
build:
6-
runs-on: ubuntu-22.04
6+
test:
7+
name: Install and test
8+
runs-on: ubuntu-latest
79
strategy:
810
fail-fast: false
911
matrix:
10-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
12+
python-version: ["3.10", "3.11", "3.12", "3.13"]
13+
1114
steps:
12-
- name: checkout
13-
uses: actions/checkout@v6
15+
- uses: actions/checkout@v6
16+
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v7
1419

15-
- uses: actions/setup-python@v6
16-
with:
17-
python-version: '${{ matrix.python-version }}'
20+
- name: Set up Python
21+
run: uv python install ${{ matrix.python-version }}
1822

19-
- name: Install dependencies
20-
run: |
21-
pip install six cachetools
23+
- name: Install the project
24+
run: uv sync --all-extras --dev
2225

23-
- name: Run tests
24-
run: |
25-
PYTHONPATH=$(pwd) python tests/__init__.py
26+
- name: Run unit tests
27+
run: uv run python -m unittest

airspeed/__init__.py

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import os
66
import string
77
import sys
8-
9-
import six
8+
from io import StringIO
109

1110
__all__ = [
1211
'Template',
@@ -43,34 +42,6 @@
4342
}
4443
}
4544

46-
try:
47-
dict
48-
except NameError:
49-
from UserDict import UserDict
50-
51-
class dict(UserDict):
52-
53-
def __init__(self):
54-
self.data = {}
55-
try:
56-
operator.__gt__
57-
except AttributeError:
58-
operator.__gt__ = lambda a, b: a > b
59-
operator.__lt__ = lambda a, b: a < b
60-
operator.__ge__ = lambda a, b: a >= b
61-
operator.__le__ = lambda a, b: a <= b
62-
operator.__eq__ = lambda a, b: a == b
63-
operator.__ne__ = lambda a, b: a != b
64-
operator.mod = lambda a, b: a % b
65-
try:
66-
basestring
67-
68-
def is_string(s):
69-
return isinstance(s, basestring)
70-
except NameError:
71-
def is_string(s):
72-
return isinstance(s, type(''))
73-
7445
###############################################################################
7546
# Public interface
7647
###############################################################################
@@ -113,19 +84,19 @@ class TemplateError(Exception):
11384

11485

11586
class TemplateExecutionError(TemplateError):
116-
def __init__(self, element, exc_info):
117-
cause, value, traceback = exc_info
118-
self.__cause__ = value
87+
"This exception will always have a __cause__ attached."
88+
def __init__(self, element):
11989
self.element = element
12090
self.start, self.end, self.filename = (element.start, element.end,
12191
element.filename)
122-
self.msg = "Error in template '%s' at position " \
123-
"%d-%d in expression: %s\n%s: %s" % \
124-
(self.filename, self.start, self.end,
125-
element.my_text(), cause.__name__, value)
12692

12793
def __str__(self):
128-
return self.msg
94+
return "Error in template '%s' at position " \
95+
"%d-%d in expression: %s\n%s: %s" % \
96+
(self.filename, self.start, self.end,
97+
self.element.my_text(),
98+
self.__cause__.__class__.__name__,
99+
self.__cause__)
129100

130101

131102
class TemplateSyntaxError(TemplateError):
@@ -207,14 +178,14 @@ def load_template(self, name):
207178
return template
208179

209180

210-
class StoppableStream(six.StringIO):
181+
class StoppableStream(StringIO):
211182
def __init__(self, buf=''):
212183
self.stop = False
213-
six.StringIO.__init__(self, buf)
184+
StringIO.__init__(self, buf)
214185

215186
def write(self, s):
216187
if not self.stop:
217-
six.StringIO.write(self, s)
188+
StringIO.write(self, s)
218189

219190

220191
###############################################################################
@@ -356,11 +327,9 @@ def evaluate(self, *args):
356327
return self.evaluate_raw(*args)
357328
except TemplateExecutionError:
358329
raise
359-
except:
360-
exc_info = sys.exc_info()
361-
six.reraise(TemplateExecutionError,
362-
TemplateExecutionError(self, exc_info), exc_info[2])
363-
330+
except Exception as e:
331+
_type, value, _tb = sys.exc_info()
332+
raise TemplateExecutionError(self) from e
364333

365334
class Text(_Element):
366335
PLAIN = re.compile(
@@ -621,7 +590,7 @@ def calculate(self, current_object, loader, top_namespace):
621590
# If list make sure index is an integer
622591
if isinstance(
623592
result, list) and not isinstance(
624-
array_index, six.integer_types):
593+
array_index, int):
625594
raise ValueError(
626595
"expected integer for array index, got '%s'" %
627596
(array_index))
@@ -714,8 +683,7 @@ def parse(self):
714683
self.require_match(self.END, ']')
715684

716685
def calculate(self, namespace, loader):
717-
result = self.index.calculate(namespace, loader)
718-
return result
686+
return self.index.calculate(namespace, loader)
719687

720688
class AlternateValue(_Element):
721689
START = re.compile(r'\|(.*)$', re.S)
@@ -757,10 +725,10 @@ def evaluate_raw(self, stream, namespace, loader):
757725
value = ''
758726
else:
759727
value = self.my_text()
760-
if is_string(value):
728+
if isinstance(value, str):
761729
stream.write(value)
762730
else:
763-
stream.write(six.text_type(value))
731+
stream.write(str(value))
764732

765733

766734
class Null:

flake.lock

Lines changed: 3 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,35 @@
33

44
inputs = {
55
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
6-
flake-utils.url = "github:numtide/flake-utils";
76
};
87

9-
outputs = { self, nixpkgs, flake-utils }@inputs:
10-
flake-utils.lib.eachDefaultSystem (system:
8+
outputs =
9+
{ self, nixpkgs }:
10+
(
1111
let
12-
pkgs = import nixpkgs { inherit system; };
12+
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.all;
1313
in
1414
{
15-
devShell = pkgs.mkShell {
16-
buildInputs = with pkgs; [
17-
(python3.withPackages (p: [ p.setuptools p.six p.build ]))
18-
twine pyright
19-
python3Packages.flake8
20-
python3Packages.pylint
21-
];
22-
};
15+
devShell = forAllSystems (
16+
system:
17+
let
18+
pkgs = import nixpkgs { inherit system; };
19+
in
20+
pkgs.mkShell {
21+
buildInputs = with pkgs; [
22+
(python3.withPackages (
23+
p: with p; [
24+
setuptools
25+
cachetools
26+
build
27+
coverage
28+
]
29+
))
30+
ty
31+
uv
32+
];
33+
}
34+
);
2335
}
2436
);
2537
}

pyproject.toml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
11
[build-system]
22
requires = ["setuptools"]
33
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "airspeed"
7+
authors = [
8+
{ name = "Steve Purcell", email = "steve@pythonconsulting.com" },
9+
{ name = "Chris Tarttelin" }
10+
]
11+
version = "0.6.1"
12+
description = "A Python framework for building HTTP-based server applications"
13+
dependencies = [
14+
"cachetools"
15+
]
16+
requires-python = ">=3.7"
17+
license = {file = "LICENCE"}
18+
classifiers = [
19+
"Development Status :: 5 - Production/Stable",
20+
"Environment :: Web Environment",
21+
"Intended Audience :: Developers",
22+
"License :: OSI Approved :: BSD License",
23+
"Operating System :: OS Independent",
24+
"Programming Language :: Python",
25+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
26+
"Topic :: Software Development :: Libraries :: Python Modules",
27+
"Programming Language :: Python :: 3.7",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3.9",
30+
"Programming Language :: Python :: 3.10",
31+
"Programming Language :: Python :: 3.11",
32+
"Programming Language :: Python :: 3.12",
33+
"Programming Language :: Python :: 3.13"
34+
]
35+
dynamic = ["readme"]
36+
37+
38+
[project.optional-dependencies]
39+
dev = [
40+
]
41+
42+
[tool.setuptools]
43+
include-package-data = false
44+
45+
[tool.setuptools.dynamic]
46+
readme = {file = ["README.md"], content-type = "text/markdown"}
47+
48+
[tool.setuptools.packages.find]
49+
include = ["airspeed*"]
50+
exclude = ["tests*", "examples"]
51+
52+
[tool.setuptools.package-data]
53+
"*" = ["*.md"]
54+
55+
[tool.coverage.report]
56+
exclude_lines = [
57+
"if __name__ == .__main__.:",
58+
"raise NotImplemented.",
59+
"return NotImplemented",
60+
"def __repr__",
61+
"__all__",
62+
]

setup.cfg

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)