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 }} diff --git a/MANIFEST.in b/MANIFEST.in index 63f6c5b..e7b07d4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,8 +1,4 @@ -include *.in -include *.py +prune .github include *.md -include LICENSE include tox.ini -include pyproject.toml -prune .travis -prune debian +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..e5871a6 100644 --- a/releasing.md +++ b/releasing.md @@ -1,11 +1,11 @@ Releasing python-canonicaljson ============================== -* bump version in `canonicaljson.py` +* bump version in `src/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..4b707de 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,49 @@ +[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 = Matrix.org Team and Contributors +author_email = packages@matrix.org +license_file = LICENSE +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 + + +[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: 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..bdbf91e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,8 @@ [tox] envlist = packaging, pep8, black, py37, py38, py39, py310, pypy3 +isolated_build = True -[testenv] +[testenv:py] deps = coverage nose2 @@ -19,7 +20,7 @@ commands = check-manifest basepython = python3.7 deps = flake8 -commands = flake8 . +commands = flake8 src tests [testenv:black] basepython = python3.7 @@ -27,7 +28,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 +36,5 @@ deps = types-frozendict==2.0.8 types-simplejson==3.17.5 types-setuptools==57.4.14 -commands = mypy +commands = mypy src tests +