Skip to content

Commit

Permalink
Python: Migrate to use "implicit namespace packages" (PEP 420)
Browse files Browse the repository at this point in the history
... instead of "declared namespaces" for the `crate` namespace package,
see PEP 420 [1], and setuptools docs [2].

> Historically, there were two methods to create namespace packages. One
> is the `pkg_resources` style supported by `setuptools` and the other
> one being `pkgutils` style offered by `pkgutils` module in Python.
> Both are now considered _deprecated_.
>
> -- Legacy Namespace Packages [3]

[1] https://peps.python.org/pep-0420/
[2] https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
[3] https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#legacy-namespace-packages
  • Loading branch information
amotl committed Nov 1, 2024
1 parent dfeb871 commit b8e3e6b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ Unreleased
- Error handling: At two spots in cursor / value converter handling, where
``assert`` statements have been used, ``ValueError`` exceptions are raised
now.
- Python: Migrated to use "implicit namespace packages" instead of "declared
namespaces" for the ``crate`` namespace package, see `PEP 420`_.


.. _Migrate from crate.client to sqlalchemy-cratedb: https://cratedb.com/docs/sqlalchemy-cratedb/migrate-from-crate-client.html
.. _PEP 420: https://peps.python.org/pep-0420/
.. _sqlalchemy-cratedb: https://pypi.org/project/sqlalchemy-cratedb/


Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os
import re

from setuptools import find_packages, setup
from setuptools import find_namespace_packages, setup


def read(path):
Expand All @@ -45,15 +45,14 @@ def read(path):
url="https://github.com/crate/crate-python",
author="Crate.io",
author_email="[email protected]",
package_dir={"": "src"},
description="CrateDB Python Client",
long_description=long_description,
long_description_content_type="text/x-rst",
platforms=["any"],
license="Apache License 2.0",
keywords="cratedb db api dbapi database sql http rdbms olap",
packages=find_packages("src"),
namespace_packages=["crate"],
packages=find_namespace_packages("src"),
package_dir={"": "src"},
install_requires=[
"urllib3<2.3",
"verlib2==0.2.0",
Expand Down
30 changes: 0 additions & 30 deletions src/crate/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)
1 change: 0 additions & 1 deletion src/crate/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# package

0 comments on commit b8e3e6b

Please sign in to comment.