Preprocessor for files.
Project description
### Preprocessor
Suited for simple preprocessing of Python files. The original use case of the package was annoying Cython work to do with data types. Notice that Preprocessor can run on any type of file (e.g. TSV, C++ sources etc.). To avoid clashes with other programming language preprocessor prefix and suffix is fully tunable.
#### Example
Here's a small file where we replicate the same Cython code 3 times - once for every of int, float and double datatypes. You can find the code for `typed_expression` function in `sample_utils.py` in this repo.
```Python
pyp
from sample_utils import typed_expression
ypy
cdef class Mat:
cdef CMat[dtype] matinternal
int dtype
def sum(Mat self):
# Inline preprcoessor expression. Executes a function.
# Generally inline expressions should be one line,
# But can be extended to multiple where all the data
# on second line and following will be captured into
# a string argument passed as last positional argument
# to a function
pypinline typed_expression(pyp, "self.matinternal", "CMat",
print('siema')
return WrapMat(TYPED_EXPRESSION.sum())
ypy
```
The output of the preprocessed file looks like this:
```Python
cdef class Mat:
cdef CMat[dtype] matinternal
int dtype
def sum(Mat self):
# Inline preprcoessor expression. Executes a function.
# Generally inline expressions should be one line,
# But can be extended to multiple where all the data
# on second line and following will be captured into
# a string argument passed as last positional argument
# to a function
if self.dtype == np.int32:
print('siema')
return WrapMat((<CMat[int]>(self.matinternal)).sum())
elif self.dtype == np.float32:
print('siema')
return WrapMat((<CMat[float]>(self.matinternal)).sum())
elif self.dtype == np.float64:
print('siema')
return WrapMat((<CMat[double]>(self.matinternal)).sum())
else:
raise ValueError("Invalid dtype:" + self.dtype + " (should be one of int32, float32, float64)")
```
#### Command Line Interface
Preprocessor comes with a command line script, to easily run the preprocessor form environments outside of Python
```bash
preprocessor --input sample.py.pre --output sample.py
```
Suited for simple preprocessing of Python files. The original use case of the package was annoying Cython work to do with data types. Notice that Preprocessor can run on any type of file (e.g. TSV, C++ sources etc.). To avoid clashes with other programming language preprocessor prefix and suffix is fully tunable.
#### Example
Here's a small file where we replicate the same Cython code 3 times - once for every of int, float and double datatypes. You can find the code for `typed_expression` function in `sample_utils.py` in this repo.
```Python
pyp
from sample_utils import typed_expression
ypy
cdef class Mat:
cdef CMat[dtype] matinternal
int dtype
def sum(Mat self):
# Inline preprcoessor expression. Executes a function.
# Generally inline expressions should be one line,
# But can be extended to multiple where all the data
# on second line and following will be captured into
# a string argument passed as last positional argument
# to a function
pypinline typed_expression(pyp, "self.matinternal", "CMat",
print('siema')
return WrapMat(TYPED_EXPRESSION.sum())
ypy
```
The output of the preprocessed file looks like this:
```Python
cdef class Mat:
cdef CMat[dtype] matinternal
int dtype
def sum(Mat self):
# Inline preprcoessor expression. Executes a function.
# Generally inline expressions should be one line,
# But can be extended to multiple where all the data
# on second line and following will be captured into
# a string argument passed as last positional argument
# to a function
if self.dtype == np.int32:
print('siema')
return WrapMat((<CMat[int]>(self.matinternal)).sum())
elif self.dtype == np.float32:
print('siema')
return WrapMat((<CMat[float]>(self.matinternal)).sum())
elif self.dtype == np.float64:
print('siema')
return WrapMat((<CMat[double]>(self.matinternal)).sum())
else:
raise ValueError("Invalid dtype:" + self.dtype + " (should be one of int32, float32, float64)")
```
#### Command Line Interface
Preprocessor comes with a command line script, to easily run the preprocessor form environments outside of Python
```bash
preprocessor --input sample.py.pre --output sample.py
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
preprocessor-1.1.3.tar.gz
(4.2 kB
view details)
File details
Details for the file preprocessor-1.1.3.tar.gz
.
File metadata
- Download URL: preprocessor-1.1.3.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cf360f24a21a3af8ef4a08837c549d20b5160199f6bbc0e4b7fedfda1822855 |
|
MD5 | ef287ec910666943a30ee17e8f5ce34f |
|
BLAKE2b-256 | 96add9f4ffb9bb97d1cb5bcb876b7932571d4dbaa3eff1701ad45d367f0ea27b |