pymetacode.coding module¶
The actual code generators of the pymetacode package.
Currently, there are four types of code generators:
pymetacode.coding.PackageCreator
Generates the basic package structure.
pymetacode.coding.ModuleCreator
Adds a module to an existing package.
pymetacode.coding.ClassCreator
Adds a class to an existing module, including a test class.
pymetacode.coding.FunctionCreator
Adds a function to an existing module, including a test class.
Each of these generators uses templates in the templates
subdirectory of
the pymetacode package.
- class pymetacode.coding.PackageCreator¶
Bases:
object
Generate the basic package structure.
The basic package structure follows Python best practices and has been used in a number of packages by the author of this package. In short, the modules reside in a subdirectory with the same name as the package, and parallel to that are directories for tests and documentation ( “tests”, “docs”).
Furthermore, a “setup.py” file is created to have the package installable using pip, and a license (“LICENSE”) and readme (“README.rst”) file are present.
The package version is stored in the file “VERSION”, a “.gitignore” file exists as well in the package root, and depending on the configuration, a git repository is initialised within the package root directory. In this case, a pre-commit hook is installed as well incrementing the version number for each commit, using the file “incrementVersion.sh” from the “bin” directory.
- configuration¶
Configuration as usually read from the configuration file.
Examples
The following examples demonstrate how to use the CLI from the terminal, rather than how to use this class programmatically.
The first step when creating a new package is to write a config file that can be filled with sensible content afterwards:
pymeta write config to mypackage_config.yaml
This would write the default configuration to “mypackage_config.yaml”. Change all values in this file according to your needs. Afterwards, you can create the basic structure of your new project:
pymeta create package from mypackage_config.yaml
Now, you have a complete package that is installable and deployable.
- class pymetacode.coding.ModuleCreator¶
Bases:
object
Add a module to an existing package.
Actually, adding a module consists of creating three files: the module itself, an accompanying test module, and the API documentation file. The latter gets added to the API toctree directive as well.
- configuration¶
Configuration as usually read from the configuration file.
- Raises
ValueError – Raised if no name is provided
Examples
The following examples demonstrate how to use the CLI from the terminal, rather than how to use this class programmatically.
Prerequisite for using the CLI is to have the package configuration stored within the package root directory in the file “.project_configuration.yaml”. This will be the case if the package has been created by the CLI as well. Furthermore, all following commands need to be issued from within the root directory of your package.
pymeta add module mymodule
This will add a module “mymodule” to your package, together with a “test_mymodule” module in the “tests” subdirectory. And even better, the API documentation will be updated as well for you.
- class pymetacode.coding.ClassCreator¶
Bases:
object
Add a class to an existing module, including a test class.
When a class is added to a module, it will always be added to the bottom of the module file, and at the same time a test class with a very basic setup and a first test will be added to the corresponding test module.
- configuration¶
Configuration as usually read from the configuration file.
- Raises
ValueError – Raised if no class or module name is provided
Examples
The following examples demonstrate how to use the CLI from the terminal, rather than how to use this class programmatically.
Prerequisite for using the CLI is to have the package configuration stored within the package root directory in the file “.project_configuration.yaml”. This will be the case if the package has been created by the CLI as well. Furthermore, all following commands need to be issued from within the root directory of your package.
pymeta add class MyClass to mymodule
This will add the class “MyClass” to the module “mymodule”, together with a test class in the “test_mymodule” module. The class will come with a basic docstring, and the test class with a minimalistic setup and first test (for implementation of the class) that gets you started with writing further tests.
- create(name='', module='')¶
Create actual code stub for the class.
- Parameters
- Raises
ValueError – Raised if function or module name is missing
- class pymetacode.coding.FunctionCreator¶
Bases:
object
Add a function to an existing module, including a test class.
When a function is added to a module, it will always be added to the bottom of the module file, and at the same time a test class with a first test will be added to the corresponding test module.
- configuration¶
Configuration as usually read from the configuration file.
- Raises
ValueError – Raised if no function or module name is provided
Examples
The following examples demonstrate how to use the CLI from the terminal, rather than how to use this class programmatically.
Prerequisite for using the CLI is to have the package configuration stored within the package root directory in the file “.project_configuration.yaml”. This will be the case if the package has been created by the CLI as well. Furthermore, all following commands need to be issued from within the root directory of your package.
pymeta add function my_function to mymodule
This will add the function “my_function” to the module “mymodule”, together with a test class in the “test_mymodule” module. The function will come with a basic docstring, and the test class with a minimalistic first test that gets you started with writing further tests.
- create(name='', module='')¶
Create actual code stub for the function.
- Parameters
- Raises
ValueError – Raised if function or module name is missing