Skip to content

Commit 73b60b0

Browse files
author
Oscar Pacheco
committed
WL#16954: Make sdist packages pip installable
Classic and XDevAPI connector Python source distribution (sdist) name was updated to comply with [PEP 625](https://peps.python.org/pep-0625/). Additionally, setup.py was updated to make sure metadata files are correctly included in the sdist when generated. Ultimately, to make the sdist pip installable. Change-Id: I0de7f1657ef9f5539f93139eff9881c23957273b
1 parent 7dd0f81 commit 73b60b0

File tree

7 files changed

+45
-48
lines changed

7 files changed

+45
-48
lines changed

.gitignore

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,16 @@ docs
2424
dist
2525
build
2626

27-
# Classic protocol connector (aka mysql)
28-
mysql-connector-python/build/
29-
mysql-connector-python/dist/
30-
mysql-connector-python/docs/INFO_BIN
31-
mysql-connector-python/docs/INFO_SRC
32-
mysql-connector-python/lib/mysql/vendor/
33-
mysql-connector-python/tests_*.log
34-
mysql-connector-python/README.txt
35-
mysql-connector-python/README.rst
36-
mysql-connector-python/LICENSE.txt
37-
mysql-connector-python/CHANGES.txt
38-
39-
# X protocol connector (aka XDevAPI or mysqlx)
40-
mysqlx-connector-python/build/
41-
mysqlx-connector-python/dist/
42-
mysqlx-connector-python/docs/INFO_BIN
43-
mysqlx-connector-python/docs/INFO_SRC
44-
mysqlx-connector-python/src/mysqlxpb/mysqlx/mysqlx*
45-
mysqlx-connector-python/README.txt
46-
mysqlx-connector-python/README.rst
47-
mysqlx-connector-python/LICENSE.txt
48-
mysqlx-connector-python/CHANGES.txt
49-
27+
# Classic/XDevAPI protocol connector (aka mysql)
28+
mysql*-connector-python/build/
29+
mysql*-connector-python/dist/
30+
mysql*-connector-python/docs/INFO_BIN
31+
mysql*-connector-python/docs/INFO_SRC
32+
mysql*-connector-python/lib/mysql/vendor/
33+
mysql*-connector-python/tests_*.log
34+
mysql*-connector-python/README.txt
35+
mysql*-connector-python/README.rst
36+
mysql*-connector-python/LICENSE.txt
37+
mysql*-connector-python/CHANGES.txt
38+
mysql*-connector-python/CONTRIBUTING.md
39+
mysql*-connector-python/SECURITY.md

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v9.4.0
1414
- WL#16966: Upgrade Python lz4 version
1515
- WL#16963: Update the OpenTelemetry version
1616
- WL#16962: Update the Python Protobuf version
17+
- WL#16954: Make sdist packages pip installable
1718
- BUG#37868219: RPM packages have incorrect copyright year in their metadata
1819
- BUG#37859771: mysql/connector python version 9.3.0 has a regression which cannot persist binary data with percent signs in it
1920
- BUG#37820231: Text based django ORM filters doesn't work with Connector/Python

mysql-connector-python/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include LICENSE.txt
44
include CONTRIBUTING.md
55
include SECURITY.md
66
include CHANGES.txt
7+
include src/version_info.rc
78
include setup.py
89
include unittests.py
910
include MANIFEST.in

mysql-connector-python/cpydist/sdist.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ def finalize_options(self):
108108
"""Finalize the options."""
109109

110110
def _get_fullname():
111-
name = self.distribution.get_name()
112-
label = f"-{self.label if self.label else ''}"
111+
# Comply with [PEP 625](https://peps.python.org/pep-0625/).
112+
# Use the normalized project name 'mysql_connector_python'.
113+
distribution = self.distribution.get_name().replace("-", "_")
114+
label = f"-{self.label}" if self.label else ""
113115
version = self.distribution.get_version()
114116
edition = self.edition or ""
115-
return f"{name}{label}-{version}{edition}"
117+
return f"{distribution}{label}-{version}{edition}"
116118

117119
self.distribution.get_fullname = _get_fullname
118120
sdist.finalize_options(self)

mysql-connector-python/setup.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,19 @@ def copy_metadata_files() -> None:
171171
parent directory to the current directory.
172172
"""
173173
for filename in METADATA_FILES:
174-
shutil.copy(pathlib.Path(os.getcwd(), f"../{filename}"), pathlib.Path(f"./"))
174+
# if file is not in current directory, then try to load it from one level above
175+
if not os.path.exists(
176+
pathlib.Path(os.getcwd(), f"./{filename}")
177+
) and os.path.exists(pathlib.Path(os.getcwd(), f"../{filename}")):
178+
shutil.copy(
179+
pathlib.Path(os.getcwd(), f"../{filename}"), pathlib.Path(f"./")
180+
)
175181

176182

177183
def get_long_description() -> str:
178184
"""Extracts a long description from the README.rst file that is suited for this specific package.
179185
"""
180-
with open(pathlib.Path(os.getcwd(), "../README.rst")) as file_handle:
186+
with open(pathlib.Path(os.getcwd(), "./README.rst")) as file_handle:
181187
# The README.rst text is meant to be shared by both mysql and mysqlx packages, so after getting it we need to
182188
# parse it in order to remove the bits of text that are not meaningful for this package (mysql)
183189
long_description = file_handle.read()
@@ -223,10 +229,4 @@ def remove_metadata_files() -> None:
223229

224230
if __name__ == "__main__":
225231
copy_metadata_files()
226-
227-
try:
228-
main()
229-
except Exception as err:
230-
raise err
231-
finally:
232-
remove_metadata_files()
232+
main()

mysqlx-connector-python/cpydist/sdist.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ def finalize_options(self):
108108
"""Finalize the options."""
109109

110110
def _get_fullname():
111-
name = self.distribution.get_name()
112-
label = f"-{self.label if self.label else ''}"
111+
# Comply with [PEP 625](https://peps.python.org/pep-0625/).
112+
# Use the normalized project name 'mysql_connector_python'.
113+
distribution = self.distribution.get_name().replace("-", "_")
114+
label = f"-{self.label}" if self.label else ""
113115
version = self.distribution.get_version()
114116
edition = self.edition or ""
115-
return f"{name}{label}-{version}{edition}"
117+
return f"{distribution}{label}-{version}{edition}"
116118

117119
self.distribution.get_fullname = _get_fullname
118120
sdist.finalize_options(self)

mysqlx-connector-python/setup.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,19 @@ def copy_metadata_files() -> None:
173173
parent directory to the current directory.
174174
"""
175175
for filename in METADATA_FILES:
176-
shutil.copy(pathlib.Path(os.getcwd(), f"../{filename}"), pathlib.Path(f"./"))
176+
# if file is not in current directory, then try to load it from one level above
177+
if not os.path.exists(
178+
pathlib.Path(os.getcwd(), f"./{filename}")
179+
) and os.path.exists(pathlib.Path(os.getcwd(), f"../{filename}")):
180+
shutil.copy(
181+
pathlib.Path(os.getcwd(), f"../{filename}"), pathlib.Path(f"./")
182+
)
177183

178184

179185
def get_long_description() -> str:
180-
"""Extracts a long description from the README.rst file that is suited for this specific package."""
181-
with open(pathlib.Path(os.getcwd(), "../README.rst")) as file_handle:
186+
"""Extracts a long description from the README.rst file that is suited for this specific package.
187+
"""
188+
with open(pathlib.Path(os.getcwd(), "./README.rst")) as file_handle:
182189
# The README.rst text is meant to be shared by both mysql and mysqlx packages, so after getting it we need to
183190
# parse it in order to remove the bits of text that are not meaningful for this package (mysqlx)
184191
long_description = file_handle.read()
@@ -229,10 +236,4 @@ def remove_metadata_files() -> None:
229236

230237
if __name__ == "__main__":
231238
copy_metadata_files()
232-
233-
try:
234-
main()
235-
except Exception as err:
236-
raise err
237-
finally:
238-
remove_metadata_files()
239+
main()

0 commit comments

Comments
 (0)