K iV dZddlmZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z mZmZmZmZddlmZmZmZmZmZdd lmZdd lmZe rdd lmZdd lmZm Z ed Z!eddZ"eddZ#eddZ$GddZ%y)ztdistutils.cmd Provides the Command class, the base class for the command classes in the distutils.command package. ) annotationsN)abstractmethod)CallableMutableSequence) TYPE_CHECKINGAnyClassVarTypeVaroverload) _modified archive_utildir_util file_utilutillog)DistutilsOptionError Distribution) TypeVarTupleUnpack_Ts _StrPathTstr | os.PathLike[str])bound _BytesPathTbytes | os.PathLike[bytes] _CommandTCommandceZdZUdZgZded<gZded<d-dZdZd.dZ e d.d Z e d.d Z d/d Z e d.d Zej fd0dZd1dZd2dZd2d3dZd4dZd2dZd4dZd4dZd5dZ d6dZd7d8dZe d9 d:dZe d9 d;dZ d9 ddZd1dZ d? d@dZ!dAdBd Z"e dC dDd!Z#e dC dEd"Z# dC dFd#Z# dG dHd$Z$e dI dJd%Z%e dI dKd&Z% dI dLd'Z% dM dNd(Z&e dO dPd)Z'e dQ dRd*Z' dO dSd+Z' dT dUd,Z(y )Vr a}Abstract base class for defining command classes, the "worker bees" of the Distutils. A useful analogy for command classes is to think of them as subroutines with local variables called "options". The options are "declared" in 'initialize_options()' and "defined" (given their final values, aka "finalized") in 'finalize_options()', both of which must be defined by every command class. The distinction between the two is necessary because option values might come from the outside world (command line, config file, ...), and any options dependent on other options must be computed *after* these outside influences have been processed -- hence 'finalize_options()'. The "body" of the subroutine, where it does all its work based on the values of its options, is the 'run()' method, which must also be implemented by every command class. z8ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] sub_commandszHClassVar[list[tuple[str, str, str]] | list[tuple[str, str | None, str]]] user_optionscddlm}t||s td|jt ur t d||_|jd|_ |j|_ d|_ d|_ d|_ y)zCreate and initialize a new Command object. Most importantly, invokes the 'initialize_options()' method, which is the real initializer and depends on the actual command being instantiated. rrz$dist must be a Distribution instancezCommand is an abstract classNF)distutils.distr isinstance TypeError __class__r RuntimeError distributioninitialize_options_dry_runverboseforcehelp finalized)selfdistrs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/setuptools/_distutils/cmd.py__init__zCommand.__init__Ksz 0$ -BC C >>W $=> >  ! ||   ct|dk(r)t|d|z}|t|j|S|St|)Ndry_run_)getattrr*AttributeError)r1attrmyvals r3 __getattr__zCommand.__getattr__{sB 9 D#*-E}t00$77  & &r5cJ|js|jd|_y)NT)r0finalize_optionsr1s r3ensure_finalizedzCommand.ensure_finalizeds~~  ! ! #r5c4td|jd)aSet default values for all the options that this command supports. Note that these defaults may be overridden by other commands, by the setup script, by config files, or by the command-line. Thus, this is not the place to code dependencies between options; generally, 'initialize_options()' implementations are just a bunch of "self.foo = None" assignments. This method must be implemented by all command classes. abstract method -- subclass  must overrider)r(r@s r3r+zCommand.initialize_options"*4>>*:. I  r5c4td|jd)aSet final values for all the options that this command supports. This is always called as late as possible, ie. after any option assignments from the command-line or from other commands have been done. Thus, this is the place to code option dependencies: if 'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as long as 'foo' still has the same value it was assigned in 'initialize_options()'. This method must be implemented by all command classes. rCrDrEr@s r3r?zCommand.finalize_optionss"*4>>*:. I  r5Nc^ddlm}|d|jd}|j||ztj |dz}|j D]Y\}}}|j|}|ddk(r|dd}t||}|j||d |ztj [y) Nr) longopt_xlatezcommand options for 'z':)levelz =z = ) distutils.fancy_getoptrIget_command_nameannounceloggingINFOr# translater9)r1headerindentrIoptionr8values r3 dump_optionszCommand.dump_optionss8 >,T-B-B-D,ERHF fvoW\\ :$ -- NLFAq%%m4FbzS D&)E MM&fXS#88 M M  Nr5c4td|jd)aA command's raison d'etre: carry out the action it exists to perform, controlled by the options initialized in 'initialize_options()', customized by other commands, the setup script, the command-line, and config files, and finalized in 'finalize_options()'. All terminal output and filesystem interaction should be done by 'run()'. This method must be implemented by all command classes. rCrDrEr@s r3runz Command.runrFr5c0tj||yNr)r1msgrJs r3rOzCommand.announces sr5chddlm}|r*t|tjj yy)z~Print 'msg' to stdout if the global DEBUG (taken from the DISTUTILS_DEBUG environment variable) flag is true. r)DEBUGN)distutils.debugr^printsysstdoutflush)r1r\r^s r3 debug_printzCommand.debug_prints& *  #J JJ    r5c t||}|t||||St|tst d|d|d|d|S)N'z ' must be a z (got `z`))r9setattrr&strr)r1rUwhatdefaultvals r3_ensure_stringlikezCommand._ensure_stringlikesTdF# ; D&' *NC%&6(,tfGC5PR'ST T r5c*|j|d|y)zWEnsure that 'option' is a string; if not defined, set it to 'default'. stringN)rl)r1rUrjs r3 ensure_stringzCommand.ensure_strings ':r5ct||}|yt|tr"t||t j d|yt|t rtd|D}nd}|std|d|dy)zEnsure that 'option' is a list of strings. If 'option' is currently a string, we split it either on /,\s*/ or /\s+/, so "foo bar baz", "foo,bar,baz", and "foo, bar baz" all become ["foo", "bar", "baz"]. Nz,\s*|\s+c3<K|]}t|tywr[)r&rh).0vs r3 z-Command.ensure_string_list.. s9As+9sFrfz!' must be a list of strings (got )) r9r&rhrgresplitlistallr)r1rUrkoks r3ensure_string_listzCommand.ensure_string_lists dF# ;  S ! D&"((;"< =#t$9S99*x@qIr5cf|j|||}|||std|z||fzyy)Nzerror in '%s' option: )rlr)r1rUtesterri error_fmtrjrks r3_ensure_tested_stringzCommand._ensure_tested_stringsF%%fdG< ?6#;&)I5&#F $/?r5c\|j|tjjddy)z5Ensure that 'option' is the name of an existing file.filenamez$'%s' does not exist or is not a fileN)rospathisfiler1rUs r3ensure_filenamezCommand.ensure_filenames" "" BGGNNJ0V r5c\|j|tjjddy)Nzdirectory namez)'%s' does not exist or is not a directory)rrrisdirrs r3ensure_dirnamezCommand.ensure_dirnames$ ""  GGMM  7  r5c^t|dr |jS|jjS)N command_name)hasattrrr(__name__r@s r3rNzCommand.get_command_name(s( 4 ($$ $>>** *r5c |jj|}|j|D])\}}t||t ||t||+y)a>Set the values of any "undefined" options from corresponding option values in some other command object. "Undefined" here means "is None", which is the convention used to indicate that an option has not been changed between 'initialize_options()' and 'finalize_options()'. Usually called from 'finalize_options()' for options that depend on some other command rather than another option of the same command. 'src_cmd' is the other command from which option values will be taken (a command object will be created for it if necessary); the remaining arguments are '(src_option,dst_option)' tuples which mean "take the value of 'src_option' in the 'src_cmd' command object, and copy it to 'dst_option' in the current command object". N)r*get_command_objrAr9rg)r1src_cmd option_pairs src_cmd_obj src_option dst_options r3set_undefined_optionszCommand.set_undefined_options.s\"''77@ $$&&2 L "J tZ(0j'+z*JK Lr5c^|jj||}|j|S)zWrapper around Distribution's 'get_command_obj()' method: find (create if necessary and 'create' is true) the command object for 'command', call its 'ensure_finalized()' method, and return the finalized command object. )r*rrA)r1commandcreatecmd_objs r3get_finalized_commandzCommand.get_finalized_commandGs- ##33GVD  "r5cyr[r1rreinit_subcommandss r3reinitialize_commandzCommand.reinitialize_commandSsr5cyr[rrs r3rzCommand.reinitialize_commandWsr5c:|jj||Sr[)r*rrs r3rzCommand.reinitialize_command[s  55g?QRRr5c:|jj|y)zRun some other command: uses the 'run_command()' method of Distribution, which creates and finalizes the command object if necessary and then invokes its 'run()' method. N)r* run_command)r1rs r3rzCommand.run_command`s %%g.r5cjg}|jD]!\}}| ||s|j|#|S)akDetermine the sub-commands that are relevant in the current distribution (ie., that need to be run). This is based on the 'sub_commands' class attribute: each tuple in that list may include a method that we call to determine if the subcommand needs to be run for the current distribution. Return a list of command names. )r"append)r1commandscmd_namemethods r3get_sub_commandszCommand.get_sub_commandsgsA $ 1 1 * Hf~) *r5cNtjd|j|y)Nzwarning: %s: %s )rwarningrN)r1r\s r3warnz Command.warnvs ')>)>)@#Fr5cJtj||||jyNr7)rexecuter7)r1funcargsr\rJs r3rzCommand.executeys T4dll;r5cHtj|||jyr)rmkpathr7)r1namemodes r3rzCommand.mkpathsdDLL9r5cyr[rr1infileoutfile preserve_modepreserve_timeslinkrJs r3 copy_filezCommand.copy_files(+r5cyr[rrs r3rzCommand.copy_files,/r5c dtj|||||j ||jS)zCopy a file respecting verbose, dry-run and force flags. (The former two default to whatever is in the Distribution object, and the latter defaults to false for commands that don't define it.)r)rrr.r7rs r3rzCommand.copy_files6""     N LL  r5c dtj||||||j |jS)z\Copy an entire directory tree respecting verbose, dry-run, and force flags. r)r copy_treer.r7)r1rrrrpreserve_symlinksrJs r3rzCommand.copy_trees6!!      NLL  r5cyr[rr1srcdstrJs r3 move_filezCommand.move_filesr5cyr[rrs r3rzCommand.move_files"r5cFtj|||jS)z$Move a file respecting dry-run flag.r)rrr7rs r3rzCommand.move_files""3T\\BBr5c:ddlm}||||jy)z2Spawn an external command respecting dry-run flag.r)spawnrN)distutils.spawnrr7)r1cmd search_pathrJrs r3rz Command.spawns * c; 5r5cyr[rr1 base_nameformatroot_dirbase_dirownergroups r3 make_archivezCommand.make_archiver5cyr[rrs r3rzCommand.make_archiverr5c Ntj|||||j||S)N)r7rr)rrr7rs r3rzCommand.make_archives0((    LL  r5c\|d|d}t|tr|f}n!t|ttfs t d|!dj |dj |}|jstj||r|j||||ytj|y)aSpecial case of 'execute()' for operations that process one or more input files and generate one output file. Works just like 'execute()', except the operation is skipped and a different message printed if 'outfile' already exists and is newer than all files listed in 'infiles'. If the command defined 'self.force', and it is true, then the command is unconditionally run -- does no timestamp checks. Nz skipping z (inputs unchanged)z9'infiles' must be a string, or a list or tuple of stringszgenerating {} from {}z, ) r&rhrxtupler'rjoinr.r newer_grouprrdebug)r1infilesrrrexec_msgskip_msgrJs r3 make_filezCommand.make_files$  "7)+>?H gs #jGGdE]3WX X  .55gtyy?QRH ::..w@ LLtXu 5 IIh r5)r2rreturnNone)rr)N)r\objectrJintrr)r\rrrr[)rUrhrj str | Nonerr)rUrhrr)rrh)rrhrztuple[str, str]rr)T)rrhrboolrr )F)rrhrrrr )rrrrrr)rz str | Commandrr )rrhrr)r list[str])Nr ) rCallable[[Unpack[_Ts]], object]rtuple[Unpack[_Ts]]r\rrJrrr)i)rrhrrrr)TTNr )rrrrrrrrrrrJrrztuple[_StrPathT | str, bool])rrrrrrrrrrrJrrz tuple[_BytesPathT | bytes, bool])r3str | os.PathLike[str] | bytes | os.PathLike[bytes]rrrrrrrrrJrrz@tuple[str | os.PathLike[str] | bytes | os.PathLike[bytes], bool])TTFr )rrrrhrrrrrrrJrrr)r )rrrrrJrrz_StrPathT | str)rrrrrJrrz_BytesPathT | bytes)rrrrrJrrr)Tr )rzMutableSequence[str]rrrJrrr)NNNN)rrhrrhr:str | os.PathLike[str] | bytes | os.PathLike[bytes] | Nonerrrrrrrrh)NNN)rrrrhrrrrrrrrrrh)rrrrhrrrrrrrrrrh)NNr )rz!str | list[str] | tuple[str, ...]rrrrrrrrrrrJrrr))r __module__ __qualname____doc__r"__annotations__r#r4r=rArr+r?rWrYrPr^rOrdrlror{rrrrNrrr rrrrrrrrrrrrrr5r3r r "s| >    -`'$         N    29.; *  + LL+:L L27<04 =B 6: :?S$S S / G <-<!< <  <  <: ##+&++ +  +  ++ &++ ##/*// /  /  // *//## C E         J 4##"' &           ,HI)09BE NO"-"4?"HK" "" C @CAC C = CQR6'66:6JM6 6 PT#  M       $  )F      PT#   )  M         2 % 2% E% . % ! %  % % %  % r5)&r __future__rrPrrvraabcrcollections.abcrrtypingrrr r r rr rrrr_logrerrorsrr%rtyping_extensionsrrrrrrr rr5r3rsx # 5BB@@(+6 u C K'? @ m+GH Ky 1 H H r5