Skip to content

Migrate to pyproject.toml and hatchling #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ ARG BUILDER_GID=1000
ENV BUILDER_USER elastic
ENV BUILDER_GROUP elastic

WORKDIR /code/elasticsearch-serverless-python

# Create user
RUN groupadd --system -g ${BUILDER_GID} ${BUILDER_GROUP} \
&& useradd --system --shell /bin/bash -u ${BUILDER_UID} -g ${BUILDER_GROUP} -d /var/lib/elastic -m elastic 1>/dev/null 2>/dev/null \
&& mkdir -p /code/elasticsearch-py && mkdir /code/elasticsearch-py/build \
&& mkdir /code/elasticsearch-serverless-python/build \
&& chown -R ${BUILDER_USER}:${BUILDER_GROUP} /code/
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .
WORKDIR /code/elasticsearch-py
USER ${BUILDER_USER}:${BUILDER_GROUP}
COPY dev-requirements.txt .
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .
RUN python -m pip install \
-U --no-cache-dir \
--disable-pip-version-check \
nox -rdev-requirements.txt
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .
RUN python -m pip install -U -e .
.[dev]
7 changes: 1 addition & 6 deletions .ci/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,7 @@ if [[ "$CMD" == "assemble" ]]; then
fi

if [[ "$CMD" == "bump" ]]; then
docker run \
--rm -v $repo:/code/elasticsearch-serverless-python \
$product \
/bin/bash -c "python /code/elasticsearch-serverless-python/utils/bump-version.py $VERSION"

exit 0
echo "TODO"
fi

if [[ "$CMD" == "codegen" ]]; then
Expand Down
12 changes: 11 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
---
version: 2
sphinx:
configuration: docs/sphinx/conf.py

build:
os: ubuntu-22.04
tools:
python: "3.10"
jobs:
pre_install:
- "python -m pip install sphinx-rtd-theme sphinx-autodoc-typehints"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed since those dependencies are now in docs extra requirements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nox -s docs was failing due to missing config values that sphinx-rtd-theme needed. I just looked into it more closely and needed to enforce versions on sphinx and the theme to work around it. Fixed in 16c972f.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered what was going and investigated too to be able to tell when we can drop the pins. As you've noticed, the root cause is that the two sphinx packages that we install currently require incompatible versions of Sphinx:

Then pip considers that the plugin "at fault" is sphinx-rtd-theme. I'm not sure how the resolver works, maybe it's the only package that does not support Sphinx 7. Anyway, pip then tries to find a version that does in fact support Sphinx 7:

INFO: pip is looking at multiple versions of sphinx-rtd-theme to determine which version is compatible with other requirements. This could take a while.
Collecting sphinx-rtd-theme (from elasticsearch-serverless==0.1.0)
  Obtaining dependency information for sphinx-rtd-theme from https://files.pythonhosted.org/packages/c2/73/946cdd32f29c87843edaa059b9fc52ab9267d1137b3a76dee1d5
9d02a01a/sphinx_rtd_theme-1.2.1-py2.py3-none-any.whl.metadata                  
  Using cached sphinx_rtd_theme-1.2.1-py2.py3-none-any.whl.metadata (4.5 kB)
  Using cached sphinx_rtd_theme-1.2.0-py2.py3-none-any.whl (2.8 MB)
  Using cached sphinx_rtd_theme-1.1.1-py2.py3-none-any.whl (2.8 MB)
  Using cached sphinx_rtd_theme-1.1.0-py2.py3-none-any.whl (2.8 MB)
  Using cached sphinx_rtd_theme-1.0.0-py2.py3-none-any.whl (2.8 MB)
  Using cached sphinx_rtd_theme-0.5.2-py2.py3-none-any.whl (9.1 MB)
  Using cached sphinx_rtd_theme-0.5.1-py2.py3-none-any.whl (2.8 MB)

Since sphinx-rtd-theme 0.5.1 is the latest release without bounds, pip considers that it does support Sphinx 7. And then installs it. This is something we are likely to continue seeing in the future, given:

I can see two ways out of this issue:

  1. We can use a different theme like which updates faster than sphinx-autodoc-typehints (but does not use a lower bound): https://github.com/pradyunsg/furo.

  2. We can pin Sphinx ourselves, and periodically bump to the latest version that sphinx-rtd-theme supports:

    docs = [                                                                                                                                                       
        # sphinx-rtd-theme does not support Sphinx 7 yet                                                                                                           
        "sphinx<7",                                                                                                                                                
        "sphinx-rtd-theme",                                                                                                                                        
        "sphinx-autodoc-typehints",
    ]

I think I prefer the second approach. Although it does not have to block the pull request, we can do this later as this pull request is otherwise ready to be merged IMO.


python:
version: "3.7"
install:
- requirements: dev-requirements.txt
- path: .
extra_requirements:
- "docs"
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include MANIFEST.in
include README.rst
include NOTICE
include CHANGELOG.md
include setup.py
include pyproject.toml
recursive-include elasticsearch_serverless* py.typed *.pyi
recursive-include docs/sphinx *

Expand Down
24 changes: 0 additions & 24 deletions dev-requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions docs/sphinx/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ arguments are required for all
Elasticsearch
-------------

.. py:module:: elasticsearch
.. py:module:: elasticsearch_serverless

.. autoclass:: Elasticsearch
:members:

.. py:module:: elasticsearch.client
.. py:module:: elasticsearch_serverless.client

Async Search
------------
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
master_doc = "index"

# General information about the project.
project = "Python Elasticsearch client"
project = "Python Elasticsearch serverless client"
copyright = "%d, Elasticsearch B.V" % datetime.date.today().year

version = elasticsearch_serverless.__versionstr__
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Exceptions & Warnings
=====================

.. py:module:: elasticsearch
.. py:module:: elasticsearch_serverless

API Errors
----------
Expand Down
6 changes: 3 additions & 3 deletions docs/sphinx/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Python Elasticsearch Client
===========================
Python Elasticsearch Serverless Client
======================================

Official low-level client for Elasticsearch. Its goal is to provide common
Official low-level client for Elasticsearch serverless. Its goal is to provide common
ground for all Elasticsearch-related code in Python; because of this it tries
to be opinion-free and very extendable.

Expand Down
12 changes: 3 additions & 9 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
SOURCE_DIR = os.path.dirname(os.path.abspath(__file__))
SOURCE_FILES = (
"docs/sphinx/conf.py",
"setup.py",
"noxfile.py",
"elasticsearch_serverless/",
"test_elasticsearch_serverless/",
Expand All @@ -32,8 +31,7 @@

@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"])
def test(session):
session.install(".")
session.install("-r", "dev-requirements.txt")
session.install(".[dev]")

junit_xml = os.path.join(
SOURCE_DIR, "junit", "elasticsearch-serverless-python-junit.xml"
Expand Down Expand Up @@ -106,10 +104,6 @@ def lint(session):

@nox.session()
def docs(session):
session.install(
"-rdev-requirements.txt", "sphinx-rtd-theme", "sphinx-autodoc-typehints"
)
session.install(".")
session.run("python", "-m", "pip", "install", "sphinx-autodoc-typehints")

session.install("sphinx-rtd-theme", "sphinx-autodoc-typehints")
session.install(".[docs]")
session.run("sphinx-build", "docs/sphinx/", "docs/sphinx/_build", "-b", "html")
104 changes: 104 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "elasticsearch-serverless"
version = "0.1.0"
description = "Python client for Elasticsearch Serverless"
readme = "README.rst"
license = "Apache-2.0"
requires-python = ">=3.7, <4"
authors = [
{ name = "Elastic Clients Team", email = "[email protected]" },
]
maintainers = [
{ name = "Elastic Clients Team", email = "[email protected]" },
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"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",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
keywords = [
"elasticsearch",
"elastic",
"kibana",
"mapping",
"REST",
"search",
"client",
"index",
]
dependencies = [
"elastic-transport>=8,<9",
]

[project.optional-dependencies]
async = [
"aiohttp>=3,<4",
]
requests = [
"requests>=2.4.0, <3.0.0",
]
dev = [
"requests>=2, <3",
"aiohttp",
"pytest",
"pytest-cov",
"pytest-asyncio",
"coverage",
"jinja2",
"python-dateutil",
"unasync",
"pyyaml>=5.4",
"isort",
"black",
"twine",
"build",
"nox",
"numpy",
"pandas",
"mapbox-vector-tile",
]
docs = [
"sphinx-rtd-theme",
"sphinx-autodoc-typehints",
"sphinx",
]

[project.urls]
Documentation = "https://elasticsearch-serverless-python.readthedocs.io"
Homepage = "https://github.com/elastic/elasticsearch-serverless-python"
"Issue Tracker" = "https://github.com/elastic/elasticsearch-serverless-python/issues"
"Source Code" = "https://github.com/elastic/elasticsearch-serverless-python"

[tool.hatch.build.targets.sdist]
include = [
"/elasticsearch_serverless",
]

[tool.pytest]
junit_family = "legacy"
addopts = "-vvv -p no:logging --cov-report=term-missing --cov=elasticsearch_serverless --cov-config=.pyproject.toml"

[tool.isort]
profile = "black"

[tool.coverage.report]
exclude_lines = [
"raise NotImplementedError*",
]

[tool.mypy]
ignore_missing_imports = true
14 changes: 0 additions & 14 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
[flake8]
ignore = E203, E266, E501, W503

[tool:pytest]
junit_family=legacy
addopts = -vvv -p no:logging --cov-report=term-missing --cov=elasticsearch --cov-config=.coveragerc

[tool:isort]
profile=black

[report]
exclude_lines=
raise NotImplementedError*

[mypy]
ignore_missing_imports = True
99 changes: 0 additions & 99 deletions setup.py

This file was deleted.

Loading