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

Function get_long_description

mysql-connector-python/setup.py:181–223  ·  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

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