Skip to content
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

Add generator packaging info #236

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 5 additions & 23 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,21 @@
"version": "0.2.0",
"configurations": [
{
"name": "Run Generator (all)",
"type": "python",
"request": "launch",
"module": "generator",
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "Run Generator (select plugin)",
"name": "Run Generator",
"type": "python",
"request": "launch",
"module": "generator",
"console": "integratedTerminal",
"justMyCode": true,
"args": [
"--plugin",
"${input:plugin}"
]
"args": ["--plugin", "${input:plugin}"]
},
{
"name": "DON'T SELECT (test debug config)",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"justMyCode": false,
"purpose": [
"debug-test"
],
"purpose": ["debug-test"],
"presentation": {
"hidden": true,
"group": "",
Expand All @@ -42,12 +29,7 @@
"id": "plugin",
"type": "pickString",
"description": "Select a plugin to debug",
"options": [
"python",
"rust",
"dotnet",
"testdata"
]
"options": ["python", "rust", "dotnet", "testdata"]
}
]
}
}
44 changes: 14 additions & 30 deletions generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_parser() -> argparse.ArgumentParser:
"-p",
help="Name of a builtin plugin module. By default uses all plugins.",
type=str,
action="append",
required=True,
)
return parser

Expand Down Expand Up @@ -80,35 +80,19 @@ def main(argv: Sequence[str]) -> None:
jsonschema.validate(json_model, schema)
json_models.append(json_model)

plugins = args.plugin or []

if not plugins:
LOGGER.info("Finding plugins.")
plugin_root = pathlib.Path(__file__).parent.parent / "generator-plugins"

for item in plugin_root.iterdir():
if (
item.is_dir()
and (item / "__init__.py").exists()
and not item.name.startswith("_")
):
plugins.append(item.name)
LOGGER.info(f"Found plugins: {plugins}")
LOGGER.info("Starting code generation.")

for plugin in plugins:
LOGGER.info(f"Running plugin {plugin}.")

# load model and generate types for each plugin to avoid
# any conflicts between plugins.
spec: model.LSPModel = model.create_lsp_model(json_models)

try:
plugin_module = importlib.import_module(f"generator-plugins.{plugin}")
plugin_module.generate(spec, os.fspath(PACKAGES_ROOT / plugin))
LOGGER.info(f"Plugin {plugin} completed.")
except Exception as e:
LOGGER.error(f"Error running plugin {plugin}:", exc_info=e)
plugin = args.plugin
LOGGER.info(f"Running plugin {plugin}.")

# load model and generate types for each plugin to avoid
# any conflicts between plugins.
spec: model.LSPModel = model.create_lsp_model(json_models)

try:
plugin_module = importlib.import_module(f"generator.plugins.{plugin}")
plugin_module.generate(spec, os.fspath(PACKAGES_ROOT / plugin))
LOGGER.info(f"Plugin {plugin} completed.")
except Exception as e:
LOGGER.error(f"Error running plugin {plugin}:", exc_info=e)


if __name__ == "__main__":
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions generator/plugins/rust/rust_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
4 changes: 3 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def create_plugin(session: nox.Session):
"""Create a new plugin."""
name = input("Enter the name of the plugin: ")

plugin_root = pathlib.Path(__file__).parent / "generator-plugins" / name
plugin_root = pathlib.Path(__file__).parent / "generator" / "plugins" / name
plugin_root.mkdir(parents=True, exist_ok=True)

init_text = "\n".join(
Expand All @@ -162,6 +162,7 @@ def create_plugin(session: nox.Session):
"# Licensed under the MIT License.",
"",
f"from .{name}_utils import generate_from_spec as generate",
"",
]
)
plugin_root.joinpath("__init__.py").write_text(init_text, encoding="utf-8")
Expand Down Expand Up @@ -193,6 +194,7 @@ def create_plugin(session: nox.Session):
" return {",
' "src/lib.rs": "code for lib.rs",',
" }",
"",
]
)

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
35 changes: 35 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[metadata]
name = generator
version = 2023.0.0a3
author = Microsoft Corporation
author_email = [email protected]
description = Generates code for the Language Server Protocol types using the LSP specification.
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/microsoft/lsprotocol

[options]
packages = find:
package_dir =
= .

install_requires =
attrs
cattrs
jsonschema
importlib_resources

[options.package_data]
generator = *.json
generator.plugins.dotnet = **/*

[options.packages.find]
exclude =
tests
packages
azure-pipelines
.devcontainer
.github
.vscode

include_package_data = true