Skip to content

List files missing type hints #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cbouysset opened this issue Mar 12, 2025 · 2 comments
Closed

List files missing type hints #248

cbouysset opened this issue Mar 12, 2025 · 2 comments
Labels
good first issue Good for newcomers

Comments

@cbouysset
Copy link
Collaborator

cbouysset commented Mar 12, 2025

TODO: go through each file to find those that already have type hints for all variables, functions and methods, and fill out the corresponding [ ] checkbox below.

    .
    ├── prolif
[ ] │   ├── datafiles.py
[ ] │   ├── exceptions.py
[ ] │   ├── fingerprint.py
[ ] │   ├── ifp.py
    │   ├── interactions
[ ] │   │   ├── base.py
[ ] │   │   ├── constants.py
[ ] │   │   ├── interactions.py
[ ] │   │   └── utils.py
[ ] │   ├── molecule.py
[ ] │   ├── parallel.py
[ ] │   ├── pickling.py
    │   ├── plotting
[ ] │   │   ├── barcode.py
[ ] │   │   ├── complex3d.py
[ ] │   │   ├── network.py
[ ] │   │   ├── residues.py
[ ] │   │   └── utils.py
[ ] │   ├── rdkitmol.py
[ ] │   ├── residue.py
[ ] │   └── utils.py
    └── tests
[ ]     ├── conftest.py
        ├── plotting
[ ]     │   ├── test_barcode.py
[ ]     │   ├── test_complex3d.py
[ ]     │   ├── test_network.py
[ ]     │   └── test_residues.py
[ ]     ├── test_fingerprint.py
[ ]     ├── test_ifp.py
[ ]     ├── test_interactions.py
[ ]     ├── test_molecule.py
[ ]     ├── test_pickling.py
[ ]     ├── test_residues.py
[ ]     └── test_utils.py
@cbouysset cbouysset added the good first issue Good for newcomers label Mar 12, 2025
@H-EKE
Copy link
Contributor

H-EKE commented Mar 19, 2025

Hi,

I am interested in working on this issue for the GSCO

@H-EKE
Copy link
Contributor

H-EKE commented Mar 19, 2025

Would something like this work this issue?

import os
import subprocess

# Directories to scan
CODE_DIRS = ["prolif", "tests"]

def find_python_files(base_dirs):
    """Recursively finds all .py files in the given directories."""
    py_files = []
    for base_dir in base_dirs:
        for root, _, files in os.walk(base_dir):
            for file in sorted(files):  # Ensure sorted order
                if file.endswith(".py"):
                    relative_path = os.path.relpath(os.path.join(root, file), start=base_dir)
                    py_files.append((base_dir, relative_path))
    return py_files

def check_type_hints(files):
    """Runs mypy on the list of Python files and returns fully typed ones."""
    fully_typed = set()
    
    for base_dir, file in files:
        file_path = os.path.join(base_dir, file)
        result = subprocess.run(["mypy", "--disallow-untyped-defs", file_path],
                                capture_output=True, text=True)
        
        # If mypy passes with no errors, mark as fully typed
        if result.returncode == 0:
            fully_typed.add((base_dir, file))
    
    return fully_typed

def generate_todo_structure(files, fully_typed):
    """Generates a tree-like TODO structure with checkboxes."""
    last_dir = None
    lines = []
    
    for base_dir, file in files:
        # Extract parent directory and filename
        parts = file.split(os.sep)
        parent_dirs = parts[:-1]
        filename = parts[-1]
        
        # Print parent directory only if it's new
        current_dir = os.path.join(base_dir, *parent_dirs)
        if current_dir and current_dir != last_dir:
            lines.append(f"    {current_dir}/")
            last_dir = current_dir
        
        # Mark with a checkbox
        status = "[✓]" if (base_dir, file) in fully_typed else "[ ]"
        lines.append(f"{status}     ├── {filename}")
    
    return "\n".join(lines)

# Find Python files
python_files = find_python_files(CODE_DIRS)

# Run type hint check
fully_typed_files = check_type_hints(python_files)

# Generate TODO output
todo_structure = generate_todo_structure(python_files, fully_typed_files)

# Save to a TODO file
with open("TODO_typing.txt", "w") as f:
    f.write(todo_structure)

print("TODO_typing.txt generated!")

The output is

    prolif/
[ ]     ├── setup.py
    prolif/tests/
[✓]     ├── __init__.py
[ ]     ├── conftest.py
[ ]     ├── test_fingerprint.py
[ ]     ├── test_ifp.py
[ ]     ├── test_interactions.py
[ ]     ├── test_molecule.py
[ ]     ├── test_pickling.py
[ ]     ├── test_residues.py
[ ]     ├── test_utils.py
    prolif/tests/plotting/
[✓]     ├── __init__.py
[ ]     ├── test_barcode.py
[ ]     ├── test_complex3d.py
[ ]     ├── test_network.py
[ ]     ├── test_residues.py
    prolif/docs/
[ ]     ├── conf.py
    prolif/prolif/
[ ]     ├── __init__.py
[ ]     ├── _version.py
[ ]     ├── datafiles.py
[ ]     ├── exceptions.py
[ ]     ├── fingerprint.py
[ ]     ├── ifp.py
[ ]     ├── molecule.py
[ ]     ├── parallel.py
[ ]     ├── pickling.py
[ ]     ├── rdkitmol.py
[ ]     ├── residue.py
[ ]     ├── utils.py
    prolif/prolif/interactions/
[ ]     ├── __init__.py
[ ]     ├── base.py
[ ]     ├── constants.py
[ ]     ├── interactions.py
[ ]     ├── utils.py
    prolif/prolif/plotting/
[ ]     ├── __init__.py
[ ]     ├── barcode.py
[ ]     ├── complex3d.py
[ ]     ├── network.py
[ ]     ├── residues.py
[ ]     ├── utils.py
    prolif/scripts/
[ ]     ├── test_build.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants