o
    $%[b~                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZdZ	dd Z
d	d
 Zdd Zdd ZedkrAeej dS dS )zEnables use of Python Fire as a "main" function (i.e. "python -m fire").

This allows using Fire with third-party libraries without modifying their code.
    )absolute_import)division)print_functionNa  usage: python -m fire [module] [arg] ..."

Python Fire is a library for creating CLIs from absolutely any Python
object or program. To run Python Fire from the command line on an
existing Python file, it can be invoked with "python -m fire [module]"
and passed a Python module using module notation:

"python -m fire packageA.packageB.module"

or with a file path:

"python -m fire packageA/packageB/module.py" c                 C   s   t j| s
tdt j| }tjjdkr-tjjdk r-t	j
j|| d}||}||fS tjjdkrVddl	m} ||| }|du rGtd||}|j| ||fS ddl}||| }||fS )	aL  Performs a module import given the filename.

  Args:
    path (str): the path to the file to be imported.

  Raises:
    IOError: if the given file does not exist or importlib fails to load it.

  Returns:
    Tuple[ModuleType, str]: returns the imported module and the module name,
      usually extracted from the path itself.
  zGiven file path does not exist.      )fullnamepathr   )utilNz*Unable to load module from specified path.)osr   existsIOErrorbasenamesysversion_infomajorminor	importlib	machinerySourceFileLoaderload_moduler	   spec_from_file_locationmodule_from_specloaderexec_moduleimpZload_source)r   module_namer   moduler	   specr    r   =D:\Projects\ConvertPro\env\Lib\site-packages\fire\__main__.pyimport_from_file_path-   s*   

r    c                 C   s   t | }|| fS )z-Imports a module and returns it and its name.)r   import_module)r   r   r   r   r   import_from_module_nameY   s   
r"   c                 C   s\   t j| r | dszt| W S  ty   tdw t| S t jj| v r*t	dt| S )a  Imports a given module or filename.

  If the module_or_filename exists in the file system and ends with .py, we
  attempt to import it. If that import fails, try to import it as a module.

  Args:
    module_or_filename (str): string name of path or module.

  Raises:
    ValueError: if the given file is invalid.
    IOError: if the file or module can not be found or imported.

  Returns:
    Tuple[ModuleType, str]: returns the imported module and the module name,
      usually extracted from the path itself.
  z.pyz%Fire can only be called on .py files.z4Fire was passed a filename which could not be found.)
r
   r   r   endswithr"   ImportError
ValueErrorr    sepr   )module_or_filenamer   r   r   r!   _   s   

r!   c                 C   sN   t | dk rtt td | d }t|\}}tj||| dd d dS )zAEntrypoint for fire when invoked as a module with python -m fire.      N)namecommand)lenprint
cli_stringr   exitr!   fireZFire)argsr'   r   r   r   r   r   main   s   
r2   __main__)__doc__Z
__future__r   r   r   r   r
   r   r0   r.   r    r"   r!   r2   __name__argvr   r   r   r   <module>   s    ,"