code: def modname_to_relpath(modname, project_root=None, add_init=True):
      
      parts = modname.split('.')
      relpath = pathlib.Path(*parts)
  
      # is the module a package? if so, the relpath identifies a directory
      # it is easier to check for whether a file is a directory than to try to
      # import the module dynamically and see whether it is a package
      if project_root is not None:
          relpath_resolved = pathlib.Path(project_root).joinpath(relpath)
      else:
          relpath_resolved = relpath
  
      if relpath_resolved.is_dir():
          if add_init:
              relpath = relpath.joinpath('__init__.py')
      else:
          relpath = str(relpath) + '.py'
  
      return str(relpath)
docs: Convert module name to relative path.
  
      The project root is usually needed to detect if the module is a package, in
      which case the relevant file is the `__init__.py` within the subdirectory.
  
      Example:
          >>> modname_to_relpath('foo.features')
          'foo/features.py'
          >>> modname_to_relpath('foo.features',
                                 project_root='/path/to/project')
          'foo/features/__init__.py'
  
      Args:
          modname (str): Module name, e.g. `os.path`
          project_root (str): Path to project root
          add_init (bool): Whether to add `__init__.py` to the path of modules
              that are packages. Defaults to True
  
      Returns:
          str