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

feat: python support #282

Closed
wants to merge 14 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,6 @@ Laboratory/C#/Benchmarks/BenchmarkDotNet.Artifacts
Core/Meta/VersionInfo.cs

.DS_Store

examples/

4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Compiler/bin/Debug/net7.0/bebopc.dll",
"args": [],
"program": "${workspaceFolder}/bin/compiler/Debug/artifacts/bebopc.dll",
"args": ["--config", "bebop.json"],
"cwd": "${workspaceFolder}/Compiler",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
Expand Down
7 changes: 6 additions & 1 deletion Compiler/CommandLineFlags.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;

Check warning on line 1 in Compiler/CommandLineFlags.cs

View workflow job for this annotation

GitHub Actions / integration-tests

Non-nullable property 'WorkingDirectory' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [/home/runner/work/bebop/bebop/Compiler/Compiler.csproj]
using System.Collections;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -198,6 +198,10 @@
"--ts ./my/output/HelloWorld.ts", true)]
public string? TypeScriptOutput { get; private set; }

[CommandLineFlag("py", "Generate Python source code to the specified file",
"--py ./my/output/HelloWorld.py", true)]
public string? PythonOutput { get; private set; }

[CommandLineFlag("namespace", "When this option is specified generated code will use namespaces",
"--cs --namespace [package]")]
public string? Namespace { get; private set; }
Expand Down Expand Up @@ -277,7 +281,8 @@
["cs"] = TempoServices.Both,
["dart"] = TempoServices.Both,
["rust"] = TempoServices.Both,
["ts"] = TempoServices.Both
["ts"] = TempoServices.Both,
["py"] = TempoServices.Both
};

/// <summary>
Expand Down Expand Up @@ -329,7 +334,7 @@
/// <summary>
/// Hide the constructor to prevent direct initializationW
/// </summary>
private CommandLineFlags(string helpText)

Check warning on line 337 in Compiler/CommandLineFlags.cs

View workflow job for this annotation

GitHub Actions / test-csharp

Non-nullable property 'WorkingDirectory' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 337 in Compiler/CommandLineFlags.cs

View workflow job for this annotation

GitHub Actions / test-rust

Non-nullable property 'WorkingDirectory' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 337 in Compiler/CommandLineFlags.cs

View workflow job for this annotation

GitHub Actions / build-compiler (macos-latest)

Non-nullable property 'WorkingDirectory' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 337 in Compiler/CommandLineFlags.cs

View workflow job for this annotation

GitHub Actions / test-dart

Non-nullable property 'WorkingDirectory' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 337 in Compiler/CommandLineFlags.cs

View workflow job for this annotation

GitHub Actions / test-typescript

Non-nullable property 'WorkingDirectory' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 337 in Compiler/CommandLineFlags.cs

View workflow job for this annotation

GitHub Actions / build-compiler (ubuntu-22.04)

Non-nullable property 'WorkingDirectory' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 337 in Compiler/CommandLineFlags.cs

View workflow job for this annotation

GitHub Actions / build-compiler (windows-latest)

Non-nullable property 'WorkingDirectory' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
HelpText = helpText;
}
Expand Down
6 changes: 5 additions & 1 deletion Core/Generators/GeneratorUtils.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Runtime.Serialization;
using System;
using System.Collections.Generic;
using System.Text;
using Core.Generators.CPlusPlus;
using Core.Generators.CSharp;
using Core.Generators.Dart;
using Core.Generators.Rust;
using Core.Generators.TypeScript;
using Core.Generators.Python;
using Core.Meta;
using Core.Meta.Extensions;

Expand Down Expand Up @@ -121,6 +123,7 @@ public static string BaseClassName(this Definition definition)
{ "dart", s => new DartGenerator(s) },
{ "rust", s => new RustGenerator(s) },
{ "ts", s => new TypeScriptGenerator(s) },
{ "py", s => new PythonGenerator(s) }
};

public static Dictionary<string, string> ImplementedGeneratorNames = new()
Expand All @@ -130,6 +133,7 @@ public static string BaseClassName(this Definition definition)
{ "dart", "Dart" },
{ "rust", "Rust" },
{ "ts", "TypeScript" },
{ "py", "Python" }
};

/// <summary>
Expand Down
426 changes: 426 additions & 0 deletions Core/Generators/Python/PythonGenerator.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Core/Generators/TypeScript/TypeScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public string CompileDecode(Definition definition)
}

/// <summary>
/// Generate the body of the <c>decode</c> function for the given <see cref=MessageDefinition"/>,
/// Generate the body of the <c>decode</c> function for the given <see cref="MessageDefinition"/>,
/// </summary>
/// <param name="definition">The message definition to generate code for.</param>
/// <returns>The generated TypeScript <c>decode</c> function body.</returns>
Expand Down
176 changes: 176 additions & 0 deletions Laboratory/Python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python
Loading
Loading