Skip to content

Commit 900e315

Browse files
dixSAVIKx
andauthored
Improve redistribute-ability (cloudevents#151)
* Move functions needed to build project into setup.py Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * Only execute setup() in __main__ Signed-off-by: Dustin Ingram <di@users.noreply.github.com> Co-authored-by: Yurii Serhiichuk <xSAVIKx@users.noreply.github.com>
1 parent 1a0d48e commit 900e315

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

pypi_packaging.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
import codecs
2-
3-
import pkg_resources
41
import os
2+
import pkg_resources
53

6-
7-
def read(rel_path):
8-
here = os.path.abspath(os.path.dirname(__file__))
9-
with codecs.open(os.path.join(here, rel_path), "r") as fp:
10-
return fp.read()
11-
12-
13-
def get_version(rel_path):
14-
for line in read(rel_path).splitlines():
15-
if line.startswith("__version__"):
16-
delim = '"' if '"' in line else "'"
17-
return line.split(delim)[1]
18-
else:
19-
raise RuntimeError("Unable to find version string.")
20-
21-
22-
# FORMAT: 1.x.x
23-
pypi_config = {
24-
"version_target": get_version("cloudevents/__init__.py"),
25-
"package_name": "cloudevents",
26-
}
4+
from setup import pypi_config
275

286

297
def createTag():

setup.py

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,59 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from pypi_packaging import pypi_config
15-
1614
from setuptools import setup, find_packages
1715

16+
import os
17+
import codecs
1818
import pathlib
1919

2020

21+
def read(rel_path):
22+
here = os.path.abspath(os.path.dirname(__file__))
23+
with codecs.open(os.path.join(here, rel_path), "r") as fp:
24+
return fp.read()
25+
26+
27+
def get_version(rel_path):
28+
for line in read(rel_path).splitlines():
29+
if line.startswith("__version__"):
30+
delim = '"' if '"' in line else "'"
31+
return line.split(delim)[1]
32+
else:
33+
raise RuntimeError("Unable to find version string.")
34+
35+
36+
# FORMAT: 1.x.x
37+
pypi_config = {
38+
"version_target": get_version("cloudevents/__init__.py"),
39+
"package_name": "cloudevents",
40+
}
41+
2142
here = pathlib.Path(__file__).parent.resolve()
2243
long_description = (here / "README.md").read_text(encoding="utf-8")
2344

24-
setup(
25-
name=pypi_config["package_name"],
26-
summary="CloudEvents SDK Python",
27-
long_description_content_type="text/markdown",
28-
long_description=long_description,
29-
author="The Cloud Events Contributors",
30-
author_email="cncfcloudevents@gmail.com",
31-
home_page="https://cloudevents.io",
32-
classifiers=[
33-
"Intended Audience :: Information Technology",
34-
"Intended Audience :: System Administrators",
35-
"License :: OSI Approved :: Apache Software License",
36-
"Operating System :: POSIX :: Linux",
37-
"Programming Language :: Python :: 3",
38-
"Programming Language :: Python :: 3.6",
39-
"Programming Language :: Python :: 3.7",
40-
"Programming Language :: Python :: 3.8",
41-
"Programming Language :: Python :: 3.9",
42-
"Programming Language :: Python :: 3.10",
43-
],
44-
packages=find_packages(exclude=["cloudevents.tests"]),
45-
version=pypi_config["version_target"],
46-
install_requires=["deprecation>=2.0,<3.0"],
47-
)
45+
if __name__ == "__main__":
46+
setup(
47+
name=pypi_config["package_name"],
48+
summary="CloudEvents SDK Python",
49+
long_description_content_type="text/markdown",
50+
long_description=long_description,
51+
author="The Cloud Events Contributors",
52+
author_email="cncfcloudevents@gmail.com",
53+
home_page="https://cloudevents.io",
54+
classifiers=[
55+
"Intended Audience :: Information Technology",
56+
"Intended Audience :: System Administrators",
57+
"License :: OSI Approved :: Apache Software License",
58+
"Operating System :: POSIX :: Linux",
59+
"Programming Language :: Python :: 3",
60+
"Programming Language :: Python :: 3.6",
61+
"Programming Language :: Python :: 3.7",
62+
"Programming Language :: Python :: 3.8",
63+
"Programming Language :: Python :: 3.9",
64+
"Programming Language :: Python :: 3.10",
65+
],
66+
packages=find_packages(exclude=["cloudevents.tests"]),
67+
version=pypi_config["version_target"],
68+
install_requires=["deprecation>=2.0,<3.0"],
69+
)

0 commit comments

Comments
 (0)