Skip to content

Commit 3b9fa6e

Browse files
committed
Moved Python generator out of the babelapi Python package.
Summary: It's still in the repository, but it's expected that the babelapi user will reference it by its full path rather than just "python". I want to bring this functionality back, but when I do, I'll be doing it in a slightly different way. Test Plan: Re-ran tests and used babelapi. Reviewed By: guido
1 parent 36d175e commit 3b9fa6e

39 files changed

+27
-5555
lines changed

README.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ service. Our hypothetical spec lives in a file called ``users.babel``::
185185
"Get information about a specified user's account."
186186

187187
Using the Python generator, we can generate a Python module that mirrors this
188-
specification using the command-line interface::
188+
specification using the command-line interface. From the top-level of the
189+
``babelapi`` folder, try::
189190

190-
$ babelapi python users.babel .
191+
$ babelapi generator/python/python.babelg.py users.babel .
191192
INFO:babelapi.idl:Parsing spec users.babel
192193
INFO:babelapi.compiler:Found generator at ...
193194
INFO:babelapi.compiler:Running generator ...

TODO.rst

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
Todo
22
====
33

4-
- Fix up internal exceptions
5-
- Babel test cases
6-
- Add docstrings to tower.py
7-
- Figure out how we would support a non-template based generator.
84
- Introduce a file that imports all the necessary babel descriptions together.
95
- Version should be specified in this file, or overwritten on the command line?
10-
- Autogenerated tests / testserver1/2
11-
- Fix server code to not output "OrderedDict" in code. Or, fix pretty print to do it better.
12-
- Accept indentation besides 4 spaces.
136
- Out of order type declarations.
147
- List(data_type=Float32) -> List(Float32)
158
- Add tuple type. Only needed for v1 endpoints (ex. delta)
16-
- Perhaps errors shouldn't be printed to stdout immediately. They should be collected by the parser,
179
and then printed by the caller if desired.
1810
- Switch symbol lookup in environment to dynamic lookup.
1911
- This lets us have circular references... as well as out of order declarations.
20-
- Bug with indent/dedent token generation when comments, newlines, and
21-
superfluous indents are mixed together.
22-
- Add "Schema Evolution" section to README.
23-
- Add feature to generate one route per file.

babelapi/cli.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
_cmdline_parser.add_argument(
2424
'generator',
2525
type=str,
26-
help='Specify a pre-packaged generator (only "python" right now), or '
27-
'the path to a custom generator (.babelg.py).',
26+
help='Specify the path to a generator. It must have a .babelg.py extension.',
2827
)
2928
_cmdline_parser.add_argument(
3029
'spec',
3130
nargs='+',
3231
type=str,
33-
help='Path to API specifications (*.babel).',
32+
help='Path to API specifications. Each must have a .babel extension.',
3433
)
3534
_cmdline_parser.add_argument(
3635
'output',
@@ -94,18 +93,9 @@ def main():
9493
'You must fix the above parsing errors for generation to continue.'
9594
sys.exit(1)
9695

97-
# Here we support two ways of specifying a generator. Either a name of a
98-
# generator, which assumes it has been pre-packaged with babelapi, or a
99-
# path to a Python module with a generator class defined within.
100-
if args.generator == 'python':
101-
generator = os.path.join(os.path.dirname(__file__),
102-
'generator/target/python/python.babelg.py')
103-
else:
104-
generator = args.generator
105-
10696
c = Compiler(
10797
api,
108-
generator,
98+
args.generator,
10999
args.output,
110100
clean_build=args.clean_build,
111101
)

babelapi/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import shutil
88

9-
from babelapi.generator.generator import Generator
9+
from babelapi.generator import Generator
1010

1111
class UnknownGenerator(Exception): pass
1212
class UnknownSourceType(Exception): pass

babelapi/data_type.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
44
The goal of this module is to define all data types that are common to the
55
languages and serialization formats we want to support.
6-
7-
TODO: This file is in need of refactoring, and should take after the
8-
babelapi.generator.target.python.babel_validators module.
96
"""
107

118
from abc import ABCMeta, abstractmethod

babelapi/generator/__init__.py

Whitespace-only changes.

babelapi/generator/target/__init__.py

Whitespace-only changes.

babelapi/generator/target/python/__init__.py

Whitespace-only changes.

doc/using_generator.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,21 @@ command-line interface (CLI)::
3030
BabelAPI
3131

3232
positional arguments:
33-
generator Specify a pre-packaged generator (only "python" right now),
34-
or the path to a custom generator (.babelg.py).
35-
spec Path to API specifications (*.babel).
33+
generator Specify the path to a generator. It must have a .babelg.py
34+
extension.
35+
spec Path to API specifications. Each must have a .babel
36+
extension.
3637
output The folder to save generated files to.
3738

3839
optional arguments:
3940
-h, --help show this help message and exit
4041
-v, --verbose Print debugging statements.
4142

4243
We'll compile the ``users.babel`` example from the
43-
`Language Reference <lang_ref.rst>`_::
44+
`Language Reference <lang_ref.rst>`_. THe first argument is the path to the
45+
Python generator which can be found in the ``babelapi`` folder::
4446

45-
$ babelapi python users.babel .
47+
$ babelapi generator/python/python.babelg.py users.babel .
4648
INFO:babelapi.idl:Parsing spec users.babel
4749
INFO:babelapi.compiler:Found generator at ...
4850
INFO:babelapi.compiler:Running generator ...
@@ -58,14 +60,14 @@ of the code generator to the current directory.
5860
Python Guide
5961
============
6062

61-
This section explains how to generate Python code and work with the Python
62-
classes that have been generated from a spec.
63+
This section explains how to use the pre-packaged Python generator and work
64+
with the Python classes that have been generated from a spec.
6365

6466
From the above section, you can generate Python using::
6567

66-
$ babelapi python users.babel .
68+
$ babelapi generator/python/python.babelg.py users.babel .
6769

68-
This runs the ``python`` generator on the ``users.babel`` spec. Its output
70+
This runs the Python generator on the ``users.babel`` spec. Its output
6971
target is ``.``, which is the current directory. A Python module is created for
7072
each declared namespace, so in this case only ``users.py`` is created.
7173

0 commit comments

Comments
 (0)