ML i%UdZddlmZddlZddlZddlmZddlmZddl m Z ddl m Z m Z mZmZmZddlmZee Zd ed <Gd d eZ d dd ZddZddZddZGddZddZddZy)z5Routines for finding the sources that mypy will check) annotationsN)Sequence)Final)FileSystemCache)PYTHON_EXTENSIONS BuildSourcematches_excludematches_gitignore mypy_path)Optionsr PY_EXTENSIONSceZdZdZy)InvalidSourceListzDException indicating a problem in the list of sources given to mypy.N)__name__ __module__ __qualname____doc__W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/find_sources.pyrrsNrrc 8|xs t}t||}g}|D]}tjj |}|j t r2|j|\}}|jt||d|i|j|r6|j|} | s|std|d|j| |jrtjj|nd} |jt|| d|S)ztFrom a list of source files/directories, makes a list of BuildSources. Raises InvalidSourceList on errors. Nz(There are no .py[i] files in directory '')r SourceFinderospathnormpathendswithr crawl_upappendrisdirfind_sources_in_dirrextendscripts_are_modulesbasename) pathsoptionsfscacheallow_empty_dirfindersourcesrnamebase_dir sub_sourcesmods rcreate_source_listr/s**G '7 +FG 9ww% == '#__T2ND( NN;tT4B C ]]4  44T:K'*RSWRXXY(Z[[ NN; ',3,G,G"''""4(TC NN;tS$7 8 9 Nrctjj|\}}ttD]\}}||k(s |dk7||fcS|dk7d|fS)zDetermines sort order for directory listing. The desirable properties are: 1) foo < foo.pyi < foo.py 2) __init__.py[i] < foo __init__)rrsplitext enumerater )r+basesuffixiexts rkeyfuncr9:sa77##D)LD&M*13 S=J&40 01 J D ))rc|stj}tjj|}|j tj r|dd}|S)Nr2)rcurdirrabspathrsep)roots rnormalise_package_baser?Hs@ yy 77??4 D }}RVVCRy Krc|jsyt|jztjgz}|Dcgc] }t |c}Scc}w)aReturns explicit package bases to use if the option is enabled, or None if disabled. We currently use MYPYPATH and the current directory as the package bases. In the future, when --namespace-packages is the default could also use the values passed with the --package-root flag, see #9632. Values returned are normalised so we can use simple string comparisons in SourceFinder.is_explicit_package_base N)explicit_package_basesr rgetcwdr?)r&rootsr>s rget_explicit_package_basesrDQsI  ) ) K'++ +ryy{m ;E5: ;T "4 ( ;; ;sAcbeZdZd dZd dZd dZd dZd dZejddZ ddZ y)rc||_t||_|j|_|j|_|j |_|j |_yN)r'rDrAnamespace_packagesexcludeexclude_gitignore verbosity)selfr'r&s rr1zSourceFinder.__init__bsJ &@&I#")"<"< !(!:!: **rcL|jsJt||jvSrG)rAr?)rLrs ris_explicit_package_basez%SourceFinder.is_explicit_package_basejs'****%d+t/J/JJJrc >g}t}t|jj|t}|D]`}|dvs|j drt jj||}t||j|j|jdk\rj|jr%t||j|jdk\r|jj|r7|j|}|s|j!||j#|t jj%|\}} ||vs| t&vs|j!||j)|\} } |j+t-|| d| c|S)N)key) __pycache__z site-packages node_modules.)setsortedr'listdirr9 startswithrrjoinr rIrKrJr r r!addr"r3r rrr) rLrr*seennamesr+subpathr-stemr6moduler,s rr!z SourceFinder.find_sources_in_dirnsRt||++D1w? QDGG4??[^K_ggll4.Gw dllDNNVWDWX%%*;t~~':+||!!'*"66w? HHTNNN;/!ww//5 ft#-(?HHTN'+}}W'=$FHNN;wh#OP/ Q2rctjj|}tjj|\}}t |xs|}|j |\}}|dk(r||fSt ||}||fS)a^Given a .py[i] filename, return module and base directory. For example, given "xxx/yyy/foo/bar.py", we might return something like: ("foo.bar", "xxx/yyy") If namespace packages is off, we crawl upwards until we find a directory without an __init__.py If namespace packages is on, we crawl upwards until the nearest explicit base directory. Failing that, we return one past the highest directory containing an __init__.py We won't crawl past directories with invalid package names. The base directory returned is an absolute path. r1)rrr<splitstrip_py crawl_up_dir module_join)rLrparentfilename module_name parent_moduler,r_s rrzSourceFinder.crawl_ups}wwt$77==.x(4H "&"3"3F"; x * $ (* *]K8xrc0|j|xsd|fS)N)_crawl_up_helper)rLdirs rrczSourceFinder.crawl_up_dirs$$S)6b#Y6rc|j|j|rd|fStjj |\}}|j d}|j |}|@|jst|d|j|\}}t|||fS|r|r|jsy|jsy|j|}|y|\}}t|||fS)aGiven a directory, maybe returns module and base directory. We return a non-None value if we were able to find something clearly intended as a base directory (as adjudicated by being an explicit base directory or by containing a package with __init__.py). This distinction is necessary for namespace packages, so that we know when to treat ourselves as a subpackage. Nrjz-stubsz# is not a valid Python package name) rArNrrra removesuffix get_init_file isidentifierrrcrdrHrk)rLrlrer+ init_file mod_prefixr,results rrkzSourceFinder._crawl_up_helpers   & & 2t7T7TUX7Ys7Nww}}S)   *&&s+  $$&(4&0S(TUU#'#4#4V#< Jz40(: :6):):)<&&&&v. > & H:t,h66rctD]i}tjj|d|z}|jj |r|cS|dk(sK|jj |sg|cSy)zCheck whether a directory contains a file named __init__.py[i]. If so, return the file's name (with dir prefixed). If not, return None. This prefers .pyi over .py (because of the ordering of PY_EXTENSIONS). r1z.pyN)r rrrYr'isfileinit_under_package_root)rLrlr8fs rrozSourceFinder.get_init_filese! C S*s"23A||""1%e| D DQ G   rN)r'rr&r returnNone)rstrrxbool)rrzrxlist[BuildSource])rrzrxtuple[str, str])rlrzrxr})rlrzrxztuple[str, str] | None)rlrzrx str | None) rrrr1rNr!rrc functools lru_cacherkrorrrrras=+K@ :7.7.7` rrc|r|dz|zS|S)z8Join module ids, accounting for a possibly empty parent.rSr)rechilds rrdrds |e## Lrc^tD]$}|j|s|dt| cSy)zVStrip a trailing .py or .pyi suffix. Return None if no such suffix is found. N)r rlen)argr8s rrbrbs7 $ << {#c(# #$ r)NF) r%z Sequence[str]r&r r'zFileSystemCache | Noner(r{rxr|)r+rzrxztuple[bool, int, str])r>rzrxrz)r&r rxzlist[str] | None)rerzrrzrxrz)rrzrxr~)r __future__rrrcollections.abcrtypingr mypy.fscachermypy.modulefinderrrr r r mypy.optionsr tupler __annotations__ Exceptionrr/r9r?rDrrdrbrrrrs;" $(!./ u/O O'+!   $   > * < KK\r