Skip to content

Commit fd74c9e

Browse files
committed
refactor(clean): remove all hydration and dehydrate code and tests
1 parent 9ce6f58 commit fd74c9e

5 files changed

Lines changed: 51 additions & 386 deletions

File tree

‎README.md‎

Lines changed: 48 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,91 @@
1-
# Python FWF
1+
<!-- markdownlint-disable MD013 -->
2+
# python-pyfwf
23

3-
[![License](https://img.shields.io/badge/License-MIT-lemon.svg)](https://opensource.org/licenses/MIT)
4-
[![Python](https://img.shields.io/pypi/pyversions/pyfwf.svg)](https://pypi.org/project/pyfwf/)
4+
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
5+
[![Python](https://img.shields.io/badge/Python-3.9%2B-blue?logo=python)](https://www.python.org/)
56
[![FWF Compliance](https://img.shields.io/badge/FWF_Compliance-5%2F5_cases_passed-brightgreen?logo=github)](https://github.com/fixed-width-file/fwf-compliance-tests)
67
[![QA](https://github.com/fixed-width-file/python-pyfwf/actions/workflows/qa.yml/badge.svg)](https://github.com/fixed-width-file/python-pyfwf/actions/workflows/qa.yml)
78
[![Coverage](https://codecov.io/gh/fixed-width-file/python-pyfwf/branch/main/graph/badge.svg)](https://codecov.io/gh/fixed-width-file/python-pyfwf)
8-
[![Docs](https://github.com/fixed-width-file/python-pyfwf/actions/workflows/docs.yml/badge.svg)](https://fixed-width-file.github.io/python-pyfwf/)
99
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
1010

11-
Python library for reading and manipulating **fixed width files (FWF)**.
11+
**python-pyfwf** is a fast, type-safe Python 3.9+ library for parsing, validating, and exporting **Fixed Width Files (FWF)**.
1212

13-
> See each package's [documentation](https://fixed-width-file.github.io/python-pyfwf/)
14-
> for details and usage examples.
13+
It is part of the [Fixed Width File Ecosystem](https://fixed-width-file.github.io/) and fully implements the **[fwf-compliance-tests v1.0.0](https://github.com/fixed-width-file/fwf-compliance-tests)** specification.
1514

16-
This library is necessary because large banks and the Brazilian government use a
17-
batch file model that has 3 data blocks:
15+
---
1816

19-
1. The **header** line identifies the file type, does not describe the file
20-
structure, and usually starts the line with the number 1 to indicate it
21-
is the header.
22-
2. The **detail** contains the data and may have more than one type of detail.
23-
For example, if it starts with 2 it represents a state, if it starts with
24-
3 it represents a municipality of the state that came before it, and each
25-
type of detail has its own data structure.
26-
3. The **footer** line signs the file, that is, it may have a line counter
27-
field or another field to validate if the file is complete, and usually
28-
starts the line with the number 9 to indicate it is the footer.
17+
## 🌟 Key Features
2918

30-
Thus, this library uses descriptors to define how the data should be read,
31-
having **file**, **header**, **detail**, and **footer** descriptors.
19+
- **Type-Safe Columns**: `CharColumn`, `RightCharColumn`, `PositiveIntegerColumn`, `PositiveDecimalColumn`, `DateColumn`, `TimeColumn`, and `DateTimeColumn`.
20+
- **Flexible Descriptors**: Structured records with `HeaderRowDescriptor`, `DetailRowDescriptor`, and `FooterRowDescriptor`.
21+
- **Multiple Output Renders**: Export layout specifications to Markdown, ReStructuredText (RST), or HTML tables via `RenderUtils`.
22+
- **Full Test Suite & Compliance**: 100% compliant with `fwf-compliance-tests` v1.0.0.
23+
- **Git Hooks Ready**: Pre-configured `pre-commit` and `pre-push` hooks.
3224

33-
## Compare with others packages
25+
---
3426

35-
<!-- markdownlint-disable MD013 -->
36-
| Package | Main Focus / Features | API Style | Typed Columns | Header/Footer | Documentation | Test Coverage |
37-
|------------------------------------------------------------|-----------------------------------------------------------------------------------------|--------------|---------------|---------------|---------------|---------------|
38-
| **pyfwf** | Flexible, typed columns, descriptors, header/footer, 100% coverage | Pythonic/OOP | Yes | Yes | Extensive | 100% |
39-
| [fwf](https://pypi.org/project/fwf/) | Simple FWF reader/writer, minimal configuration | Functional | No | No | Minimal | Unknown |
40-
| [microtrade-fwf](https://pypi.org/project/microtrade-fwf/) | Basic FWF parsing, focused on simplicity, limited features | Functional | No | No | Minimal | Unknown |
41-
| [petl-fwf](https://pypi.org/project/petl-fwf/) | FWF support as part of [petl](https://petl.readthedocs.io/) ETL toolkit, table-oriented | Table/ETL | No | No | Good (petl) | Good (petl) |
42-
<!-- markdownlint-enable MD013 -->
43-
44-
**Summary of differences:**
45-
46-
- **pyfwf** offers an object-oriented API, support for typed columns
47-
(int, decimal, date, etc.), header/footer definition, and full test coverage.
48-
Ideal for scenarios that require validation and strict data structure.
49-
- **fwf** and **microtrade-fwf** are simpler solutions, with fewer validation
50-
and configuration options, aimed at quick and basic usage.
51-
- **petl-fwf** integrates FWF reading into the petl ecosystem, useful for ETL,
52-
but without a focus on type validation or detailed file structure.
53-
54-
## Features
55-
56-
- 📖 Read fixed-width format files with custom column definitions
57-
- 🔧 Support for typed columns (integer, decimal, date, time, etc.)
58-
- 📋 Header and footer row handling
59-
- 🎯 Simple and intuitive API
60-
- ✅ Fully tested (100% coverage)
61-
62-
## Installation
27+
## 🚀 Installation
28+
29+
Install via `pip`:
6330

6431
```bash
6532
pip install pyfwf
6633
```
6734

68-
## Quick Start
35+
---
36+
37+
## 💡 Quickstart
6938

7039
```python
7140
from pyfwf.columns import CharColumn, PositiveIntegerColumn
7241
from pyfwf.descriptors import DetailRowDescriptor, FileDescriptor
7342
from pyfwf.readers import Reader
7443

75-
# Define columns
76-
detail = DetailRowDescriptor([
77-
CharColumn(name='name', pos=1, size=20),
78-
PositiveIntegerColumn(name='age', pos=21, size=3),
79-
])
44+
# 1. Define columns
45+
name_col = CharColumn('name', 20, 'User Name')
46+
age_col = PositiveIntegerColumn('age', 3, 'Age in years')
8047

81-
# Create file descriptor
82-
fd = FileDescriptor(line_size=23, details=[detail])
48+
# 2. Define row and file descriptors
49+
detail = DetailRowDescriptor([name_col, age_col])
50+
file_descriptor = FileDescriptor([detail])
8351

84-
# Read file
85-
with open('data.fwf', 'r') as f:
86-
reader = Reader(f, fd)
87-
for row in reader:
88-
print(row)
89-
```
52+
# 3. Read fixed-width file content
53+
content = "KELSON MEDEIROS 045\nMARIA SILVA 030\n"
54+
reader = Reader(content, file_descriptor, "\n")
9055

91-
## Development & Pre-commit Hooks
56+
for row in reader:
57+
print(f"Name: {row['name']} | Age: {row['age']}")
58+
```
9259

93-
This project uses [`pre-commit`](https://pre-commit.com/) to enforce
94-
code quality, linting, formatting, and unit tests before committing and pushing.
60+
---
9561

96-
### Installing Git Hooks
62+
## 🧪 Testing & Compliance
9763

98-
To set up the pre-commit and pre-push hooks locally:
64+
Run all unit tests using pytest:
9965

10066
```bash
101-
# Install development dependencies
102-
pip install -e ".[dev]"
67+
pytest
68+
```
10369

104-
# Install pre-commit and pre-push hooks
70+
---
71+
72+
## ⚓ Pre-Commit & Pre-Push Setup
73+
74+
Set up pre-commit and pre-push hooks:
75+
76+
```bash
10577
pre-commit install
10678
pre-commit install --hook-type pre-push
10779
```
10880

109-
### Running Hooks Manually
110-
111-
You can execute the hooks manually against all files at any time:
81+
Run checks manually:
11282

11383
```bash
114-
# Run commit-stage hooks (Black, Ruff, doc8, markdownlint, whitespace)
11584
pre-commit run --all-files
116-
117-
# Run push-stage hooks (pytest & 100% coverage gate)
118-
pre-commit run --hook-stage pre-push --all-files
11985
```
12086

121-
## Security
122-
123-
Please report vulnerabilities according to [SECURITY.md](SECURITY.md).
87+
---
12488

125-
## Author
89+
## 📄 License
12690

127-
Kelson da Costa Medeiros <kelsoncm@gmail.com>
91+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

‎pyfwf/columns.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@
2727
import re
2828
from datetime import date, datetime, time
2929

30-
from .hydrating import Hydrator
3130

32-
33-
class AbstractColumn(Hydrator):
31+
class AbstractColumn:
3432
to_str_assertion_types = None
3533
to_str_assertion_class = None
3634
to_str_none_pad = None
3735
to_str_pad_template = None
38-
hydrating_args = ["name", "size", "description"]
3936

4037
def __init__(self, _name: str, size: int, description: str = None):
4138
super(AbstractColumn, self).__init__()
@@ -129,7 +126,6 @@ def to_value(self, slice: str):
129126
class PositiveDecimalColumn(PositiveIntegerColumn):
130127
to_str_assertion_types = "positive decimal"
131128
to_str_assertion_class = float
132-
hydrating_args = ["name", "size", "decimals", "description"]
133129

134130
def __init__(self, _name: str, size: int, decimals: int = 2, description: str = None):
135131
super(PositiveDecimalColumn, self).__init__(_name, size, description)
@@ -163,7 +159,6 @@ class DateTimeColumn(AbstractColumn):
163159
to_str_assertion_class = datetime
164160
to_str_none_pad = "0"
165161
format_num_elements = 5
166-
hydrating_args = ["name", "format", "description"]
167162

168163
def __init__(self, _name: str, _format: str = "%d%m%Y%H%M", description: str = None):
169164
if not isinstance(_name, str):

‎pyfwf/descriptors.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
from typing import List
2828

2929
from .columns import AbstractColumn
30-
from .hydrating import Hydrator
3130

3231

33-
class RowDescriptor(Hydrator):
32+
class RowDescriptor:
3433
def __init__(self, columns: List[AbstractColumn]):
3534
super(RowDescriptor, self).__init__()
3635
if not isinstance(columns, list):
@@ -78,7 +77,7 @@ class DetailRowDescriptor(RowDescriptor):
7877
pass
7978

8079

81-
class FileDescriptor(Hydrator):
80+
class FileDescriptor:
8281
def __init__(
8382
self,
8483
details: List[DetailRowDescriptor],

‎pyfwf/hydrating.py‎

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)