Skip to content

Commit 2da2868

Browse files
authored
Properly package the canonicaljson module (#52)
Package canonicaljson as a proper module rather than a single-file module. The main motivation is to expose the py.typed marker file so other projects can use the typing annotations. I've decided to go with an src/ layout for the module's source rather than the solution proposed in #50 (comment) to avoid a repeat of matrix-org/matrix-python-common#23. Fixes #50
1 parent bbd0c70 commit 2da2868

File tree

11 files changed

+82
-92
lines changed

11 files changed

+82
-92
lines changed

.github/workflows/tests.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Tests
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
branches: ["main"]
5+
pull_request:
36

47
concurrency:
58
group: ${{ github.workflow }}-${{ github.ref }}

MANIFEST.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
include *.in
2-
include *.py
1+
prune .github
32
include *.md
4-
include LICENSE
53
include tox.ini
6-
include pyproject.toml
7-
prune .travis
8-
prune debian
4+
recursive-include tests *.py

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ show_error_codes = true
33
strict = true
44

55
files = ["."]
6-
exclude = "setup.py"
6+
7+
[build-system]
8+
requires = [
9+
"setuptools >= 35.0.2",
10+
"setuptools_scm >= 2.0.0, <3"
11+
]
12+
build-backend = "setuptools.build_meta"

releasing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Releasing python-canonicaljson
22
==============================
33

4-
* bump version in `canonicaljson.py`
4+
* bump version in `src/canonicaljson/__init__.py`
55
* update changelog
66
* Build and upload to pypi:
77
* `rm -r dist`
8-
* `python setup.py sdist bdist_wheel`
8+
* `python -m build`
99
* `twine upload -s dist/*`
1010
* `git tag -s v<ver>`
1111
* `git push`

setup.cfg

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1+
[metadata]
2+
name = canonicaljson
3+
description = Canonical JSON
4+
long_description = file: README.rst
5+
long_description_content_type = text/x-rst
6+
version = attr: canonicaljson.__version__
7+
keywords = json
8+
url = https://github.com/matrix-org/python-canonicaljson
9+
license = Apache License, Version 2.0
10+
author = Matrix.org Team and Contributors
11+
author_email = [email protected]
12+
license_file = LICENSE
13+
classifiers =
14+
Development Status :: 5 - Production/Stable
15+
Intended Audience :: Developers
16+
License :: OSI Approved :: Apache Software License
17+
Programming Language :: Python :: 2
18+
Programming Language :: Python :: 3
19+
20+
21+
[options]
22+
zip_safe = true
23+
python_requires = >=3.7
24+
25+
package_dir = =src
26+
packages =
27+
canonicaljson
28+
29+
install_requires =
30+
# simplejson versions before 3.14.0 had a bug with some characters
31+
# (e.g. \u2028) if ensure_ascii was set to false.
32+
simplejson>=3.14.0
33+
# typing.Protocol was only added to the stdlib in Python 3.8
34+
typing_extensions>=4.0.0; python_version < '3.8'
35+
36+
37+
[options.extras_require]
38+
# frozendict support can be enabled using the `canonicaljson[frozendict]` syntax
39+
frozendict =
40+
frozendict>=1.0
41+
42+
43+
[options.package_data]
44+
canonicaljson = py.typed
45+
46+
147
[flake8]
248
# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
349
# for error codes. The ones we ignore are:

setup.py

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

canonicaljson.py renamed to src/canonicaljson/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# -*- coding: utf-8 -*-
2-
31
# Copyright 2014 OpenMarket Ltd
42
# Copyright 2018 New Vector Ltd
3+
# Copyright 2022 The Matrix.org Foundation C.I.C.
54
#
65
# Licensed under the Apache License, Version 2.0 (the "License");
76
# you may not use this file except in compliance with the License.

src/canonicaljson/py.typed

Whitespace-only changes.

tests/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2022 The Matrix.org Foundation C.I.C.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

test_canonicaljson.py renamed to tests/test_canonicaljson.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Copyright 2015 OpenMarket Ltd
42
# Copyright 2018 New Vector Ltd
3+
# Copyright 2022 The Matrix.org Foundation C.I.C.
54
#
65
# Licensed under the Apache License, Version 2.0 (the "License");
76
# you may not use this file except in compliance with the License.

tox.ini

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[tox]
22
envlist = packaging, pep8, black, py37, py38, py39, py310, pypy3
3+
isolated_build = True
34

4-
[testenv]
5+
[testenv:py]
56
deps =
67
coverage
78
nose2
@@ -19,20 +20,21 @@ commands = check-manifest
1920
basepython = python3.7
2021
deps =
2122
flake8
22-
commands = flake8 .
23+
commands = flake8 src tests
2324

2425
[testenv:black]
2526
basepython = python3.7
2627
deps =
2728
black==21.9b0
2829
# Workaround black+click incompatability, see https://github.com/psf/black/issues/2964
2930
click==8.0.4
30-
commands = python -m black --check --diff .
31+
commands = python -m black --check --diff src tests
3132

3233
[testenv:mypy]
3334
deps =
3435
mypy==0.942
3536
types-frozendict==2.0.8
3637
types-simplejson==3.17.5
3738
types-setuptools==57.4.14
38-
commands = mypy
39+
commands = mypy src tests
40+

0 commit comments

Comments
 (0)