Skip to content

Commit 118c854

Browse files
author
Christopher Neugebauer
committed
Updates build config to work with JitPack
Squashed commit of the following: commit 0655550 Author: Christopher Neugebauer <chris.neugebauer@alphasights.com> Date: Wed Feb 12 14:30:44 2020 -0800 Add Jitpack Maven config to README.md commit d64dba3 Author: Christopher Neugebauer <chris.neugebauer@alphasights.com> Date: Wed Feb 12 14:24:09 2020 -0800 Add Maven plugin commit 2e846d6 Author: Christopher Neugebauer <chris.neugebauer@alphasights.com> Date: Wed Feb 12 14:23:02 2020 -0800 Makes the python dependency work with Python 2 commit 13370c9 Author: Christopher Neugebauer <chris.neugebauer@alphasights.com> Date: Wed Feb 12 14:00:38 2020 -0800 maybe normal python works? commit 7bb7174 Author: Christopher Neugebauer <chris.neugebauer@alphasights.com> Date: Wed Feb 12 13:54:56 2020 -0800 Add the new gradle wrapper version *properly*
1 parent 0efc016 commit 118c854

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

README.md

+18-4
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,31 @@ val voiceResponse = return DSLTwiML.voiceResponse {
4242

4343
## Building
4444

45-
The build script is written in Gradle, but currently depends on Python 3.6 or greater being available on your system. The
45+
The build script is written in Gradle, but currently depends on Python 2.7, or 3.5 or greater being available on your system. The
4646
Python script generates a Kotlin source file that contains the TwiML DSL, and the extensions to the TwiML builder
4747
classes that make it work.
4848

4949
## Adding to your project
5050

51-
Run `gradle build` to produce a JAR, and include the JAR as a dependency in your project. We'll investigate JitPack or
52-
other Maven options at a later date.
51+
Maven distributions are available through JitPack. To include in your Gradle project, ensure you have jitpack in your
52+
repositories
5353

54-
TODO: verify that JitPack will work with the Python dependency
54+
```
55+
allprojects {
56+
repositories {
57+
...
58+
maven { url 'https://jitpack.io' }
59+
}
60+
}
61+
```
62+
63+
and include the following build dependency:
5564

65+
```
66+
dependencies {
67+
implementation 'com.github.alphasights:kotlin-twilio-extensions:${KOTLIN_TWILIO_EXTENSIONS_VERSION}'
68+
}
69+
```
5670

5771
## Disclaimers
5872

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ plugins {
2222
}
2323

2424
apply plugin: 'org.jlleitschuh.gradle.ktlint'
25+
apply plugin: 'maven'
2526

2627
group 'com.alphasights'
2728
version '0.1-SNAPSHOT'
@@ -63,7 +64,7 @@ task generate(type:Exec) {
6364

6465
workingDir '.'
6566

66-
commandLine 'python3', 'contrib/codegen/generate.py', 'contrib/codegen/layout.json', outputDir + "KotlinTwimlDsl.kt"
67+
commandLine 'python', 'contrib/codegen/generate.py', 'contrib/codegen/layout.json', outputDir + "KotlinTwimlDsl.kt"
6768

6869
}
6970

contrib/codegen/generate.py

+31-27
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def __main__():
100100
# Generate the code!
101101

102102
# Imports go first
103-
print("package com.alphasights.kotlintwilio", file=output)
104-
print("\n".join(imports) + "\n", file=output)
103+
print(u"package com.alphasights.kotlintwilio", file=output)
104+
print(u"\n".join(imports) + u"\n", file=output)
105105

106106
# Boilerplate code and type aliases
107107
print(fmt_preamble(), file=output)
@@ -110,14 +110,14 @@ def __main__():
110110
print(fmt_dsl_definition(package_layout_code), file=output)
111111

112112
# The extenions
113-
print("\n".join(extension_code), file=output)
113+
print(u"\n".join(extension_code), file=output)
114114

115115
# Finally, a list of types that have been declared as a valid child,
116116
# but have not had code generated.
117117
missing = list(set(acceptors) - set(constructors))
118118
missing.sort()
119-
print("", file=output)
120-
print(f"/** MISSING: {missing} */", file=output)
119+
print(u"", file=output)
120+
print(u"/** MISSING: {missing} */".format(missing=missing), file=output)
121121

122122
reformatted = refmt_kotlin(output.getvalue())
123123
output_file.write(reformatted)
@@ -134,41 +134,41 @@ def importer(typespec):
134134
package = typespec.package.strip()
135135
sep = "." if package else ""
136136
name = typespec.name
137-
return f"import com.twilio.twiml.{package}{sep}{name}"
137+
return u"import com.twilio.twiml.{package}{sep}{name}".format(package=package, sep=sep, name=name)
138138

139139
def fun_constructor(typespec, declare, consume):
140140
''' Build a constructor function for the given class '''
141141
sep = ", " if declare else ""
142-
return f"""
143-
inline fun {camel(typespec.name)}({declare}{sep}f: Takes<{typespec.dsl_builder}> = {{}}): {typespec.qualified} = {typespec.dsl_builder}({consume}).apply(f).build()
144-
""".strip()
142+
return u"""
143+
inline fun {typespec.camel_name}({declare}{sep}f: Takes<{typespec.dsl_builder}> = {{}}): {typespec.qualified} = {typespec.dsl_builder}({consume}).apply(f).build()
144+
""".format(typespec=typespec, declare=declare, sep=sep, consume=consume).strip()
145145

146146
def fun_class_marked_constructor(declare, consume):
147147
''' Build a constructor function for the given class '''
148-
return f"""
148+
return u"""
149149
constructor ({declare}) : super({consume})
150-
""".strip()
150+
""".format(declare=declare, consume=consume).strip()
151151

152152
def fun_extension(typespec, acceptor, declare, consume):
153153
''' Build an extension to construct a child under the given parent class '''
154154
sep = ", " if declare else ""
155-
return f"""
156-
inline fun {acceptor.qualified}.Builder.{camel(typespec.name)}({declare}{sep}f: Takes<{typespec.dsl_builder}> = {{}}): {acceptor.qualified}.Builder = this.{camel(typespec.name)}({typespec.dsl_constructor}({consume}{sep}f))
157-
""".strip()
155+
return u"""
156+
inline fun {acceptor.qualified}.Builder.{typespec.camel_name}({declare}{sep}f: Takes<{typespec.dsl_builder}> = {{}}): {acceptor.qualified}.Builder = this.{typespec.camel_name}({typespec.dsl_constructor}({consume}{sep}f))
157+
""".format(acceptor=acceptor, typespec=typespec, declare=declare, sep=sep, consume=consume).strip()
158158

159159
def class_marked_with_constructors(typespec, constructors):
160160
''' Build a DSL-marked class to ensure TwiML verbs are appropriately restricted. '''
161161

162162
constructor_code = "\n".join(fun_class_marked_constructor(i, j) for (i, j) in constructors)
163163

164-
return f"""@TwimlMarker class {typespec.name} : {typespec.qualified}.Builder {{
164+
return u"""@TwimlMarker class {typespec.name} : {typespec.qualified}.Builder {{
165165
{constructor_code}
166166
}}
167-
"""
167+
""".format(typespec=typespec, constructor_code=constructor_code)
168168

169169
def fmt_preamble():
170170
''' The code after the import lines and before the DSL definition '''
171-
return """
171+
return u"""
172172
typealias Takes<F> = F.() -> Unit
173173
@DslMarker annotation class TwimlMarker
174174
""".strip()
@@ -181,21 +181,21 @@ def fmt_dsl_definition(package_layout):
181181
code = "\n".join(code_bits)
182182
if package:
183183
pp = package.title()
184-
value = f"""
184+
value = """
185185
object {pp} {{
186186
{code}
187187
}}
188-
""".strip() + "\n"
188+
""".format(pp=pp, code=code).strip() + "\n"
189189
else:
190-
value = f"""{code}\n"""
190+
value = """{code}\n""".format(code=code)
191191
lines.append(value)
192192
c = "\n".join(lines).strip()
193193

194-
return f"""
194+
return u"""
195195
object DSLTwiML {{
196196
{c}
197197
}}
198-
"""
198+
""".format(c=c)
199199

200200
def constructor_argstrings(args):
201201
''' Produce the argstrings for the type. Args is a list of strings formatted
@@ -207,8 +207,8 @@ def constructor_argstrings(args):
207207
consume_argstrings = []
208208
for arg in args:
209209
argname, argtype = arg.split(":")
210-
declare_argstrings.append(f"{argname}: {argtype}")
211-
consume_argstrings.append(f"{argname}")
210+
declare_argstrings.append("{argname}: {argtype}".format(argname=argname, argtype=argtype))
211+
consume_argstrings.append("{argname}".format(argname=argname))
212212

213213
declare_argstring = ", ".join(declare_argstrings)
214214
consume_argstring = ", ".join(consume_argstrings)
@@ -252,19 +252,23 @@ class TypeSpec(namedtuple("TypeSpec", ("package", "name"))):
252252
@property
253253
def qualified(self):
254254
sep = "." if self.package else ""
255-
return f"com.twilio.twiml.{self.package}{sep}{self.name}"
255+
return "com.twilio.twiml.{self.package}{sep}{self.name}".format(self=self, sep=sep)
256256

257257
@property
258258
def dsl_constructor(self):
259259
p = self.package.title()
260260
sep = "." if p else ""
261-
return f"DSLTwiML.{p}{sep}{camel(self.name)}"
261+
return "DSLTwiML.{p}{sep}{self.camel_name}".format(p=p, sep=sep, self=self)
262262

263263
@property
264264
def dsl_builder(self):
265265
p = self.package.title()
266266
sep = "." if p else ""
267-
return f"DSLTwiML.{p}{sep}{self.name}"
267+
return "DSLTwiML.{p}{sep}{self.name}".format(p=p, sep=sep, self=self)
268+
269+
@property
270+
def camel_name(self):
271+
return camel(self.name)
268272

269273
if __name__ == "__main__":
270274
__main__()

gradle/wrapper/gradle-wrapper.jar

57.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)