From 2d2710bbded7b2568a0c2ec105f532274f63b91d Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Fri, 23 Sep 2022 13:58:26 +0100 Subject: [PATCH 1/8] Properly package the canonicaljson module --- MANIFEST.in | 12 +-- pyproject.toml | 8 +- releasing.md | 4 +- setup.cfg | 41 ++++++++++ setup.py | 74 ------------------- .../canonicaljson/__init__.py | 3 +- src/canonicaljson/py.typed | 0 tests/__init__.py | 13 ++++ .../test_canonicaljson.py | 3 +- tox.ini | 12 ++- 10 files changed, 77 insertions(+), 93 deletions(-) delete mode 100755 setup.py rename canonicaljson.py => src/canonicaljson/__init__.py (98%) create mode 100644 src/canonicaljson/py.typed create mode 100644 tests/__init__.py rename test_canonicaljson.py => tests/test_canonicaljson.py (99%) diff --git a/MANIFEST.in b/MANIFEST.in index 63f6c5b..7412947 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,8 +1,4 @@ -include *.in -include *.py -include *.md -include LICENSE -include tox.ini -include pyproject.toml -prune .travis -prune debian +prune .github + +# Include tests in the source distribution +recursive-include tests *.py \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index bd1d867..688a9b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,4 +3,10 @@ show_error_codes = true strict = true files = ["."] -exclude = "setup.py" + +[build-system] +requires = [ + "setuptools >= 35.0.2", + "setuptools_scm >= 2.0.0, <3" +] +build-backend = "setuptools.build_meta" diff --git a/releasing.md b/releasing.md index 73cb3ed..2aa58c1 100644 --- a/releasing.md +++ b/releasing.md @@ -1,11 +1,11 @@ Releasing python-canonicaljson ============================== -* bump version in `canonicaljson.py` +* bump version in `canonicaljson/__init__.py` * update changelog * Build and upload to pypi: * `rm -r dist` - * `python setup.py sdist bdist_wheel` + * `python -m build` * `twine upload -s dist/*` * `git tag -s v` * `git push` diff --git a/setup.cfg b/setup.cfg index ab09830..68c8c5d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,44 @@ +[metadata] +name = canonicaljson +description = Canonical JSON +long_description = file: README.rst +long_description_content_type = text/x-rst +version = attr: canonicaljson.__version__ +keywords = json +url = https://github.com/matrix-org/python-canonicaljson +license = Apache License, Version 2.0 +author = The Matrix.org Team +author_email = team@matrix.org +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + License :: OSI Approved :: Apache Software License + Programming Language :: Python :: 2 + Programming Language :: Python :: 3 + + +[options] +zip_safe = true +python_requires = >=3.7 + +package_dir = =src +packages = + canonicaljson + +install_requires = + # simplejson versions before 3.14.0 had a bug with some characters + # (e.g. \u2028) if ensure_ascii was set to false. + simplejson>=3.14.0 + # typing.Protocol was only added to the stdlib in Python 3.8 + typing_extensions>=4.0.0; python_version < '3.8' + + +[options.extras_require] +# frozendict support can be enabled using the `canonicaljson[frozendict]` syntax +frozendict = + frozendict>=1.0 + + [flake8] # see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes # for error codes. The ones we ignore are: diff --git a/setup.py b/setup.py deleted file mode 100755 index fec43db..0000000 --- a/setup.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2015 OpenMarket Ltd -# Copyright 2018 New Vector Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from setuptools import setup -from codecs import open -import os - -here = os.path.abspath(os.path.dirname(__file__)) - - -def read_file(path_segments): - """Read a UTF-8 file from the package. Takes a list of strings to join to - make the path""" - file_path = os.path.join(here, *path_segments) - with open(file_path, encoding="utf-8") as f: - return f.read() - - -def exec_file(path_segments, name): - """Extract a constant from a python file by looking for a line defining - the constant and executing it.""" - result = {} - code = read_file(path_segments) - lines = [line for line in code.split("\n") if line.startswith(name)] - exec("\n".join(lines), result) - return result[name] - - -setup( - name="canonicaljson", - version=exec_file(("canonicaljson.py",), "__version__"), - py_modules=["canonicaljson"], - description="Canonical JSON", - install_requires=[ - # simplerjson versions before 3.14.0 had a bug with some characters - # (e.g. \u2028) if ensure_ascii was set to false. - "simplejson>=3.14.0", - # typing.Protocol was only added to the stdlib in Python 3.8 - "typing_extensions>=4.0.0; python_version < '3.8'", - ], - extras_require={ - # frozendict support can be enabled using the `canonicaljson[frozendict]` syntax - "frozendict": ["frozendict>=1.0"], - }, - zip_safe=True, - long_description=read_file(("README.rst",)), - keywords="json", - author="The Matrix.org Team", - author_email="team@matrix.org", - url="https://github.com/matrix-org/python-canonicaljson", - license="Apache License, Version 2.0", - python_requires="~=3.7", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 3", - ], -) diff --git a/canonicaljson.py b/src/canonicaljson/__init__.py similarity index 98% rename from canonicaljson.py rename to src/canonicaljson/__init__.py index a2d8148..eb0ef85 100644 --- a/canonicaljson.py +++ b/src/canonicaljson/__init__.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- - # Copyright 2014 OpenMarket Ltd # Copyright 2018 New Vector Ltd +# Copyright 2022 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/canonicaljson/py.typed b/src/canonicaljson/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..3a5f22c --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2022 The Matrix.org Foundation C.I.C. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/test_canonicaljson.py b/tests/test_canonicaljson.py similarity index 99% rename from test_canonicaljson.py rename to tests/test_canonicaljson.py index fc19922..f1fac9a 100644 --- a/test_canonicaljson.py +++ b/tests/test_canonicaljson.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- -# # Copyright 2015 OpenMarket Ltd # Copyright 2018 New Vector Ltd +# Copyright 2022 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tox.ini b/tox.ini index 00ae34c..1457c49 100644 --- a/tox.ini +++ b/tox.ini @@ -1,14 +1,17 @@ [tox] envlist = packaging, pep8, black, py37, py38, py39, py310, pypy3 +isolated_build = True -[testenv] +[testenv:py] deps = coverage nose2 + pytest commands = coverage run --source canonicaljson -m nose2 coverage report -m --fail-under 100 + pytest tests [testenv:packaging] deps = @@ -19,7 +22,7 @@ commands = check-manifest basepython = python3.7 deps = flake8 -commands = flake8 . +commands = flake8 src tests [testenv:black] basepython = python3.7 @@ -27,7 +30,7 @@ deps = black==21.9b0 # Workaround black+click incompatability, see https://github.com/psf/black/issues/2964 click==8.0.4 -commands = python -m black --check --diff . +commands = python -m black --check --diff src tests [testenv:mypy] deps = @@ -35,4 +38,5 @@ deps = types-frozendict==2.0.8 types-simplejson==3.17.5 types-setuptools==57.4.14 -commands = mypy +commands = mypy src tests + From 1e7d67c391b9f5eb6d0526e60a896116b7878aa9 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Fri, 23 Sep 2022 14:01:11 +0100 Subject: [PATCH 2/8] Fixup manifest --- MANIFEST.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index 7412947..e855d3b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,9 @@ prune .github +include *.md +include tox.ini + +# Make sure typing markers are included. +recursive-include src py.typed # Include tests in the source distribution recursive-include tests *.py \ No newline at end of file From c85a01e9923be0d129992ed50a6e40d183594d38 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Fri, 23 Sep 2022 14:13:42 +0100 Subject: [PATCH 3/8] Fix file path in doc --- releasing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasing.md b/releasing.md index 2aa58c1..e5871a6 100644 --- a/releasing.md +++ b/releasing.md @@ -1,7 +1,7 @@ Releasing python-canonicaljson ============================== -* bump version in `canonicaljson/__init__.py` +* bump version in `src/canonicaljson/__init__.py` * update changelog * Build and upload to pypi: * `rm -r dist` From 60b07c8c9160394204d548801be222dbe62b6c0a Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Fri, 23 Sep 2022 15:41:40 +0100 Subject: [PATCH 4/8] Only use one test runner --- tox.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/tox.ini b/tox.ini index 1457c49..bdbf91e 100644 --- a/tox.ini +++ b/tox.ini @@ -6,12 +6,10 @@ isolated_build = True deps = coverage nose2 - pytest commands = coverage run --source canonicaljson -m nose2 coverage report -m --fail-under 100 - pytest tests [testenv:packaging] deps = From e05f3cbc375a720f3ff239fa4b602ac85c8ff153 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Fri, 23 Sep 2022 15:42:06 +0100 Subject: [PATCH 5/8] Fix email address and include py.typed in wheel --- setup.cfg | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 68c8c5d..7c9ef4f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,8 +7,8 @@ version = attr: canonicaljson.__version__ keywords = json url = https://github.com/matrix-org/python-canonicaljson license = Apache License, Version 2.0 -author = The Matrix.org Team -author_email = team@matrix.org +author = Matrix.org Team and Contributors +author_email = packages@matrix.org classifiers = Development Status :: 5 - Production/Stable Intended Audience :: Developers @@ -39,6 +39,10 @@ frozendict = frozendict>=1.0 +[options.package_data] +canonicaljson = py.typed + + [flake8] # see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes # for error codes. The ones we ignore are: From 1a367daf385a1e4ec482b2f88b6c52006cafbe12 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Fri, 23 Sep 2022 15:46:18 +0100 Subject: [PATCH 6/8] Incorporate changes suggested by check-manifest --- MANIFEST.in | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index e855d3b..e7b07d4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,9 +1,4 @@ prune .github include *.md include tox.ini - -# Make sure typing markers are included. -recursive-include src py.typed - -# Include tests in the source distribution recursive-include tests *.py \ No newline at end of file From 339f8d6e79a6ca14a4995ed7f057fbbee6be5861 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Fri, 23 Sep 2022 15:48:54 +0100 Subject: [PATCH 7/8] Add license file to package metadata --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 7c9ef4f..4b707de 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,7 @@ url = https://github.com/matrix-org/python-canonicaljson license = Apache License, Version 2.0 author = Matrix.org Team and Contributors author_email = packages@matrix.org +license_file = LICENSE classifiers = Development Status :: 5 - Production/Stable Intended Audience :: Developers From e7af4edaf9b890823951076686544158be3c5224 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Fri, 23 Sep 2022 15:55:40 +0100 Subject: [PATCH 8/8] Only run CI on push for the main branch --- .github/workflows/tests.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c4bfa98..92c505a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,5 +1,8 @@ name: Tests -on: [push, pull_request] +on: + push: + branches: ["main"] + pull_request: concurrency: group: ${{ github.workflow }}-${{ github.ref }}