From 70343880f1b20d9026066b2dd3a94b90914176bc Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 4 Nov 2024 19:23:32 +0100 Subject: [PATCH] Python: Migrate to use "implicit namespace packages" (PEP 420) --- CHANGES.txt | 4 ++++ crate/__init__.py | 30 ------------------------ devtools/ci.sh | 4 ++-- setup.py | 9 +++---- src/crate/__init__.py | 0 {crate => src/crate}/crash/__init__.py | 0 {crate => src/crate}/crash/__main__.py | 0 {crate => src/crate}/crash/command.py | 0 {crate => src/crate}/crash/commands.py | 0 {crate => src/crate}/crash/config.py | 0 {crate => src/crate}/crash/connect.txt | 0 {crate => src/crate}/crash/keybinding.py | 0 {crate => src/crate}/crash/layout.py | 0 {crate => src/crate}/crash/output.txt | 0 {crate => src/crate}/crash/outputs.py | 0 {crate => src/crate}/crash/printer.py | 0 {crate => src/crate}/crash/repl.py | 0 {crate => src/crate}/crash/sysinfo.py | 0 {crate => src/crate}/crash/tabulate.py | 0 tests/test_integration.py | 4 ++-- 20 files changed, 13 insertions(+), 38 deletions(-) delete mode 100644 crate/__init__.py create mode 100644 src/crate/__init__.py rename {crate => src/crate}/crash/__init__.py (100%) rename {crate => src/crate}/crash/__main__.py (100%) rename {crate => src/crate}/crash/command.py (100%) rename {crate => src/crate}/crash/commands.py (100%) rename {crate => src/crate}/crash/config.py (100%) rename {crate => src/crate}/crash/connect.txt (100%) rename {crate => src/crate}/crash/keybinding.py (100%) rename {crate => src/crate}/crash/layout.py (100%) rename {crate => src/crate}/crash/output.txt (100%) rename {crate => src/crate}/crash/outputs.py (100%) rename {crate => src/crate}/crash/printer.py (100%) rename {crate => src/crate}/crash/repl.py (100%) rename {crate => src/crate}/crash/sysinfo.py (100%) rename {crate => src/crate}/crash/tabulate.py (100%) diff --git a/CHANGES.txt b/CHANGES.txt index e0a18054..039bc650 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,10 @@ Changes for crash Unreleased ========== +- Python: Migrated to use "implicit namespace packages" instead of "declared + namespaces" for the ``crate`` namespace package, see `PEP 420`_. + +.. _PEP 420: https://peps.python.org/pep-0420/ 2024/04/24 0.31.5 ================= diff --git a/crate/__init__.py b/crate/__init__.py deleted file mode 100644 index 026c0677..00000000 --- a/crate/__init__.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8; -*- -# -# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor -# license agreements. See the NOTICE file distributed with this work for -# additional information regarding copyright ownership. Crate licenses -# this file to you 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. -# -# However, if you have executed another commercial license agreement -# with Crate these terms will supersede the license and you may use the -# software solely pursuant to the terms of the relevant commercial agreement. - -# this is a namespace package -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/devtools/ci.sh b/devtools/ci.sh index f506f887..a8e59ea8 100755 --- a/devtools/ci.sh +++ b/devtools/ci.sh @@ -2,6 +2,6 @@ set -e -x -isort --check --diff crate/ tests/ setup.py -flake8 crate/crash +isort --check --diff src/crate/ tests/ setup.py +flake8 src/crate/crash coverage run -m unittest -v diff --git a/setup.py b/setup.py index f5d3d19b..ff63d8ab 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ def read(path): read('README.rst') ) -versionf_content = read(os.path.join('crate', 'crash', '__init__.py')) +versionf_content = read(os.path.join('src', 'crate', 'crash', '__init__.py')) version_rex = r'^__version__ = [\'"]([^\'"]*)[\'"]$' m = re.search(version_rex, versionf_content, re.M) if m: @@ -68,7 +68,7 @@ def read(path): license='Apache License 2.0', keywords='cratedb db data client shell', packages=['crate.crash'], - namespace_packages=['crate'], + package_dir={"": "src"}, entry_points={ 'console_scripts': [ 'crash = crate.crash.command:main', @@ -76,9 +76,10 @@ def read(path): }, extras_require=dict( test=[ - 'crate[test]', + 'crate[test]>=1.0.0.dev2', + 'cratedb-toolkit[testing]', + 'sqlalchemy-cratedb', 'zc.customdoctests<2', - 'cratedb-toolkit[test]', ], devel=[ 'coverage<8', diff --git a/src/crate/__init__.py b/src/crate/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/crate/crash/__init__.py b/src/crate/crash/__init__.py similarity index 100% rename from crate/crash/__init__.py rename to src/crate/crash/__init__.py diff --git a/crate/crash/__main__.py b/src/crate/crash/__main__.py similarity index 100% rename from crate/crash/__main__.py rename to src/crate/crash/__main__.py diff --git a/crate/crash/command.py b/src/crate/crash/command.py similarity index 100% rename from crate/crash/command.py rename to src/crate/crash/command.py diff --git a/crate/crash/commands.py b/src/crate/crash/commands.py similarity index 100% rename from crate/crash/commands.py rename to src/crate/crash/commands.py diff --git a/crate/crash/config.py b/src/crate/crash/config.py similarity index 100% rename from crate/crash/config.py rename to src/crate/crash/config.py diff --git a/crate/crash/connect.txt b/src/crate/crash/connect.txt similarity index 100% rename from crate/crash/connect.txt rename to src/crate/crash/connect.txt diff --git a/crate/crash/keybinding.py b/src/crate/crash/keybinding.py similarity index 100% rename from crate/crash/keybinding.py rename to src/crate/crash/keybinding.py diff --git a/crate/crash/layout.py b/src/crate/crash/layout.py similarity index 100% rename from crate/crash/layout.py rename to src/crate/crash/layout.py diff --git a/crate/crash/output.txt b/src/crate/crash/output.txt similarity index 100% rename from crate/crash/output.txt rename to src/crate/crash/output.txt diff --git a/crate/crash/outputs.py b/src/crate/crash/outputs.py similarity index 100% rename from crate/crash/outputs.py rename to src/crate/crash/outputs.py diff --git a/crate/crash/printer.py b/src/crate/crash/printer.py similarity index 100% rename from crate/crash/printer.py rename to src/crate/crash/printer.py diff --git a/crate/crash/repl.py b/src/crate/crash/repl.py similarity index 100% rename from crate/crash/repl.py rename to src/crate/crash/repl.py diff --git a/crate/crash/sysinfo.py b/src/crate/crash/sysinfo.py similarity index 100% rename from crate/crash/sysinfo.py rename to src/crate/crash/sysinfo.py diff --git a/crate/crash/tabulate.py b/src/crate/crash/tabulate.py similarity index 100% rename from crate/crash/tabulate.py rename to src/crate/crash/tabulate.py diff --git a/tests/test_integration.py b/tests/test_integration.py index 877d1186..033c4781 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -113,10 +113,10 @@ def __call__(self, *args, **kwargs): class DocumentationTest(TestCase): def test_output(self): - testfile('../crate/crash/output.txt') + testfile('../src/crate/crash/output.txt') def test_connect(self): - testfile('../crate/crash/connect.txt') + testfile('../src/crate/crash/connect.txt') class CommandTest(TestCase):