Skip to content

Commit 871a335

Browse files
authored
Actually dockerize repo, update build-dists for release manager
1 parent 598a767 commit 871a335

14 files changed

+102
-22
lines changed

Diff for: .ci/Dockerfile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
ARG PYTHON_VERSION=3.8
22
FROM python:${PYTHON_VERSION}
33

4-
COPY dev-requirements.txt /tmp
5-
RUN python -m pip install -r /tmp/dev-requirements.txt
6-
74
WORKDIR /code/elasticsearch-py
5+
COPY . .
6+
RUN python -m pip install \
7+
--no-cache-dir \
8+
--disable-pip-version-check \
9+
-e . \
10+
-r dev-requirements.txt

Diff for: .ci/make.sh

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ set -eo pipefail
55
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
66
BASE_DIR="$( dirname "$BASE_DIR" )"
77

8-
if [[ "$1" != "release" ]]; then
9-
echo "Must be called ./.ci/make.sh release [version]"
10-
exit 1
8+
if [[ "$1" == "release" ]]; then
9+
python $BASE_DIR/utils/build-dists.py $2
10+
mkdir -p $BASE_DIR/.ci/output
11+
cp $BASE_DIR/dist/* $BASE_DIR/.ci/output/
12+
exit 0
1113
fi
1214

13-
python $BASE_DIR/utils/build_dists.py
14-
mkdir -p $BASE_DIR/.ci/output
15-
cp $BASE_DIR/dist/* $BASE_DIR/.ci/output/
15+
echo "Must be called with '.ci/make.sh [command]"
16+
exit 1

Diff for: .ci/run-repository.sh

-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ docker run \
4040
--env "TEST_TYPE=server" \
4141
--name elasticsearch-py \
4242
--rm \
43-
--volume `pwd`:/code/elasticsearch-py \
4443
elastic/elasticsearch-py \
4544
python setup.py test

Diff for: .dockerignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ docs
22
example
33
venv
44
.git
5-
.tox
5+
.tox
6+
.nox
7+
.*_cache

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
python3.7 -m pip install setuptools wheel twine
1919
- name: Build packages
2020
run: |
21-
python3.7 utils/build_dists.py
21+
python3.7 utils/build-dists.py
2222
- name: Check packages
2323
run: |
2424
set -exo pipefail;

Diff for: dev-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pandas
1414
pyyaml<5.3
1515

1616
black; python_version>="3.6"
17+
twine
1718

1819
# Requirements for testing [async] extra
1920
aiohttp; python_version>="3.6"

Diff for: elasticsearch/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
# flake8: noqa
1919
from __future__ import absolute_import
2020

21-
__versionstr__ = "8.0.0+dev"
22-
2321
import re
2422
import sys
2523
import logging
2624
import warnings
2725

26+
from ._version import __versionstr__
27+
2828
_major, _minor, _patch = [
2929
int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups()
3030
]

Diff for: elasticsearch/_version.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
__versionstr__ = "8.0.0+dev"

Diff for: noxfile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def blacken(session):
4040
session.install("black")
4141

4242
session.run("black", "--target-version=py27", *SOURCE_FILES)
43-
session.run("python", "utils/license_headers.py", "fix", *SOURCE_FILES)
43+
session.run("python", "utils/license-headers.py", "fix", *SOURCE_FILES)
4444

4545
lint(session)
4646

@@ -51,7 +51,7 @@ def lint(session):
5151

5252
session.run("black", "--target-version=py27", "--check", *SOURCE_FILES)
5353
session.run("flake8", *SOURCE_FILES)
54-
session.run("python", "utils/license_headers.py", "check", *SOURCE_FILES)
54+
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)
5555

5656
# Workaround to make '-r' to still work despite uninstalling aiohttp below.
5757
session.run("python", "-m", "pip", "install", "aiohttp")

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
package_name = "elasticsearch"
2525
base_dir = abspath(dirname(__file__))
2626

27-
with open(join(base_dir, package_name, "__init__.py")) as f:
27+
with open(join(base_dir, package_name, "_version.py")) as f:
2828
package_version = re.search(
2929
r"__versionstr__\s+=\s+[\"\']([^\"\']+)[\"\']", f.read()
3030
).group(1)

Diff for: utils/build_dists.py renamed to utils/build-dists.py

+61-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import tempfile
2424
import os
2525
import shlex
26+
import sys
2627
import re
2728
import contextlib
2829
import shutil
@@ -163,11 +164,50 @@ def main():
163164
run("rm", "-rf", "build/", "dist/", "*.egg-info", ".eggs")
164165

165166
# Grab the major version to be used as a suffix.
166-
setup_py_path = os.path.join(base_dir, "setup.py")
167-
with open(os.path.join(base_dir, "elasticsearch/__init__.py")) as f:
168-
major_version = re.search(
169-
r"^__versionstr__\s+=\s+[\"\'](\d+)\.", f.read(), re.M
167+
version_path = os.path.join(base_dir, "elasticsearch/_version.py")
168+
with open(version_path) as f:
169+
version = re.search(
170+
r"^__versionstr__\s+=\s+[\"\']([^\"\']+)[\"\']", f.read(), re.M
170171
).group(1)
172+
major_version = version.split(".")[0]
173+
174+
# If we're handed a version from the build manager we
175+
# should check that the version is correct or write
176+
# a new one.
177+
if len(sys.argv) >= 2:
178+
# 'build_version' is what the release manager wants,
179+
# 'expect_version' is what we're expecting to compare
180+
# the package version to before building the dists.
181+
build_version = expect_version = sys.argv[1]
182+
183+
# '-SNAPSHOT' means we're making a pre-release.
184+
if "-SNAPSHOT" in build_version:
185+
# If there's no +dev already (as is the case on dev
186+
# branches like 7.x, master) then we need to add one.
187+
if not version.endswith("+dev"):
188+
version = version + "+dev"
189+
expect_version = expect_version.replace("-SNAPSHOT", "")
190+
if expect_version.endswith(".x"):
191+
expect_version = expect_version[:-2]
192+
193+
# For snapshots we ensure that the version in the package
194+
# at least *starts* with the version. This is to support
195+
# build_version='7.x-SNAPSHOT'.
196+
if not version.startswith(expect_version):
197+
print(
198+
"Version of package (%s) didn't match the "
199+
"expected release version (%s)" % (version, build_version)
200+
)
201+
exit(1)
202+
203+
# A release that will be tagged, we want
204+
# there to be no '+dev', etc.
205+
elif expect_version != version:
206+
print(
207+
"Version of package (%s) didn't match the "
208+
"expected release version (%s)" % (version, build_version)
209+
)
210+
exit(1)
171211

172212
for suffix in ("", major_version):
173213
run("rm", "-rf", "build/", "*.egg-info", ".eggs")
@@ -178,7 +218,21 @@ def main():
178218
os.path.join(base_dir, "elasticsearch%s" % suffix),
179219
)
180220

221+
# Ensure that the version within 'elasticsearch/_version.py' is correct.
222+
version_path = os.path.join(base_dir, f"elasticsearch{suffix}/_version.py")
223+
with open(version_path) as f:
224+
version_data = f.read()
225+
version_data = re.sub(
226+
r"__versionstr__ = \"[^\"]+\"",
227+
'__versionstr__ = "%s"' % version,
228+
version_data,
229+
)
230+
with open(version_path, "w") as f:
231+
f.truncate()
232+
f.write(version_data)
233+
181234
# Rewrite setup.py with the new name.
235+
setup_py_path = os.path.join(base_dir, "setup.py")
182236
with open(setup_py_path) as f:
183237
setup_py = f.read()
184238
with open(setup_py_path, "w") as f:
@@ -200,7 +254,9 @@ def main():
200254
run("rm", "-rf", "elasticsearch%s/" % suffix)
201255

202256
# Test everything that got created
203-
for dist in os.listdir(os.path.join(base_dir, "dist")):
257+
dists = os.listdir(os.path.join(base_dir, "dist"))
258+
assert len(dists) == 4
259+
for dist in dists:
204260
test_dist(os.path.join(base_dir, "dist", dist))
205261

206262
# After this run 'python -m twine upload dist/*'
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)