code: def safe_version(version: str) -> str:
      """Convert an arbitrary string into a valid version string.
      Can still raise an ``InvalidVersion`` exception.
      To avoid exceptions use ``best_effort_version``.
      >>> safe_version("1988 12 25")
      '1988.12.25'
      >>> safe_version("v0.2.1")
      '0.2.1'
      >>> safe_version("v0.2?beta")
      '0.2b0'
      >>> safe_version("v0.2 beta")
      '0.2b0'
      >>> safe_version("ubuntu lts")
      Traceback (most recent call last):
      ...
      setuptools.extern.packaging.version.InvalidVersion: Invalid version: 'ubuntu.lts'
      """
      v = version.replace(" ", ".")
      try:
          return str(packaging.version.Version(v))
      except packaging.version.InvalidVersion:
          attempt = _UNSAFE_NAME_CHARS.sub("-", v)
          return str(packaging.version.Version(attempt))
  
file_path: catboost/contrib/python/setuptools/py3/setuptools/_normalization.py
imports: import re
  from pathlib import Path
  from typing import Union
  from .extern import packaging
label_desc: Use image node_id 3 for calling a global function with example usage: safe_version(version) and returns: str, str