ghost_writer
A simple package that allows you to build a class to parameterize scripts via code generation.
A cmdline utility is add to convert python scripts into generators which can later be modified.
Installation
pip install pyghost-writer
Usage
Say you have a simple script that you want to parameterize for code generation.
import os
for i in range(10):
for j in range(20):
pass
In the terminal run the scriptify_py command on the script
scriptify_py script.py
Now you will have a new file called generated_script.py which contains a class that can generate that script which can be run:
from ghost_writer import ScriptGenerator
class NewGenerator(ScriptGenerator):
def __init__(self, file_name: str) -> None:
super().__init__(file_name)
def _build_script(self) -> None:
self._add_line('import os')
self._end_line()
self._end_line()
self._add_line('for i in range(10):')
self._add_line('for j in range(20):', indent_level=1)
self._add_line('pass', indent_level=2)
We can now modify the class to be parameterized:
from ghost_writer import ScriptGenerator
class MyGenerator(ScriptGenerator):
def __init__(self, file_name: str, parameter: int) -> None:
self._parameter = parameter
super().__init__(file_name)
def _build_script(self) -> None:
self._add_line('import os')
self._end_line()
self._end_line()
self._add_line('for i in range(10):')
self._add_line('for j in range(20):', indent_level=1)
self._add_line(f'print({parameter})', indent_level=2)
Now in python, we can import our class and run it:
generator = MyGenerator("new_script.py", 4)
generator.write()
And now we have a generated script called new_script.py
import os
for i in range(10):
for j in range(20):
print(4)
- Free software: GNU General Public License v3
Metadata
Release files for pyghost-writer 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyghost_writer-0.1.2.tar.gz | 25.4 kB | Without provenance | Details for pyghost_writer-0.1.2.tar.gz |
Release files / pyghost_writer-0.1.2.tar.gz
| Download URL | pyghost_writer-0.1.2.tar.gz |
|---|---|
| Size | 25.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8266c31f28a52e4f285ac64fe6ecb130b06be468276e065d4591655cbb188fbd
|
|
BLAKE2b-256 checksum How to use checksums |
8390c4119f30d21b8a7fcfba4cd4cd1946131076e6e0c45b8b2c1ed88acf366d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for pyghost-writer 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.