MCPcopy Create free account
hub / github.com/mysql/mysql-connector-python / get_long_description

Function get_long_description

mysqlx-connector-python/setup.py:187–229  ·  view source on GitHub ↗

Extracts a long description from the README.rst file that is suited for this specific package.

()

Source from the content-addressed store, hash-verified

185
186
187def get_long_description() -> str:
188 """Extracts a long description from the README.rst file that is suited for this specific package."""
189 with open(pathlib.Path(os.getcwd(), "./README.rst")) as file_handle:
190 # The README.rst text is meant to be shared by both mysql and mysqlx packages, so after getting it we need to
191 # parse it in order to remove the bits of text that are not meaningful for this package (mysqlx)
192 long_description = file_handle.read()
193 block_matches = re.finditer(
194 pattern=(
195 r"(?P<module_start>\.{2}\s+={2,}\s+(?P<module_tag>\<(?P<module_name>mysql|mysqlx|both)\>)(?P<repls>\s+"
196 r'\[(?:(?:,\s*)?(?:repl(?:-mysql(?:x)?)?)\("(?:[^"]+)",\s*"(?:[^"]*)"\))+\])?\s+={2,})'
197 r"(?P<block_text>.+?(?=\.{2}\s+={2,}))(?P<module_end>\.{2}\s+={2,}\s+\</(?P=module_name)\>\s+={2,})"
198 ),
199 string=long_description,
200 flags=re.DOTALL,
201 )
202 for block_match in block_matches:
203 if block_match.group("module_name") == "mysql":
204 long_description = long_description.replace(block_match.group(), "")
205 else:
206 block_text = block_match.group("block_text")
207 if block_match.group("repls"):
208 repl_matches = re.finditer(
209 pattern=r'(?P<repl_name>repl(?:-mysql(?:x)?)?)\("'
210 r'(?P<repl_source>[^"]+)",\s*"(?P<repl_target>[^"]*)"\)+',
211 string=block_match.group("repls"),
212 )
213 for repl_match in repl_matches:
214 repl_name = repl_match.group("repl_name")
215 repl_source = repl_match.group("repl_source")
216 repl_target = repl_match.group("repl_target")
217 if repl_target is None:
218 repl_target = ""
219 if repl_name == "repl" or repl_name.endswith("mysqlx"):
220 block_text = block_text.replace(repl_source, repl_target)
221 long_description = long_description.replace(block_match.group(), block_text)
222 # Make replacements for files that are directly accessible within GitHub but not within PyPI
223 files_regex_fragment = "|".join(mf.replace(".", r"\.") for mf in METADATA_FILES)
224 long_description = re.sub(
225 pattern=rf"\<(?P<file_name>{files_regex_fragment})\>",
226 repl=f"<{GITHUB_URL}/blob/trunk/\g<file_name>>",
227 string=long_description,
228 )
229 return long_description
230
231
232def remove_metadata_files() -> None:

Callers 1

mainFunction · 0.70

Calls 1

readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…