From b2bd273eabeb39a85904ae1700aa1395b3da0e87 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Sun, 22 Mar 2026 05:04:40 -0500 Subject: [PATCH] Migrate to a `src/` layout This prevents the test suite from accidentally passing when a packaging problem is masked by `jsonpath_ng` being importable from the root of the repository. See https://github.com/h2non/jsonpath-ng/pull/209 for a PR that demonstrates the consequences of having `jsonpath_ng/` as a folder in the root of the repo. In addition, this migrates from `setup.py` to `pyproject.toml`. With this change, the project can be built with these commands: ``` pip install build python -m build ``` --- .devcontainer/devcontainer.json | 2 +- .github/workflows/ci.yml | 1 - .gitignore | 2 +- Makefile | 1 - pyproject.toml | 30 ++++++++++++++++ requirements.txt | 1 - setup.py | 36 ------------------- {jsonpath_ng => src/jsonpath_ng}/__init__.py | 0 .../jsonpath_ng}/_ply/__init__.py | 0 {jsonpath_ng => src/jsonpath_ng}/_ply/lex.py | 0 {jsonpath_ng => src/jsonpath_ng}/_ply/yacc.py | 0 .../jsonpath_ng}/bin/__init__.py | 0 .../jsonpath_ng}/bin/jsonpath.py | 0 .../jsonpath_ng}/exceptions.py | 0 .../jsonpath_ng}/ext/__init__.py | 0 .../jsonpath_ng}/ext/arithmetic.py | 0 .../jsonpath_ng}/ext/filter.py | 0 .../jsonpath_ng}/ext/iterable.py | 0 .../jsonpath_ng}/ext/parser.py | 0 .../jsonpath_ng}/ext/string.py | 0 {jsonpath_ng => src/jsonpath_ng}/jsonpath.py | 0 {jsonpath_ng => src/jsonpath_ng}/lexer.py | 0 {jsonpath_ng => src/jsonpath_ng}/parser.py | 0 23 files changed, 32 insertions(+), 41 deletions(-) delete mode 100644 requirements.txt delete mode 100644 setup.py rename {jsonpath_ng => src/jsonpath_ng}/__init__.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/_ply/__init__.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/_ply/lex.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/_ply/yacc.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/bin/__init__.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/bin/jsonpath.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/exceptions.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/ext/__init__.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/ext/arithmetic.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/ext/filter.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/ext/iterable.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/ext/parser.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/ext/string.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/jsonpath.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/lexer.py (100%) rename {jsonpath_ng => src/jsonpath_ng}/parser.py (100%) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 094f835..b751188 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,7 @@ "cpus": 4 }, "waitFor": "onCreateCommand", - "updateContentCommand": "pip install -r requirements.txt -r requirements-dev.txt", + "updateContentCommand": "pip install -r requirements-dev.txt", "customizations": { "vscode": { "extensions": [ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7125355..ef4f788 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip setuptools wheel - pip install -r requirements.txt pip install -r requirements-dev.txt - name: Run tests run: tox run -e py${{ matrix.python-version }} diff --git a/.gitignore b/.gitignore index 3a035cd..ef3a334 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ __pycache__/ # Build and test artifacts /README.txt /dist -/*.egg-info +*.egg-info parser.out .cache .coverage diff --git a/Makefile b/Makefile index 75a273a..f51ffa5 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,6 @@ htmldocs: $(MAKE) -C docs html install: - @pip install -r requirements.txt @pip install -r requirements-dev.txt lint: diff --git a/pyproject.toml b/pyproject.toml index 9250e21..4823cc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,33 @@ +[build-system] +requires = ["setuptools >= 77.0.3"] +build-backend = "setuptools.build_meta" + +[project] +name = "jsonpath-ng" +version = "1.8.0" +description="A final implementation of JSONPath for Python that aims to be standard compliant, including arithmetic and binary comparison operators and providing clear AST for metaprogramming." +authors = [ + {name = "Tomas Aparicio", email = "tomas@aparicio.me"}, +] +license = "Apache-2.0" +readme = "README.rst" +classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", +] + +[project.urls] +Source = "https://github.com/h2non/jsonpath-ng" + +[project.scripts] +jsonpath_ng = "jsonpath_ng.bin.jsonpath:entry_point" + [tool.pytest.ini_options] filterwarnings = [ # Escalate warnings to errors. diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e5f04fc..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -setuptools>=18.5 diff --git a/setup.py b/setup.py deleted file mode 100644 index 001eabd..0000000 --- a/setup.py +++ /dev/null @@ -1,36 +0,0 @@ -import io -import setuptools - - -setuptools.setup( - name='jsonpath-ng', - version='1.8.0', - description=( - 'A final implementation of JSONPath for Python that aims to be ' - 'standard compliant, including arithmetic and binary comparison ' - 'operators and providing clear AST for metaprogramming.' - ), - author='Tomas Aparicio', - author_email='tomas@aparicio.me', - url='https://github.com/h2non/jsonpath-ng', - license='Apache 2.0', - long_description=io.open('README.rst', encoding='utf-8').read(), - packages=['jsonpath_ng', 'jsonpath_ng.bin', 'jsonpath_ng.ext','jsonpath_ng._ply'], - entry_points={ - 'console_scripts': [ - 'jsonpath_ng=jsonpath_ng.bin.jsonpath:entry_point' - ], - }, - test_suite='tests', - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'Programming Language :: Python :: 3.13', - 'Programming Language :: Python :: 3.14', - ], -) diff --git a/jsonpath_ng/__init__.py b/src/jsonpath_ng/__init__.py similarity index 100% rename from jsonpath_ng/__init__.py rename to src/jsonpath_ng/__init__.py diff --git a/jsonpath_ng/_ply/__init__.py b/src/jsonpath_ng/_ply/__init__.py similarity index 100% rename from jsonpath_ng/_ply/__init__.py rename to src/jsonpath_ng/_ply/__init__.py diff --git a/jsonpath_ng/_ply/lex.py b/src/jsonpath_ng/_ply/lex.py similarity index 100% rename from jsonpath_ng/_ply/lex.py rename to src/jsonpath_ng/_ply/lex.py diff --git a/jsonpath_ng/_ply/yacc.py b/src/jsonpath_ng/_ply/yacc.py similarity index 100% rename from jsonpath_ng/_ply/yacc.py rename to src/jsonpath_ng/_ply/yacc.py diff --git a/jsonpath_ng/bin/__init__.py b/src/jsonpath_ng/bin/__init__.py similarity index 100% rename from jsonpath_ng/bin/__init__.py rename to src/jsonpath_ng/bin/__init__.py diff --git a/jsonpath_ng/bin/jsonpath.py b/src/jsonpath_ng/bin/jsonpath.py similarity index 100% rename from jsonpath_ng/bin/jsonpath.py rename to src/jsonpath_ng/bin/jsonpath.py diff --git a/jsonpath_ng/exceptions.py b/src/jsonpath_ng/exceptions.py similarity index 100% rename from jsonpath_ng/exceptions.py rename to src/jsonpath_ng/exceptions.py diff --git a/jsonpath_ng/ext/__init__.py b/src/jsonpath_ng/ext/__init__.py similarity index 100% rename from jsonpath_ng/ext/__init__.py rename to src/jsonpath_ng/ext/__init__.py diff --git a/jsonpath_ng/ext/arithmetic.py b/src/jsonpath_ng/ext/arithmetic.py similarity index 100% rename from jsonpath_ng/ext/arithmetic.py rename to src/jsonpath_ng/ext/arithmetic.py diff --git a/jsonpath_ng/ext/filter.py b/src/jsonpath_ng/ext/filter.py similarity index 100% rename from jsonpath_ng/ext/filter.py rename to src/jsonpath_ng/ext/filter.py diff --git a/jsonpath_ng/ext/iterable.py b/src/jsonpath_ng/ext/iterable.py similarity index 100% rename from jsonpath_ng/ext/iterable.py rename to src/jsonpath_ng/ext/iterable.py diff --git a/jsonpath_ng/ext/parser.py b/src/jsonpath_ng/ext/parser.py similarity index 100% rename from jsonpath_ng/ext/parser.py rename to src/jsonpath_ng/ext/parser.py diff --git a/jsonpath_ng/ext/string.py b/src/jsonpath_ng/ext/string.py similarity index 100% rename from jsonpath_ng/ext/string.py rename to src/jsonpath_ng/ext/string.py diff --git a/jsonpath_ng/jsonpath.py b/src/jsonpath_ng/jsonpath.py similarity index 100% rename from jsonpath_ng/jsonpath.py rename to src/jsonpath_ng/jsonpath.py diff --git a/jsonpath_ng/lexer.py b/src/jsonpath_ng/lexer.py similarity index 100% rename from jsonpath_ng/lexer.py rename to src/jsonpath_ng/lexer.py diff --git a/jsonpath_ng/parser.py b/src/jsonpath_ng/parser.py similarity index 100% rename from jsonpath_ng/parser.py rename to src/jsonpath_ng/parser.py