pynamer.validators

Collection of functions to test availability of a package name on PyPI

Functions

is_valid_package_name(→ bool)

Function does a basic check of project name validity.

get_homepage(→ tuple[str, str])

Finds the GitHub homepage from the PyPI json data.

github_meta(→ str)

Finds GitHub statistics given a GitHub Homepage URL.

ping_project(→ bool)

Determines if the URL to the project exists in PyPIs project area.

ping_json(→ str)

Collects some PyPI details about the project if it exists.

pypi_search_index(→ bool)

Open the generated index file and search for the project name.

pypi_search(→ tuple[list[list[Union[str, Any]]], ...)

Performs a get request to PyPI's search API for the project name.

final_analysis(→ None)

Displays a rich console table displaying the conclusion of the test results

Module Contents

pynamer.validators.is_valid_package_name(project_name: str) bool[source]

Function does a basic check of project name validity.

Parameters:

project_name – the name of the project to test.

Returns:

If the name passes the basic check False: If the name fails the basic check

Return type:

True

pynamer.validators.get_homepage(project_json: dict, project_name: str) tuple[str, str][source]

Finds the GitHub homepage from the PyPI json data.

With this function we are trying to ultimately find the GitHub ‘homepage’: https://github.com/{username}/{project_name}. Unfortunately not everyone agrees what the homepage should be. Some people for example use ‘readthedocs’ or ‘github.io’ etc.

Parameters:
  • project_json – json data from PyPI json URL.

  • project_name – package name under test.

Returns:

strings containing found homepage URL.

Return type:

tuple[str, str]

pynamer.validators.github_meta(url: str) str[source]

Finds GitHub statistics given a GitHub Homepage URL.

Parameters:

url – GitHub homepage URL.

Returns:

a string containing all the pertinent statistics:

Return type:

str

pynamer.validators.ping_project(project_name: str) bool

Determines if the URL to the project exists in PyPIs project area.

Parameters:

project_name – the name of the project to test.

Returns:

if the URLs response code is 200. False: if the URLs response code is not 200.

Return type:

True

Raises:

SystemExit – if any requests.RequestException occurs.

pynamer.validators.ping_json(project_name: str, stats: bool = False) str

Collects some PyPI details about the project if it exists.

Parameters:
  • project_name – the name of the project to test.

  • stats – display stats from github json url.

Raises:

SystemExit – if any requests.RequestException occurs.

pynamer.validators.pypi_search_index(project_name: str) bool[source]

Open the generated index file and search for the project name.

Parameters:

project_name – the name of the project currently under test.

Returns:

a match was found. False: a match was not found.

Return type:

True

Performs a get request to PyPI’s search API for the project name.

Parameters:

search_project – the name of the project currently under test.

Returns:

a list of projects matching name comprising:

[project_name, version, released, description]

others: a list of projects not matching but PyPI thinks are relevant.

[project_name, version, released, description]

others_total: a str representation of total projects found (minus matches).

Return type:

match

pynamer.validators.final_analysis(pattern: list[int]) None[source]

Displays a rich console table displaying the conclusion of the test results

Parameters:

pattern – a list of the test results: 1 - a ‘negative’ result, indicating the project has been found. 0 - a ‘positive’ result, indicating the project was not found.