From 98155d3ce8e22e802b5a47d68092fd17b218eac1 Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Sun, 2 Jan 2022 17:33:46 +0300 Subject: [PATCH] Moved the metadata into `setup.cfg`. Added `pyproject.toml`. Version is now fetched and populated automatically from git tags using setuptools_scm. Metadata stored in source files is fetched using `read_version`. Got rid of raw scripts, using `console_scripts` entry point since now. --- .gitignore | 3 +- jsonpatch.py => jsonpatch/__init__.py | 4 +- jsonpatch/cli/__init__.py | 0 bin/jsondiff => jsonpatch/cli/jsondiff.py | 7 +- bin/jsonpatch => jsonpatch/cli/jsonpatch.py | 7 +- pyproject.toml | 13 +++ setup.cfg | 42 ++++++++++ setup.py | 93 --------------------- 8 files changed, 68 insertions(+), 101 deletions(-) rename jsonpatch.py => jsonpatch/__init__.py (99%) create mode 100644 jsonpatch/cli/__init__.py rename bin/jsondiff => jsonpatch/cli/jsondiff.py (87%) rename bin/jsonpatch => jsonpatch/cli/jsonpatch.py (96%) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 179770e..18db948 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -*.pyc +/jsonpatch/version.py +*.py[co] build .coverage dist diff --git a/jsonpatch.py b/jsonpatch/__init__.py similarity index 99% rename from jsonpatch.py rename to jsonpatch/__init__.py index a4bd519..d798a6d 100644 --- a/jsonpatch.py +++ b/jsonpatch/__init__.py @@ -66,7 +66,9 @@ str = unicode # Will be parsed by setup.py to determine package metadata -__author__ = 'Stefan Kögl ' +__author__ = 'Stefan Kögl' +__email__ = 'stefan@skoegl.net' +__author__ += ' <' + __email__ + '>' __version__ = '1.32' __website__ = 'https://github.com/stefankoegl/python-json-patch' __license__ = 'Modified BSD License' diff --git a/jsonpatch/cli/__init__.py b/jsonpatch/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bin/jsondiff b/jsonpatch/cli/jsondiff.py similarity index 87% rename from bin/jsondiff rename to jsonpatch/cli/jsondiff.py index b79188b..77d752d 100755 --- a/bin/jsondiff +++ b/jsonpatch/cli/jsondiff.py @@ -5,9 +5,10 @@ import sys import json -import jsonpatch import argparse +from .. import __version__, make_patch + parser = argparse.ArgumentParser(description='Diff two JSON files') parser.add_argument('FILE1', type=argparse.FileType('r')) @@ -15,7 +16,7 @@ parser.add_argument('--indent', type=int, default=None, help='Indent output by n spaces') parser.add_argument('-v', '--version', action='version', - version='%(prog)s ' + jsonpatch.__version__) + version='%(prog)s ' + __version__) def main(): @@ -30,7 +31,7 @@ def diff_files(): args = parser.parse_args() doc1 = json.load(args.FILE1) doc2 = json.load(args.FILE2) - patch = jsonpatch.make_patch(doc1, doc2) + patch = make_patch(doc1, doc2) if patch.patch: print(json.dumps(patch.patch, indent=args.indent)) sys.exit(1) diff --git a/bin/jsonpatch b/jsonpatch/cli/jsonpatch.py similarity index 96% rename from bin/jsonpatch rename to jsonpatch/cli/jsonpatch.py index a7adf29..799b6be 100755 --- a/bin/jsonpatch +++ b/jsonpatch/cli/jsonpatch.py @@ -4,10 +4,11 @@ import sys import os.path import json -import jsonpatch import tempfile import argparse +from .. import __version__, apply_patch + parser = argparse.ArgumentParser( description='Apply a JSON patch on a JSON file') @@ -23,7 +24,7 @@ parser.add_argument('-i', '--in-place', action='store_true', help='Modify ORIGINAL in-place instead of to stdout') parser.add_argument('-v', '--version', action='version', - version='%(prog)s ' + jsonpatch.__version__) + version='%(prog)s ' + __version__) parser.add_argument('-u', '--preserve-unicode', action='store_true', help='Output Unicode character as-is without using Code Point') @@ -39,7 +40,7 @@ def patch_files(): args = parser.parse_args() doc = json.load(args.ORIGINAL) patch = json.load(args.PATCH) - result = jsonpatch.apply_patch(doc, patch) + result = apply_patch(doc, patch) if args.in_place: dirname = os.path.abspath(os.path.dirname(args.ORIGINAL.name)) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c011afe --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[build-system] +requires = ["setuptools>=44", "wheel", "setuptools_scm[toml]>=3.4.3", "read_version[toml] >= 0.3.0"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "jsonpatch/version.py" +write_to_template = "__version__ = '{version}'\n" + +[tool.read_version] +author = "jsonpatch.__init__:__author__" +author_email = "jsonpatch.__init__:__email__" +url = "jsonpatch.__init__:__website__" +license = "jsonpatch.__init__:__license__" diff --git a/setup.cfg b/setup.cfg index 2a9acf1..077a6ac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,44 @@ +[metadata] +name = jsonpatch +description = Apply JSON-Patches (RFC 6902) +long_description = file: README.md +long_description_content_type = text/markdown +classifiers = + Development Status :: 5 - Production/Stable + Environment :: Console + Intended Audience :: Developers + License :: OSI Approved :: BSD License + Operating System :: OS Independent + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: Implementation :: CPython + Programming Language :: Python :: Implementation :: PyPy + Topic :: Software Development :: Libraries + Topic :: Utilities +project_urls = + Website = https://github.com/stefankoegl/python-json-patch + Repository = https://github.com/stefankoegl/python-json-patch.git + Documentation = https://python-json-patch.readthedocs.org/ + PyPI = https://pypi.org/pypi/jsonpatch + Tests = https://travis-ci.org/stefankoegl/python-json-patch + Test Coverage = https://coveralls.io/r/stefankoegl/python-json-patch + +[options] +packages = jsonpatch, jsonpatch.cli +install_requires = jsonpointer>=1.9 +python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* + +[options.entry_points] +console_scripts = + jsondiff = jsonpatch.cli.jsondiff:main + jsonpatch = jsonpatch.cli.jsonpatch:main + [bdist_wheel] universal = 1 diff --git a/setup.py b/setup.py deleted file mode 100644 index ad43bd5..0000000 --- a/setup.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import io -import re -try: - from setuptools import setup - has_setuptools = True -except ImportError: - from distutils.core import setup - has_setuptools = False - -src = io.open('jsonpatch.py', encoding='utf-8').read() -metadata = dict(re.findall("__([a-z]+)__ = '([^']+)'", src)) -docstrings = re.findall('"""([^"]*)"""', src, re.MULTILINE | re.DOTALL) - -PACKAGE = 'jsonpatch' - -MODULES = ( - 'jsonpatch', -) - -REQUIREMENTS = list(open('requirements.txt')) - -if has_setuptools: - OPTIONS = { - 'install_requires': REQUIREMENTS - } -else: - OPTIONS = {} - -AUTHOR_EMAIL = metadata['author'] -VERSION = metadata['version'] -WEBSITE = metadata['website'] -LICENSE = metadata['license'] -DESCRIPTION = docstrings[0] - -# Extract name and e-mail ("Firstname Lastname ") -AUTHOR, EMAIL = re.match(r'(.*) <(.*)>', AUTHOR_EMAIL).groups() - -try: - from pypandoc import convert - read_md = lambda f: convert(f, 'rst') -except ImportError: - print('warning: pypandoc module not found, could not convert ' - 'Markdown to RST') - read_md = lambda f: open(f, 'r').read() - -CLASSIFIERS = [ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Console', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Topic :: Software Development :: Libraries', - 'Topic :: Utilities', -] - - -setup(name=PACKAGE, - version=VERSION, - description=DESCRIPTION, - long_description=read_md('README.md'), - author=AUTHOR, - author_email=EMAIL, - license=LICENSE, - url=WEBSITE, - py_modules=MODULES, - package_data={'': ['requirements.txt']}, - scripts=['bin/jsondiff', 'bin/jsonpatch'], - classifiers=CLASSIFIERS, - python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', - project_urls={ - 'Website': 'https://github.com/stefankoegl/python-json-patch', - 'Repository': 'https://github.com/stefankoegl/python-json-patch.git', - 'Documentation': "https://python-json-patch.readthedocs.org/", - 'PyPI': 'https://pypi.org/pypi/jsonpatch', - 'Tests': 'https://travis-ci.org/stefankoegl/python-json-patch', - 'Test Coverage': 'https://coveralls.io/r/stefankoegl/python-json-patch', - }, - **OPTIONS -)