Skip to content

Commit

Permalink
[7.x] Handle Python pre-releases properly in meta header
Browse files Browse the repository at this point in the history
Co-authored-by: Seth Michael Larson <seth.larson@elastic.co>
  • Loading branch information
github-actions[bot] and sethmlarson committed Dec 15, 2020
1 parent b894e35 commit 58b3761
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ jobs:
run: nox -s docs

test-linux:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
experimental: [false]
include:
- python-version: 3.9-dev
experimental: true

runs-on: ubuntu-latest
name: test-${{ matrix.python-version }}
continue-on-error: ${{ matrix.experimental }}
steps:
- name: Checkout Repository
uses: actions/checkout@v1
Expand Down
7 changes: 4 additions & 3 deletions elasticsearch/connection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io
import re
from platform import python_version
import sys
import warnings

try:
Expand Down Expand Up @@ -344,7 +343,9 @@ def _python_to_meta_version(version):
compatible with 'X-Elastic-Client-Meta'. Essentially
replaces any pre-release information with a 'p' suffix.
"""
version, version_pre = re.match(r"^([0-9.]+)(.*)$", version).groups()
version, version_pre = re.match(
r"^([0-9][0-9.]*[0-9]|[0-9])(.*)$", version
).groups()
if version_pre:
version += "p"
return version
Expand All @@ -353,7 +354,7 @@ def _python_to_meta_version(version):
def _get_client_meta_header(client_meta=()):
"""Builds an 'X-Elastic-Client-Meta' HTTP header"""
es_version = _python_to_meta_version(__versionstr__)
py_version = python_version() + ("p" if sys.version_info[3] != "final" else "")
py_version = _python_to_meta_version(python_version())
# First three values have to be 'service', 'language', 'transport'
client_meta = (("es", es_version), ("py", py_version), ("t", es_version)) + tuple(
client_meta
Expand Down
3 changes: 2 additions & 1 deletion test_elasticsearch/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_get_client_meta_header(self):
meta_header = _get_client_meta_header()
assert ("es=%s" % (".".join(str(x) for x in __version__),)) in meta_header
assert ("t=%s" % (".".join(str(x) for x in __version__),)) in meta_header
assert ("py=%s" % python_version()) in meta_header
assert ("py=%s" % _python_to_meta_version(python_version())) in meta_header

meta_header = _get_client_meta_header((("h", "bp"),))
assert meta_header.endswith(",h=bp")
Expand All @@ -191,6 +191,7 @@ def test_get_client_meta_header(self):
def test_python_to_meta_version(self):
assert _python_to_meta_version("1.26.3") == "1.26.3"
assert _python_to_meta_version("7.10.1a1") == "7.10.1p"
assert _python_to_meta_version("7.10.a1") == "7.10p"


class TestUrllib3Connection(TestCase):
Expand Down

0 comments on commit 58b3761

Please sign in to comment.