
    3j                       d dl mZ g dZd dlZd dlmZ d dlZd dlZd dlZd dl	Z	 ej                  deej                  z        ZddZddZdd	Zdd
ZddZdddZedd	 	 	 dd       Zedd	 	 	 dd       Ze	 	 	 	 dd       Ze	 	 	 	 dd       Zdd	 	 	 ddZ G d de	j*                        Zedk(  rd dlZ ej2                  e       yy)    )annotations)getRootFilePathgetSourceFilePathgetMetadataCacheFilePathgetCorpusFilePathgetCorpusContentDirsrelativepath	cleanpathN)overload	StrOrPath)boundc                     t        j                  t        j                  t                    j                         } | j                  j                  }d|j                         D cg c]  }|j                   c}vrt        d|       |S c c}w )z
    Get the music21 directory that contains source files such as note.py, etc.
    This is not the same as the
    outermost package development directory.
    streamz(cannot find expected music21 directory: )
pathlibPathinspectgetfiler   resolveparentiterdirnameFileNotFoundError)fpThis	fpMusic21xs      E/DATA/.local/lib/python3.12/site-packages/music21/common/pathTools.pyr   r   !   s~     \\'//*;<=EEGF$$I	(9(9(;<(;1(;<<6ykB
 	
 	 =s   $Bc                 "    t               dz  dz  S )z
    Get the stored music21 directory that contains the corpus metadata cache.

    >>> fp = common.getMetadataCacheFilePath()
    >>> fp.name == '_metadataCache' and fp.parent.name == 'corpus'
    True
    corpus_metadataCache)r        r   r   r   1   s     ),<<<r!   c                     ddl m}  | j                  j                         }|j                  t               dz  S t        j                  |j                        S )z
    Get the stored music21 directory that contains the corpus metadata cache.

    >>> fp = common.getCorpusFilePath()
    >>> fp.name == 'corpus' and fp.parent.name == 'music21'
    True
    r   )r   r   )music21r   corpora
CoreCorpusmanualCoreCorpusPathr   r   r   )r   
coreCorpuss     r   r   r   <   sH     **,J&&. "X--<<
7788r!   c                     t               } g }d}t        t        j                  |             D ]<  }|j	                  d      r|j                  d      r'||v r,|j                  |       > t        |      S )a"  
    Get all dirs that are found in the CoreCorpus that contain content;
    that is, exclude dirs that have code or other resources.

    >>> fp = common.getCorpusContentDirs()
    >>> fp  # this list will be fragile, depending on composition of dirs
    ['airdsAirs', 'bach', 'beach', 'beethoven', 'chopin',
     'ciconia', 'corelli', 'cpebach',
     'demos', 'essenFolksong', 'handel', 'haydn', 'johnson_j_r', 'joplin', 'josquin',
     'leadSheet', 'liliuokalani', 'luca', 'lusitano',
     'miscFolk', 'monteverdi', 'mozart',
     'nottingham-dataset',
     'oneills1850', 'palestrina',
     'ryansMammoth', 'schoenberg', 'schubert', 'schumann_clara', 'schumann_robert',
     'theoryExercises', 'trecento', 'verdi', 'weber', 'webern']

    Make sure that all corpus data has a directoryInformation tag in
    CoreCorpus.

    >>> cc = corpus.corpora.CoreCorpus()
    >>> failed = []
    >>> di = [d.directoryName for d in cc.directoryInformation]
    >>> for f in fp:
    ...     if f not in di:
    ...         failed.append(f)
    >>> failed
    []
    )zlicense.txtr   __pycache__)z.pyz.pyc.)r   sortedoslistdirendswith
startswithappend)directoryNameresultexcludedNamesfilenames       r   r   r   K   sw    : &'MFM 2::m45_-  %&h 6 &>r!   c                 2    t               } | j                  }|S )a  
    Return the root directory for music21 -- outside the music21 namespace
    which has directories such as "dist", "documentation", "music21"

    >>> fp = common.getRootFilePath()
    >>> #_DOCS_SHOW fp
    PosixPath('/Users/florencePrice/git/music21')
    )r   r   )r   fpParents     r   r   r   |   s     "#IHOr!   c                X    ddl }|dk(  r| S t        j                  j                  | |      S )a  
    A cross-platform wrapper for `os.path.relpath()`, which returns `path` if
    under Windows, otherwise returns the relative path of `path`.

    This avoids problems under Windows when the current working directory is
    on a different drive letter from `path`.
    r   NWindows)platformr,   pathrelpath)r:   startr9   s      r   r	   r	      s)     977??4''r!   )returnPathlibc                    y Nr    r:   r=   s     r   r
   r
           r!   c                    y r?   r    r@   s     r   r
   r
      rA   r!   c                    y r?   r    r@   s     r   r
   r
      rA   r!   c                    y r?   r    r@   s     r   r
   r
      rA   r!   c                  t        | t        j                        rt        |       } |d}n|d}t        j
                  j                  |       } t        j
                  j                  |       } t        j
                  j                  |       st        j
                  j                  |       } t        j
                  j                  |       } |s| S t        j                  |       S )a  
    Normalizes the path by expanding ~user on Unix, ${var} environmental vars
    (is this a good idea?), expanding %name% on Windows, normalizing path names
    (Windows turns backslashes to forward slashes), and finally if that file
    is not an absolute path, turns it from a relative path to an absolute path.

    v5 -- returnPathlib -- None (default) does not convert. False, returns a string,
    True, returns a pathlib.Path.
    TF)
isinstancer   r   strr,   r:   
expandusernormpathisabsabspath
expandvarsr@   s     r   r
   r
      s     $%4y  M		77d#D77D!D77==wwt$77d#D||D!!r!   c                      e Zd Zd Zy)Testc                X    t               }| j                  |t        j                         y r?   )r   assertIsInstancer   r   )selffps     r   testGetSourcePathzTest.testGetSourcePath   s     b',,/r!   N)__name__
__module____qualname__rS   r    r!   r   rN   rN      s    0r!   rN   __main__)returnpathlib.Path)rX   z	list[str]r?   )r:   r   r<   z
str | NonerX   zStrOrPath | str)r:   rY   r=   t.Literal[None]rX   rY   )r:   rG   r=   rZ   rX   rG   )r:   str | pathlib.Pathr=   zt.Literal[True]rX   rY   )r:   r[   r=   zt.Literal[False]rX   rG   )r:   r[   r=   zbool | NonerX   r[   )
__future__r   __all__typingtr   r   r,   r   unittestTypeVarrG   r   r   r   r   r   r   r   r	   r
   TestCaserN   rT   r#   mainTestr    r!   r   <module>rd      sC   #    	  AIIkW\\)9:	 =9.b( 
/3,8D 
 
/3,8; 
 
,1= 
 
-25 

 *."&"2B":08 0 zGT r!   