Skip to content

Commit 9b8cee0

Browse files
authored
[7.x] Add .ci/make.sh script for building releases
Co-authored-by: Seth Michael Larson <[email protected]>
1 parent f6d2da6 commit 9b8cee0

File tree

6 files changed

+52
-16
lines changed

6 files changed

+52
-16
lines changed

.ci/make.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
BASE_DIR="$( dirname "$BASE_DIR" )"
7+
8+
if [[ "$1" != "release" ]]; then
9+
echo "Must be called ./.ci/make.sh release [version]"
10+
exit 1
11+
fi
12+
13+
python $BASE_DIR/utils/build_dists.py
14+
mkdir -p $BASE_DIR/.ci/output
15+
cp $BASE_DIR/dist/* $BASE_DIR/.ci/output/

.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 setup.py sdist bdist_wheel
21+
python3.7 utils/build_dists.py
2222
- name: Check packages
2323
run: |
2424
set -exo pipefail;

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,5 @@ cython_debug/
142142

143143
# elasticsearch files
144144
test_elasticsearch/cover
145-
test_elasticsearch/local.py
145+
test_elasticsearch/local.py
146+
.ci/output

elasticsearch/__init__.py

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

21-
VERSION = (7, 10, 0)
22-
__version__ = VERSION
23-
__versionstr__ = "7.10.0.dev0"
21+
__versionstr__ = "7.10.0+dev"
2422

23+
import re
2524
import sys
2625
import logging
2726
import warnings
2827

28+
_major, _minor, _patch = [
29+
int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups()
30+
]
31+
VERSION = __version__ = (_major, _minor, _patch)
32+
2933
logger = logging.getLogger("elasticsearch")
3034
logger.addHandler(logging.NullHandler())
3135

setup.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818

19-
from os.path import join, dirname
19+
import re
20+
from os.path import abspath, join, dirname
2021
from setuptools import setup, find_packages
2122

22-
VERSION = (7, 10, 0)
23-
__version__ = VERSION
24-
__versionstr__ = "7.10.0.dev0"
23+
package_name = "elasticsearch"
24+
base_dir = abspath(dirname(__file__))
2525

26-
with open(join(dirname(__file__), "README")) as f:
26+
with open(join(base_dir, package_name, "__init__.py")) as f:
27+
package_version = re.search(
28+
r"__versionstr__\s+=\s+[\"\']([^\"\']+)[\"\']", f.read()
29+
).group(1)
30+
31+
with open(join(base_dir, "README")) as f:
2732
long_description = f.read().strip()
2833

34+
packages = [
35+
package
36+
for package in find_packages(where=".", exclude=("test_elasticsearch*",))
37+
if package == package_name or package.startswith(package_name + ".")
38+
]
39+
2940
install_requires = [
3041
"urllib3>=1.21.1",
3142
"certifi",
@@ -44,13 +55,13 @@
4455
generate_require = ["black", "jinja2"]
4556

4657
setup(
47-
name="elasticsearch",
58+
name=package_name,
4859
description="Python client for Elasticsearch",
4960
license="Apache-2.0",
5061
url="https://github.com/elastic/elasticsearch-py",
5162
long_description=long_description,
5263
long_description_content_type="text/x-rst",
53-
version=__versionstr__,
64+
version=package_version,
5465
author="Honza Král, Nick Lang",
5566
5667
maintainer="Seth Michael Larson",
@@ -60,7 +71,7 @@
6071
"Source Code": "https://github.com/elastic/elasticsearch-py",
6172
"Issue Tracker": "https://github.com/elastic/elasticsearch-py/issues",
6273
},
63-
packages=find_packages(where=".", exclude=("test_elasticsearch*",)),
74+
packages=packages,
6475
package_data={"elasticsearch": ["py.typed"]},
6576
include_package_data=True,
6677
zip_safe=False,

utils/build_dists.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@ def test_dist(dist):
127127

128128

129129
def main():
130+
run("git", "checkout", "--", "setup.py", "elasticsearch/")
130131
run("rm", "-rf", "build/", "dist/", "*.egg-info", ".eggs")
131132

132133
# Grab the major version to be used as a suffix.
133134
setup_py_path = os.path.join(base_dir, "setup.py")
134-
with open(setup_py_path) as f:
135-
major_version = re.search(r"^VERSION = \((\d+),", f.read(), re.M).group(1)
135+
with open(os.path.join(base_dir, "elasticsearch/__init__.py")) as f:
136+
major_version = re.search(
137+
r"^__versionstr__\s+=\s+[\"\'](\d+)\.", f.read(), re.M
138+
).group(1)
136139

137140
for suffix in ("", major_version):
138141
run("rm", "-rf", "build/", "*.egg-info", ".eggs")
@@ -148,9 +151,11 @@ def main():
148151
setup_py = f.read()
149152
with open(setup_py_path, "w") as f:
150153
f.truncate()
154+
assert 'package_name = "elasticsearch"' in setup_py
151155
f.write(
152156
setup_py.replace(
153-
'name="elasticsearch",', 'name="elasticsearch%s",' % suffix
157+
'package_name = "elasticsearch"',
158+
'package_name = "elasticsearch%s"' % suffix,
154159
)
155160
)
156161

0 commit comments

Comments
 (0)