pyTooling.Packaging
A set of helper functions to describe a Python package for setuptools.
Hint
See high-level help for explanations and usage examples.
Variables
Functions
loadReadmeFile()
: Read the README file (e.g. in Markdown format), so it can be used as long description for the package.loadRequirementsFile()
: Reads a requirements.txt file (recursively) and extracts all specified dependencies into an array.extractVersionInformation()
: Extract double underscored variables from a Python source file, so these can be used for single-sourcing information.DescribePythonPackage()
: Helper function to describe a Python package.DescribePythonPackageHostedOnGitHub()
: Helper function to describe a Python package when the source code is hosted on GitHub.
Classes
Readme
: Encapsulates the READMEs file content and MIME type.VersionInformation
: Encapsulates version information extracted from a Python source file.
Variables
- pyTooling.Packaging.STATUS
A dictionary of supported development status values.
The mapping’s value will be appended to ``Development Status :: `` to form a package classifier.
Planning
Pre-Alpha
Alpha
Beta
Production/Stable
Mature
Inactive
See also
{'alpha': '3 - Alpha', 'beta': '4 - Beta', 'inactive': '7 - Inactive', 'mature': '6 - Mature', 'planning': '1 - Planning', 'pre-alpha': '2 - Pre-Alpha', 'stable': '5 - Production/Stable'}
- pyTooling.Packaging.DEFAULT_LICENSE
Default license (Apache License, 2.0) used by
DescribePythonPackage()
andDescribePythonPackageHostedOnGitHub()
if parameterlicense
is not assigned.Apache-2.0
- pyTooling.Packaging.DEFAULT_PY_VERSIONS
A tuple of supported CPython versions used by
DescribePythonPackage()
andDescribePythonPackageHostedOnGitHub()
if parameterpythonVersions
is not assigned.See also
('3.9', '3.10', '3.11', '3.12', '3.13')
- pyTooling.Packaging.DEFAULT_CLASSIFIERS
A list of Python package classifiers used by
DescribePythonPackage()
andDescribePythonPackageHostedOnGitHub()
if parameterclassifiers
is not assigned.See also
('Operating System :: OS Independent', 'Intended Audience :: Developers', 'Topic :: Utilities')
- pyTooling.Packaging.DEFAULT_README
Path to the README file used by
DescribePythonPackage()
andDescribePythonPackageHostedOnGitHub()
if parameterreadmeFile
is not assigned.PosixPath('README.md')
- pyTooling.Packaging.DEFAULT_REQUIREMENTS
Path to the requirements file used by
DescribePythonPackage()
andDescribePythonPackageHostedOnGitHub()
if parameterrequirementsFile
is not assigned.PosixPath('requirements.txt')
- pyTooling.Packaging.DEFAULT_DOCUMENTATION_REQUIREMENTS
Path to the README requirements file used by
DescribePythonPackage()
andDescribePythonPackageHostedOnGitHub()
if parameterdocumentationRequirementsFile
is not assigned.PosixPath('doc/requirements.txt')
- pyTooling.Packaging.DEFAULT_TEST_REQUIREMENTS
Path to the README requirements file used by
DescribePythonPackage()
andDescribePythonPackageHostedOnGitHub()
if parameterunittestRequirementsFile
is not assigned.PosixPath('tests/requirements.txt')
- pyTooling.Packaging.DEFAULT_PACKAGING_REQUIREMENTS
Path to the package requirements file used by
DescribePythonPackage()
andDescribePythonPackageHostedOnGitHub()
if parameterpackagingRequirementsFile
is not assigned.PosixPath('build/requirements.txt')
- pyTooling.Packaging.DEFAULT_VERSION_FILE
Path subclass for non-Windows systems.
On a POSIX system, instantiating a Path should return this object.
PosixPath('__init__.py')
Functions
- pyTooling.Packaging.loadReadmeFile(readmeFile)[source]
Read the README file (e.g. in Markdown format), so it can be used as long description for the package.
Supported formats:
Plain text (
*.txt
)Markdown (
*.md
)ReStructured Text (
*.rst
)
- Parameters:
readmeFile (
Path
) – Path to the README file as an instance ofPath
.- Return type:
- Returns:
A tuple containing the file content and the MIME type.
- Raises:
TypeError – If parameter ‘readmeFile’ is not of type ‘Path’.
ValueError – If README file has an unsupported format.
FileNotFoundError – If README file does not exist.
- pyTooling.Packaging.loadRequirementsFile(requirementsFile, indent=0, debug=False)[source]
Reads a requirements.txt file (recursively) and extracts all specified dependencies into an array.
Special dependency entries like Git repository references are translates to match the syntax expected by setuptools.
Hint
Duplicates should be removed by converting the result to a
set
and back to alist
.requirements = list(set(loadRequirementsFile(requirementsFile)))
- Parameters:
- Return type:
- Returns:
A list of dependencies.
- Raises:
TypeError – If parameter ‘requirementsFile’ is not of type ‘Path’.
FileNotFoundError – If requirements file does not exist.
- pyTooling.Packaging.extractVersionInformation(sourceFile)[source]
Extract double underscored variables from a Python source file, so these can be used for single-sourcing information.
Supported variables:
__author__
__copyright__
__email__
__keywords__
__license__
__version__
- Parameters:
sourceFile (
Path
) – Path to a Python source file as an instance ofPath
.- Return type:
- Returns:
An instance of
VersionInformation
with gathered variable contents.- Raises:
- pyTooling.Packaging.DescribePythonPackage(packageName, description, projectURL, sourceCodeURL, documentationURL, issueTrackerCodeURL, keywords=None, license=Apache - 2.0, readmeFile=PosixPath('README.md'), requirementsFile=PosixPath('requirements.txt'), documentationRequirementsFile=PosixPath('doc/requirements.txt'), unittestRequirementsFile=PosixPath('tests/requirements.txt'), packagingRequirementsFile=PosixPath('build/requirements.txt'), additionalRequirements=None, sourceFileWithVersion=PosixPath('__init__.py'), classifiers=('Operating System :: OS Independent', 'Intended Audience :: Developers', 'Topic :: Utilities'), developmentStatus='stable', pythonVersions=('3.9', '3.10', '3.11', '3.12', '3.13'), consoleScripts=None, dataFiles=None, debug=False)[source]
Helper function to describe a Python package.
Hint
Some information will be gathered automatically from well-known files.
Examples:
README.md
,requirements.txt
,__init__.py
The gathered information be used to add further mappings in the result dictionary.
- Parameters:
packageName (
str
) – Name of the Python package.description (
str
) – Short description of the package. The long description will be read from README file.projectURL (
str
) – URL to the Python project.sourceCodeURL (
str
) – URL to the Python source code.documentationURL (
str
) – URL to the package’s documentation.issueTrackerCodeURL (
str
) – URL to the projects issue tracker (ticket system).license (
License
) – The package’s license. (Default:Apache License, 2.0
, seeDEFAULT_LICENSE
)readmeFile (
Path
) – The path to the README file. (Default:README.md
, seeDEFAULT_README
)requirementsFile (
Path
) – The path to the project’s requirements file. (Default:requirements.txt
, seeDEFAULT_REQUIREMENTS
)documentationRequirementsFile (
Path
) – The path to the project’s requirements file for documentation. (Default:doc/requirements.txt
, seeDEFAULT_DOCUMENTATION_REQUIREMENTS
)unittestRequirementsFile (
Path
) – The path to the project’s requirements file for unit tests. (Default:tests/requirements.txt
, seeDEFAULT_TEST_REQUIREMENTS
)packagingRequirementsFile (
Path
) – The path to the project’s requirements file for packaging. (Default:build/requirements.txt
, seeDEFAULT_PACKAGING_REQUIREMENTS
)additionalRequirements (
Dict
[str
,List
[str
]]) – A dictionary of a lists with additional requirements. (default: None)sourceFileWithVersion (
Optional
[Path
]) – The path to the project’s source file containing dunder variables like__version__
. (Default:__init__.py
, seeDEFAULT_VERSION_FILE
)classifiers (
Iterable
[str
]) – A list of package classifiers. (Default: 3 classifiers, seeDEFAULT_CLASSIFIERS
)developmentStatus (
str
) – Development status of the package. (Default: stable, seeSTATUS
for supported status values)pythonVersions (
Sequence
[str
]) – A list of supported Python 3 version. (Default: all currently maintained CPython versions, seeDEFAULT_PY_VERSIONS
)consoleScripts (
Dict
[str
,str
]) – A dictionary mapping command line names to entry points. (Default: None)dataFiles (
Dict
[str
,List
[str
]]) – A dictionary mapping package names to lists of additional data files.debug (
bool
) – Enable extended outputs for debugging.
- Return type:
- Returns:
A dictionary suitable for
setuptools.setup()
.- Raises:
ToolingException – If package ‘setuptools’ is not available.
FileNotFoundError – If README file doesn’t exist.
TypeError – If parameter ‘requirementsFile’ is not of type
Path
.FileNotFoundError – If requirements file doesn’t exist.
TypeError – If parameter ‘documentationRequirementsFile’ is not of type
Path
.TypeError – If parameter ‘unittestRequirementsFile’ is not of type
Path
.TypeError – If parameter ‘packagingRequirementsFile’ is not of type
Path
.TypeError – If parameter ‘sourceFileWithVersion’ is not of type
Path
.FileNotFoundError – If package file with dunder variables doesn’t exist.
ValueError – If developmentStatus uses an unsupported value. (See
STATUS
)ValueError – If the content type of the README file is not supported. (See
loadReadmeFile()
)FileNotFoundError – If the README file doesn’t exist. (See
loadReadmeFile()
)FileNotFoundError – If the requirements file doesn’t exist. (See
loadRequirementsFile()
)
- pyTooling.Packaging.DescribePythonPackageHostedOnGitHub(packageName, description, gitHubNamespace, gitHubRepository=None, projectURL=None, keywords=None, license=Apache - 2.0, readmeFile=PosixPath('README.md'), requirementsFile=PosixPath('requirements.txt'), documentationRequirementsFile=PosixPath('doc/requirements.txt'), unittestRequirementsFile=PosixPath('tests/requirements.txt'), packagingRequirementsFile=PosixPath('build/requirements.txt'), additionalRequirements=None, sourceFileWithVersion=PosixPath('__init__.py'), classifiers=('Operating System :: OS Independent', 'Intended Audience :: Developers', 'Topic :: Utilities'), developmentStatus='stable', pythonVersions=('3.9', '3.10', '3.11', '3.12', '3.13'), consoleScripts=None, dataFiles=None, debug=False)[source]
Helper function to describe a Python package when the source code is hosted on GitHub.
This is a wrapper for
DescribePythonPackage()
, because some parameters can be simplified by knowing the GitHub namespace and repository name: issue tracker URL, source code URL, …- Parameters:
packageName (
str
) – Name of the Python package.description (
str
) – Short description of the package. The long description will be read from README file.gitHubNamespace (
str
) – Name of the GitHub namespace (organization or user).gitHubRepository (
str
) – Name of the GitHub repository.projectURL (
str
) – URL to the Python project.license (
License
) – The package’s license. (Default:Apache License, 2.0
, seeDEFAULT_LICENSE
)readmeFile (
Path
) – The path to the README file. (Default:README.md
, seeDEFAULT_README
)requirementsFile (
Path
) – The path to the project’s requirements file. (Default:requirements.txt
, seeDEFAULT_REQUIREMENTS
)documentationRequirementsFile (
Path
) – The path to the project’s requirements file for documentation. (Default:doc/requirements.txt
, seeDEFAULT_DOCUMENTATION_REQUIREMENTS
)unittestRequirementsFile (
Path
) – The path to the project’s requirements file for unit tests. (Default:tests/requirements.txt
, seeDEFAULT_TEST_REQUIREMENTS
)packagingRequirementsFile (
Path
) – The path to the project’s requirements file for packaging. (Default:build/requirements.txt
, seeDEFAULT_PACKAGING_REQUIREMENTS
)additionalRequirements (
Dict
[str
,List
[str
]]) – A dictionary of a lists with additional requirements. (default: None)sourceFileWithVersion (
Path
) – The path to the project’s source file containing dunder variables like__version__
. (Default:__init__.py
, seeDEFAULT_VERSION_FILE
)classifiers (
Iterable
[str
]) – A list of package classifiers. (Default: 3 classifiers, seeDEFAULT_CLASSIFIERS
)developmentStatus (
str
) – Development status of the package. (Default: stable, seeSTATUS
for supported status values)pythonVersions (
Sequence
[str
]) – A list of supported Python 3 version. (Default: all currently maintained CPython versions, seeDEFAULT_PY_VERSIONS
)consoleScripts (
Dict
[str
,str
]) – A dictionary mapping command line names to entry points. (Default: None)dataFiles (
Dict
[str
,List
[str
]]) – A dictionary mapping package names to lists of additional data files.debug (
bool
) – Enable extended outputs for debugging.
- Return type:
- Returns:
A dictionary suitable for
setuptools.setup()
.- Raises:
ToolingException – If package ‘setuptools’ is not available.
FileNotFoundError – If README file doesn’t exist.
TypeError – If parameter ‘requirementsFile’ is not of type
Path
.FileNotFoundError – If requirements file doesn’t exist.
TypeError – If parameter ‘documentationRequirementsFile’ is not of type
Path
.TypeError – If parameter ‘unittestRequirementsFile’ is not of type
Path
.TypeError – If parameter ‘packagingRequirementsFile’ is not of type
Path
.TypeError – If parameter ‘sourceFileWithVersion’ is not of type
Path
.FileNotFoundError – If package file with dunder variables doesn’t exist.
ValueError – If developmentStatus uses an unsupported value. (See
STATUS
)ValueError – If the content type of the README file is not supported. (See
loadReadmeFile()
)FileNotFoundError – If the README file doesn’t exist. (See
loadReadmeFile()
)FileNotFoundError – If the requirements file doesn’t exist. (See
loadRequirementsFile()
)
Classes
- class pyTooling.Packaging.Readme[source]
Encapsulates the READMEs file content and MIME type.
Inheritance
- class pyTooling.Packaging.VersionInformation[source]
Encapsulates version information extracted from a Python source file.
Inheritance
- __init__(author, email, copyright, license, version, description, keywords)[source]
Initializes a Python package (version) information instance.
- Parameters:
author (
str
) – Author of the Python package.email (
str
) – The author’s email addresscopyright (
str
) – The copyright notice of the Package.license (
str
) – The Python package’s license.version (
str
) – The Python package’s version.description (
str
) – The Python package’s short description.keywords (
Iterable
[str
]) – The Python package’s list of keywords.
- Return type:
None