o
    KeU                     @   sL   d Z ddlZdd ZdddZddd	Zd
d Zdd Zdd Zdd ZdS )a)  yolklib.

Desc: Library for getting information about Python packages installed by
      setuptools, package metadata, package dependencies, and querying
      The CheeseShop (PYPI) for Python package release information.


Author: Rob Cakebread <cakebread @ gmail>

License  : BSD (See COPYING)

    Nc                 C   s   t  }| |v r
dS dS )z}Return True if distribution is active.

    @param dist: pkg_resources Distribution object

    @returns: True or False

    TF)pkg_resources
WorkingSet)distworking_set r   D/home/ubuntu/flask/venv/lib/python3.10/site-packages/yolk/yolklib.pyquery_activated   s   r    c           	      c   s    t  }t  }t| ||D ]?\}}|j}||j D ]2}||jkrM| dkr2||vr2|t|fV  q| dkrB||v rB|t|fV  q| dkrM|t|fV  qqdS )a  Yield installed packages.

    @param show: Type of package(s) to show; active, non-active or all
    @type show: string: "active", "non-active", "all"

    @param pkg_name: PyPI project name
    @type pkg_name: string

    @param version: project's PyPI version
    @type version: string

    @returns: yields tuples of distribution and True or False depending
              on active state. e.g. (dist, True)

    	nonactiveactiveallN)r   Environmentr   	get_alphaversionproject_namer   )	showpkg_namer   environmentr   namer   verpackager   r   r   get_distributions    s    
r   c                 C   sT   g }t | D ]}|r|j|krq|r|j|krq||j|j |f q|  |S )al  Return list of alphabetized packages.

    @param pkg_name: PyPI project name
    @type pkg_name: string

    @param version: project's PyPI version
    @type version: string

    @returns: Alphabetized list of tuples. Each tuple contains
              a string and a pkg_resources Distribution object.
              The string is the project name + version.

    )get_packagesr   r   appendsort)r   r   r   
alpha_listr   r   r   r   r   ?   s   r   c                 C   sf   | dks| dkr/g }t  }|D ]}tt|| D ]}|| | r+||| |  qq|S t  S )zReturn list of Distributions filtered by active status or all.

    @param show: Type of package(s) to show; active, non-active or all
    @type show: string: "active", "non-active", "all"

    @returns: list of pkg_resources Distribution objects

    r
   r   )r   r   rangelenr   r   )r   all_packagesr   r   ir   r   r   r   [   s   	r   c                 C   s&   t  }t||  r||  d jS dS )zReturn case-sensitive package name given any-case package name.

    @param project_name: PyPI project name
    @type project_name: string

    r   N)r   r   r   r   )package_namer   r   r   r   case_sensitive_namer   s   r!   c                 C   s   t  }||  d jS )zReturn highest version of installed package.

    @param project_name: PyPI project name
    @type project_name: string

    @return: string of highest installed version

    r   )r   r   r   )r   r   r   r   r   get_highest_installed~   s   	r"   c                 C   s>   g }| D ]}| t||f qttt|}|d d S )a  Return highest available version for a package in a list of versions.

    Uses pkg_resources to parse the versions.

    @param versions: List of PyPI package versions
    @type versions: List of strings

    @returns: string of a PyPI package version

    r      )r   r   parse_versionlistreversedsorted)versionssorted_versionsr   r   r   r   get_highest_version   s
   r*   )r	   r	   )	__doc__r   r   r   r   r   r!   r"   r*   r   r   r   r   <module>   s    

