pyscaffold.templates package¶
Module contents¶
Templates for all files of a project’s scaffold
All template files (*.template) within this subpackage are licensed under the BSD 0-Clause license.
- pyscaffold.templates.add_pyscaffold(config, opts)[source]¶
Add PyScaffold section to a
setup.cfg
-like file + PyScaffold’s version + extensions and their associated options.
- pyscaffold.templates.get_template(name, relative_to='pyscaffold.templates')[source]¶
Retrieve the template by name
- Parameters
name – name of template (the
.template
extension will be automatically added to this name)relative_to –
module/package object or name to which the resource file is relative (in the standard module format, e.g.
foo.bar.baz
). Notice thatrelative_to
should not represent directly a shared namespace package, since this kind of package is spread in different folders in the file system.Default value:
pyscaffold.templates
(please assign accordingly when using in custom extensions).
Examples
Consider the following package organization:
. ├── src │ └── my_package │ ├── __init__.py │ ├── templates │ │ ├── __init__.py │ │ ├── file1.template │ │ └── file2.template │ … └── tests
Inside the file
src/my_package/__init__.py
, one can easily obtain the contents offile1.template
by doing:from pyscaffold.templates import get_template from . import templates as my_templates tpl1 = get_template("file1", relative_to=my_templates) # OR # tpl1 = get_template('file1', relative_to=my_templates.__name__)
Please notice you can also use relative_to=__name__ or a combination of from .. import __name__ as parent and relative_to=parent to deal with relative imports.
- Returns
template
- Return type
Changed in version 3.3: New parameter relative_to.
- pyscaffold.templates.init(opts)[source]¶
Template of __init__.py
- Parameters
opts – mapping parameters as dictionary
- Returns
file content as string
- Return type
- pyscaffold.templates.license(opts)[source]¶
Template of LICENSE.txt
- Parameters
opts – mapping parameters as dictionary
- Returns
file content as string
- Return type
- pyscaffold.templates.licenses = {'0BSD': 'license_bsd0', 'AGPL-3.0-only': 'license_affero_3.0', 'AGPL-3.0-or-later': 'license_affero_3.0', 'Apache-2.0': 'license_apache', 'Artistic-2.0': 'license_artistic_2.0', 'BSD-2-Clause': 'license_simplified_bsd', 'BSD-3-Clause': 'license_new_bsd', 'CC0-1.0': 'license_cc0_1.0', 'EPL-1.0': 'license_eclipse_1.0', 'GPL-2.0-only': 'license_gpl_2.0', 'GPL-2.0-or-later': 'license_gpl_2.0', 'GPL-3.0-only': 'license_gpl_3.0', 'GPL-3.0-or-later': 'license_gpl_3.0', 'ISC': 'license_isc', 'LGPL-2.0-only': 'license_lgpl_2.1', 'LGPL-2.0-or-later': 'license_lgpl_2.1', 'LGPL-3.0-only': 'license_lgpl_3.0', 'LGPL-3.0-or-later': 'license_lgpl_3.0', 'MIT': 'license_mit', 'MPL-2.0': 'license_mozilla', 'Proprietary': 'license_none', 'Unlicense': 'license_public_domain'}¶
All available licences (identifiers based on SPDX
https://spdx.org/licenses/
)