diff --git a/README.md b/README.md index c5f7fae..3851ec3 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,6 @@ # opengl-registry -**NOTE: The repository is currently a work-in-progress. This warning -will be removed once the first stable version is released on PyPI** - * [opengl-registry Documentation](https://opengl-registry.readthedocs.io) * [opengl-registry on PyPI](https://pypi.org/project/opengl-registry) * [opengl-registry on Github](https://github.com/moderngl/opengl-registry) diff --git a/docs/conf.py b/docs/conf.py index 2a4474b..61aaa05 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,10 +24,9 @@ author = 'Einar Forselv' # The short X.Y version -version = '0.2.0' +version = '0.3.0' # The full version, including alpha/beta/rc tags -release = '0.2.0' - +release = '0.3.0' # -- General configuration --------------------------------------------------- diff --git a/opengl_registry/__init__.py b/opengl_registry/__init__.py index a086e7d..d44ad30 100644 --- a/opengl_registry/__init__.py +++ b/opengl_registry/__init__.py @@ -1,4 +1,4 @@ from opengl_registry.reader import RegistryReader # noqa from opengl_registry.registry import Registry # noqa -__version__ = "0.2.0" +__version__ = "0.3.0" diff --git a/opengl_registry/extensions.py b/opengl_registry/extensions.py index c689944..fc6bd64 100644 --- a/opengl_registry/extensions.py +++ b/opengl_registry/extensions.py @@ -1,2 +1,29 @@ +from typing import List + class Extension: - pass + """An OpenGL extensions containins enum and command names to add""" + + def __init__(self, *, name: str, supported: str, enums: List[str], commands: List[str]): + self._name = name + self._supported = supported + self._enums = enums + self._commands = commands + + def __repr__(self) -> str: + return " str: + return self._name + + @property + def enums(self) -> List[str]: + """List if enum names to include""" + return self._enums + + @property + def commands(self) -> List[str]: + """List of command names to include""" + return self._commands diff --git a/opengl_registry/reader.py b/opengl_registry/reader.py index ae3e40a..fdc9854 100644 --- a/opengl_registry/reader.py +++ b/opengl_registry/reader.py @@ -1,5 +1,6 @@ import logging from io import StringIO +from opengl_registry.extensions import Extension from typing import Dict, List from xml.etree import ElementTree import requests @@ -244,10 +245,21 @@ def read_features(self) -> List[Feature]: return features - def read_extensions(self): + def read_extensions(self) -> Dict[str, Extension]: """Reads all extensions. Returns: List[Extension]: list of extensions """ - return [] + extensions = {} + # NOTE: Extensions done have . We can safely iter + for ext_elem in self._tree.iter("extension"): + name = ext_elem.get("name") + extensions[name] = Extension( + name=name, + supported=ext_elem.get("supported"), + enums=[e.get("name") for e in ext_elem.iter("enum")], + commands=[e.get("name") for e in ext_elem.iter("command")], + ) + + return extensions diff --git a/opengl_registry/registry.py b/opengl_registry/registry.py index e786ba4..1ebc56b 100644 --- a/opengl_registry/registry.py +++ b/opengl_registry/registry.py @@ -20,7 +20,7 @@ def __init__( enums: Dict[str, Enum] = None, commands: Dict[str, Command] = None, features: List[Feature] = None, - extensions: List[Extension] = None, + extensions: Dict[str, Extension] = None, ): """Initialize the registry. @@ -32,10 +32,10 @@ def __init__( self._enums: Dict[str, Enum] = enums or {} self._commands: Dict[str, Command] = commands or {} self._features = features or [] - self._extensions = extensions or [] + self._extensions: Dict[str, Extension] = extensions or {} def __repr__(self) -> str: - return f"" + return f"" @property def enums(self) -> Dict[str, Enum]: @@ -82,8 +82,15 @@ def remove_command(self, name: str) -> bool: return True return False + def get_extension(self, name) -> Extension: + """Get an extension by name""" + if not name.startswith("GL_"): + name = f"GL_{name}" + + return self._extensions[name] + def get_profile( - self, api: str = "gl", profile: str = "core", version: str = "3.3", extensions=None + self, api: str = "gl", profile: str = "core", version: str = "3.3", extensions=List[str], ) -> "Registry": """Get a subset of the registry""" # Create the new registry @@ -127,4 +134,12 @@ def get_profile( if not registry.remove_command(name): raise ValueError("Cannot remove command", name) + # Add extensions + for ext_name in extensions: + ext = self.get_extension(ext_name) + for name in ext.enums: + registry.add_enum(self.get_enum(name)) + for name in ext.commands: + registry.add_command(self.get_enum(name)) + return registry diff --git a/setup.py b/setup.py index 2207522..a82c2a0 100644 --- a/setup.py +++ b/setup.py @@ -2,14 +2,14 @@ setup( name="opengl-registry", - version="0.2.0", + version="0.3.0", description="A simple tool for extracting information from the OpenGL API Registry", long_description=open('README.md').read(), long_description_content_type='text/markdown', url="https://github.com/moderngl/opengl-registry", author="Einar Forselv", author_email="eforselv@gmail.com", - python_requires='>=3.5', + python_requires='>=3.6', platforms=['any'], license='MIT', packages=find_namespace_packages(include=['opengl_registry']), @@ -26,9 +26,6 @@ 'Topic :: Multimedia :: Graphics', 'Topic :: Multimedia :: Graphics :: 3D Rendering', 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', ], entry_points={ 'console_scripts': [