pynamer.utils

Collection of package support utilities.

Functions

check_integrity(→ None)

reset(→ None)

feedback(→ None)

Generates a formatted messages appropriate to the message type.

search_json(→ str)

Searches a json data structure for a GitHub project URL.

find_pypirc_file(→ None)

Function to iterate over paths in the PATH environment variable to find a file.

generate_pypi_index(→ None)

Generates a list of projects in PyPI's simple index - writes results to a file.

check_version(→ None)

Utility function to compare package version against latest version on PyPI.

process_input_file(→ list[Union[str, Any]])

Processes the contents of the file to a list of strings.

write_output_file(→ None)

Write the results to a file.

Module Contents

pynamer.utils.check_integrity() None[source]
pynamer.utils.reset() None[source]
pynamer.utils.feedback(message: str, feedback_type: str) None[source]

Generates a formatted messages appropriate to the message type.

Parameters:
  • message – text to be echoed.

  • feedback_type – identifies type of message to display.

pynamer.utils.search_json(json_data: dict, project_name: str) str[source]

Searches a json data structure for a GitHub project URL.

The json data is found from the PyPI json URL: “https://pypi.org/pypi/package_name”. The function searches for the GitHub homepage URL:

https://github.com/{owner}/{package_name} and returns upon first match.

Args:

json_data: json found from PyPI. project_name: the package name under test.

Returns:

the GitHub homepage URL if found else an empty string.

Return type:

str

pynamer.utils.find_pypirc_file(filename: str = '.pypirc') None[source]

Function to iterate over paths in the PATH environment variable to find a file.

Designed to find a .pypirc file starting with the current working directory. If identified will update the config.pypirc variable, so it can be used elsewhere.

Parameters:

filename – filename to find.

pynamer.utils.generate_pypi_index() None

Generates a list of projects in PyPI’s simple index - writes results to a file.

Raises:

SystemExit – if any requests.RequestException occurs.

Notes

A potentially expensive operation as there are almost 500,000 projects to process. Can take 2-3 seconds. Look to improve performance at a later date: look at asyncio, asyncio.http etc. An improvement is to automatically periodically run this in the background.

pynamer.utils.check_version() None

Utility function to compare package version against latest version on PyPI.

Returns:

version of the installed package. str: message concerning the result of the comparison. bool: True: if the installed package is up-to-date.

False: if there is a newer version on PyPI.

Return type:

current_version

Raises:

SystemExit – if any requests.RequestException occurs.

pynamer.utils.process_input_file(file: str) list[str | Any]

Processes the contents of the file to a list of strings.

Parameters:

file – simple string for the file.

Raises:

SystemExit – if there is an error opening the file.

Notes

File contents should contain any number of space separated strings on any number of lines.

pynamer.utils.write_output_file(file_name: str, results: dict) None

Write the results to a file.

Parameters:
  • file_name – name of file to save as a simple string.

  • results – dictionary containing the test results e.g. {“pynball”: [1, 1, 1]}

Raises:

SystemExit – if there is an error opening the file.