Skip to content

Commit cc0522f

Browse files
authored
Add .ci/make.sh script for building releases
1 parent 398a417 commit cc0522f

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

.ci/make.sh

Lines changed: 15 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

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

21-
VERSION = (8, 0, 0)
22-
__version__ = VERSION
23-
__versionstr__ = "8.0.0.dev0"
21+
__versionstr__ = "8.0.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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,28 @@
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 = (8, 0, 0)
23-
__version__ = VERSION
24-
__versionstr__ = "8.0.0.dev0"
2523

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

35+
packages = [
36+
package
37+
for package in find_packages(where=".", exclude=("test_elasticsearch*",))
38+
if package == package_name or package.startswith(package_name + ".")
39+
]
40+
2941
install_requires = [
3042
"urllib3>=1.21.1",
3143
"certifi",
@@ -44,13 +56,13 @@
4456
generate_require = ["black", "jinja2"]
4557

4658
setup(
47-
name="elasticsearch",
59+
name=package_name,
4860
description="Python client for Elasticsearch",
4961
license="Apache-2.0",
5062
url="https://github.com/elastic/elasticsearch-py",
5163
long_description=long_description,
5264
long_description_content_type="text/x-rst",
53-
version=__versionstr__,
65+
version=package_version,
5466
author="Honza Král, Nick Lang",
5567
author_email="honza.kral@gmail.com, nick@nicklang.com",
5668
maintainer="Seth Michael Larson",
@@ -60,7 +72,7 @@
6072
"Source Code": "https://github.com/elastic/elasticsearch-py",
6173
"Issue Tracker": "https://github.com/elastic/elasticsearch-py/issues",
6274
},
63-
packages=find_packages(where=".", exclude=("test_elasticsearch*",)),
75+
packages=packages,
6476
package_data={"elasticsearch": ["py.typed"]},
6577
include_package_data=True,
6678
zip_safe=False,

utils/build_dists.py

Lines changed: 8 additions & 3 deletions
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)