Development Guide¶
This guide provides information for developers who want to contribute to WordNet DB Migrator or modify it for their own needs.
Project Structure¶
The WordNet DB Migrator project is organized as follows:
wordnet_db_migrator/
├── .github/ # GitHub-specific files
│ ├── workflows/ # GitHub Actions workflows
│ │ └── ci.yml # CI/CD configuration
│ └── ISSUE_TEMPLATE/ # Issue templates
├── docs/ # Documentation
│ ├── installation.md # Installation guide
│ ├── usage.md # Usage guide
│ └── development.md # Development guide (this file)
├── examples/ # Example usage
├── tests/ # Test cases
├── src/ # Source directory
│ └── wordnet_db_migrator/ # Main package
│ ├── __init__.py # Package initialization
│ ├── cli.py # Command-line interface
│ ├── config.py # Configuration handling
│ ├── main.py # Main entry point
│ ├── steps/ # Individual steps
│ │ ├── __init__.py
│ │ ├── step010_test_sqlite_connection.py
│ │ ├── ...
│ └── utils/ # Utility functions
│ ├── __init__.py
│ └── db_utils.py
├── .gitignore # Git ignore file
├── LICENSE # License file
├── pyproject.toml # Modern Python packaging
├── README.md # Main README
├── CONTRIBUTING.md # Contribution guidelines
└── setup.py # Setup script
Development Setup¶
To set up your development environment:
-
Clone the repository:
-
Create a virtual environment:
-
Install development dependencies:
Adding a New Step¶
The migration process is divided into steps, each implemented as a separate module in the steps directory. To add a new step:
-
Create a new module in the
stepsdirectory with a name following the patternstepXXX_description.py, whereXXXis a three-digit number indicating the order of the step. -
Implement the step as a function named
runthat returns a boolean indicating success or failure:
# src/wordnet_db_migrator/steps/stepXXX_description.py
"""
Step XXX: Description of the step.
This module implements step XXX of the WordNet migration process.
"""
import logging
from wordnet_db_migrator.config import config
# Set up logging
logger = logging.getLogger(__name__)
def run() -> bool:
"""
Run step XXX of the WordNet migration process.
Returns:
bool: True if the step was successful, False otherwise.
"""
logger.info("Starting step XXX")
try:
# Implement the step here
logger.info("Step XXX completed successfully")
return True
except Exception as e:
logger.error(f"Step XXX failed: {e}")
config.success = False
return False
- Add the step to the
ALL_STEPSlist inmain.py:
ALL_STEPS: List[StepDefinition] = [
# ...
("Step XXX: Description", stepXXX_description.run),
# ...
]
Modifying an Existing Step¶
To modify an existing step:
- Locate the step module in the
stepsdirectory. - Make your changes to the
runfunction. - Test your changes (see the Testing section below).
Adding a New Command-Line Option¶
To add a new command-line option:
- Add the option to the
VALID_FLAGSset incli.py:
-
Add the option to the help text in the
show_helpfunction incli.py. -
Add code to handle the option in the
validate_cli_argsfunction incli.py.
Testing¶
Running Tests¶
Run tests with pytest:
Writing Tests¶
Tests are located in the tests directory. To add a new test:
-
Create a new module in the
testsdirectory with a name following the patterntest_*.py. -
Implement test functions using pytest:
# tests/test_example.py
"""
Tests for the example module.
"""
import pytest
from wordnet_db_migrator import example
def test_example_function():
"""Test the example function."""
result = example.function()
assert result == expected_result
Code Style¶
This project follows PEP 8 style guidelines. We use:
- Black for code formatting
- isort for import sorting
- flake8 for linting
- mypy for type checking
You can run these tools with:
Documentation¶
Docstrings¶
All modules, classes, and functions should have docstrings following the Google style:
def function(arg1: str, arg2: int) -> bool:
"""
Short description of the function.
Longer description of the function if needed.
Args:
arg1: Description of arg1
arg2: Description of arg2
Returns:
Description of the return value
Raises:
ValueError: Description of when this error is raised
"""
# Function implementation
Markdown Documentation¶
Documentation files are written in Markdown and located in the docs directory. To add a new documentation file:
- Create a new Markdown file in the
docsdirectory. - Add a link to the new file in the appropriate place (e.g., in the README.md or another documentation file).
Releasing a New Version¶
To release a new version:
- Update the version number in
src/wordnet_db_migrator/__init__.py:
-
Update the CHANGELOG.md file with the changes in the new version.
-
Commit the changes:
- Tag the release:
- Build the package:
- Upload to PyPI:
Getting Help¶
If you need help with development, please:
- Check the documentation in the
docsdirectory - Look at the code and comments
- Check the GitHub Issues
- Create a new issue if your question is not answered elsewhere