### Install and Run Pre-commit Hooks Source: https://github.com/ethanfurman/dbf/blob/master/CONTRIBUTING.md Install the pre-commit tool and run its checks manually or automatically before committing. Pre-commit is used for code quality and style checks defined in `.pre-commit-config.yaml`. The `pre-commit install` command integrates it with git hooks. ```bash pip install pre-commit ``` ```bash pre-commit run --all-files ``` ```bash pre-commit install ``` -------------------------------- ### Run Unit Tests for dbf Source: https://github.com/ethanfurman/dbf/blob/master/CONTRIBUTING.md Execute the unit tests for the dbf library using its built-in test runner. This command is straightforward and requires no external setup beyond having the dbf package installed. ```bash python -m dbf.test ``` -------------------------------- ### Set Up Toxrunner Environment Source: https://github.com/ethanfurman/dbf/blob/master/CONTRIBUTING.md Create and activate a virtual environment for running tox, a tool for automating testing across different Python versions. This setup is necessary due to dbf's backward compatibility requirements, necessitating a specific virtualenv version. ```bash python -m venv toxrunner source toxrunner/bin/activate pip install -r requirements-toxrunner.txt ``` -------------------------------- ### Run Tox Environments Source: https://github.com/ethanfurman/dbf/blob/master/CONTRIBUTING.md Execute tox tests for specific Python environments or the entire suite. The examples show how to run tests for Python 3.6 (`tox -e py36`), the packaging build (`tox -e packaging`), or all configured environments (`tox`). ```bash tox -e py36 ``` ```bash tox -e packaging ``` ```bash tox ``` -------------------------------- ### Creating and Writing to DBF Tables with Python Source: https://github.com/ethanfurman/dbf/blob/master/README.md This example shows how to create a new DBF table, either in-memory or on disk, add records, and modify them. It utilizes `dbf.Table` for table creation and `table.append` for adding records. Custom data types and field specifications can be defined. The `with` statement ensures proper table handling. ```python import datetime import dbf # create an in-memory table table = dbf.Table( filename='test', field_specs='name C(25); age N(3,0); birth D; qualified L', on_disk=False, ) table.open(dbf.READ_WRITE) # add some records to it for datum in ( ('Spanky', 7, dbf.Date.fromymd('20010315'), False), ('Spunky', 23, dbf.Date(1989, 7, 23), True), ('Sparky', 99, dbf.Date(), dbf.Unknown), ): table.append(datum) # iterate over the table, and print the records for record in table: print(record) print('--------') print(record[0:3]) print([record.name, record.age, record.birth]) print('--------') # make a copy of the test table (structure, not data) custom = table.new( filename='test_on_disk.dbf', default_data_types=dict(C=dbf.Char, D=dbf.Date, L=dbf.Logical), ) # automatically opened and closed with custom: # copy records from test to custom for record in table: custom.append(record) # modify each record in custom (could have done this in prior step) for record in custom: dbf.write(record, name=record.name.upper()) # and print the modified record print(record) print('--------') print(record[0:3]) print([record.name, record.age, record.birth]) print('--------') table.close() ``` -------------------------------- ### Reading a DBF Table with Python Source: https://github.com/ethanfurman/dbf/blob/master/README.md This snippet demonstrates how to read data from a DBF file using the dbf module. It iterates through records, extracts field names, and prints each row as a dictionary. Ensure the 'dbf' library is installed. Input is a DBF filename and an encoding. ```python import dbf dbf_filename = "some-file.dbf" encoding = "utf8" table = dbf.Table(dbf_filename, codepage=encoding, on_disk=True) field_names = table.field_names table.open() for record in table: row = {field_name: record[field_name] for field_name in field_names} print(row) # You can use row.field_name to get each field's data also ``` -------------------------------- ### Configure Pyenv for Tox Source: https://github.com/ethanfurman/dbf/blob/master/CONTRIBUTING.md Set environment variables to integrate pyenv with virtualenv for Python interpreter discovery. This ensures tox can find and use various Python versions managed by pyenv, facilitating cross-environment testing. The VIRTUALENV_DISCOVERY variable is key for this integration. ```bash export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH" eval "$(pyenv init -)" export VIRTUALENV_DISCOVERY=pyenv ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.