Skip to main content

Overview

The project uses ZeroC Ice middleware to enable remote procedure calls between the backend server and clients. The ICE stubs are Python files automatically generated from the Conversor.ice interface definition file.
You only need to regenerate stubs when you modify the backend/Conversor.ice file. For normal development work, the existing stubs work without changes.

Understanding ICE Stubs

The stubs are located in the Conversor/ directory and include:
  • ConversorUnidades.py - Main interface implementation
  • UnidadInvalidaException.py - Exception handling
  • ConversorUnidades_forward.py - Forward declarations
  • __init__.py - Package initialization
These files are generated from backend/Conversor.ice, which defines:
module Conversor
{
    exception UnidadInvalidaException
    {
        string mensaje;
    };

    interface ConversorUnidades
    {
        double convertirTemperatura(double valor, string desde, string hasta)
            throws UnidadInvalidaException;

        double convertirLongitud(double valor, string desde, string hasta)
            throws UnidadInvalidaException;

        double convertirPeso(double valor, string desde, string hasta)
            throws UnidadInvalidaException;

        double convertirVelocidad(double valor, string desde, string hasta)
            throws UnidadInvalidaException;

        string unidadesDisponibles(string categoria)
            throws UnidadInvalidaException;
    };
};

When to Regenerate Stubs

Regenerate the ICE stubs whenever you:

Add New Methods

Adding new conversion methods or utility functions to the interface

Modify Parameters

Changing parameter types or adding new parameters to existing methods

Add Exceptions

Defining new exception types for error handling

Change Return Types

Modifying the return type of any method

Regenerating Stubs

1

Activate your virtual environment

Make sure your virtual environment is active before running the slice compiler.
source .venv/bin/activate
2

Run the slice2py compiler

From the project root directory, run:
slice2py backend/Conversor.ice
This command reads backend/Conversor.ice and regenerates all Python stub files in the Conversor/ directory.
3

Verify the generated files

Check that the Conversor/ directory contains the updated stub files:
ls -l Conversor/
You should see:
  • ConversorUnidades.py (main interface)
  • UnidadInvalidaException.py (exception class)
  • ConversorUnidades_forward.py (forward declarations)
  • __init__.py (package init)
4

Test the changes

Restart your servers and verify that the changes work correctly:
# Terminal 1: ICE Server
cd backend
python3 server.py

# Terminal 2: Web Server
cd backend
python3 web_server.py
Or use the automated run script:
./run.sh  # macOS/Linux
# or
powershell -ExecutionPolicy Bypass -File run.ps1  # Windows

Example: Adding a New Method

Let’s say you want to add volume conversion. Here’s the workflow:
1

Edit Conversor.ice

Add the new method to backend/Conversor.ice:
interface ConversorUnidades
{
    // ... existing methods ...

    double convertirVolumen(double valor, string desde, string hasta)
        throws UnidadInvalidaException;
};
2

Regenerate stubs

slice2py backend/Conversor.ice
3

Implement in server.py

Add the implementation in backend/server.py:
def convertirVolumen(self, valor, desde, hasta, current=None):
    # Implementation here
    pass
4

Test the new endpoint

Restart servers and test the new functionality.
Always regenerate stubs before implementing the new methods in your server code. The server imports these stubs, so they must be up-to-date.

Troubleshooting

The slice2py command comes from the zeroc-ice package. Make sure it’s installed:
pip install zeroc-ice
If still not found, verify your virtual environment is activated:
which slice2py  # macOS/Linux
where slice2py  # Windows
If you see import errors after regenerating stubs:
  1. Restart your Python processes (server.py, web_server.py)
  2. Clear Python cache: find . -type d -name __pycache__ -exec rm -rf {} +
  3. Verify the Conversor/__init__.py file exists
If slice2py reports errors:
  • Check for missing semicolons
  • Verify all braces are balanced
  • Ensure all methods have return types
  • Confirm exception declarations are properly formatted
Example of valid ICE syntax:
exception MyException
{
    string mensaje;
};

interface MyInterface
{
    double myMethod(double param) throws MyException;
};

ZeroC Ice Documentation

Official Ice documentation for Python

Slice Language Reference

Complete Slice language specification
Commit your Conversor.ice file to version control, but consider adding the Conversor/ directory to .gitignore if you want developers to generate their own stubs locally.

Build docs developers (and LLMs) love