forked from pantsbuild/pantsbuild.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
howto_develop.html
582 lines (553 loc) · 32.6 KB
/
howto_develop.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!DOCTYPE html>
<html lang="en">
<!--
Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
Licensed under the Apache License, Version 2.0 (see LICENSE).
-->
<head>
<meta charset="utf-8"/>
<title>Pants Developers Guide</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="pants-logo.ico">
<!-- In case this is a "test publish", tell search engines where real version lives: -->
<link rel="canonical" href="http://pantsbuild.org/howto_develop.html">
<link rel="stylesheet" href="bootstrap-custom.min.css">
<link rel="stylesheet" href="bootstrap-custom-theme.min.css">
<link rel="stylesheet" href="docsite.css">
</head>
<body>
<div class="header">
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand navbar-brand-img" href="index.html">
<img src="pants-logo.ico" alt="[pantsbuild logo]">
</a>
<a class="navbar-brand" href="index.html">
Pants
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="/">Docs</a></li>
<li><a href="community.html">Community</a></li>
<li><a href="https://www.github.com/pantsbuild/pants">GitHub</a></li>
<li>
<form class="navbar-form navbar-left search" role="search" action="https://www.google.com/search">
<div class="form-group">
<input type="text" name="as_q" class="form-control query" placeholder="Search">
<input name="as_sitesearch" value="pantsbuild.org" type="hidden">
</div>
</form>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
</div>
<div class="page">
<div class="container-fluid">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-2">
<div class="site-toc">
<ul>
<li class="toc-h1 toc-heading">
Getting Started
</li>
<li class="toc-h1 toc-link ">
<a href="install.html">Installing Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="setup_repo.html">Setting Up Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="first_tutorial.html">Tutorial</a>
</li>
<li class="toc-h1 toc-link ">
<a href="common_tasks.html">Common Tasks</a>
</li>
<li class="toc-h1 toc-heading">
Pants Basics
</li>
<li class="toc-h1 toc-link ">
<a href="why_use_pants.html">Why Use Pants?</a>
</li>
<li class="toc-h1 toc-link ">
<a href="first_concepts.html">Pants Concepts</a>
</li>
<li class="toc-h1 toc-link ">
<a href="build_files.html">BUILD files</a>
</li>
<li class="toc-h1 toc-link ">
<a href="target_addresses.html">Target Addresses</a>
</li>
<li class="toc-h1 toc-link ">
<a href="3rdparty.html">Third-Party Dependencies</a>
</li>
<li class="toc-h1 toc-link ">
<a href="options.html">Pants Options</a>
</li>
<li class="toc-h1 toc-link ">
<a href="invoking.html">Invoking Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="reporting_server.html">Reporting Server</a>
</li>
<li class="toc-h1 toc-link ">
<a href="ide_support.html">IDE Support</a>
</li>
<li class="toc-h1 toc-heading">
JVM
</li>
<li class="toc-h1 toc-link ">
<a href="jvm_projects.html">JVM Projects with Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="3rdparty_jvm.html">JVM 3rdparty Pattern</a>
</li>
<li class="toc-h1 toc-link ">
<a href="scala.html">Scala Support</a>
</li>
<li class="toc-h1 toc-link ">
<a href="publish.html">Publishing Artifacts</a>
</li>
<li class="toc-h1 toc-link ">
<a href="from_maven.html">Pants for Maven Experts</a>
</li>
<li class="toc-h1 toc-heading">
Python
</li>
<li class="toc-h1 toc-link ">
<a href="python_readme.html">Python Projects with Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="3rdparty_py.html">Python 3rdparty Pattern</a>
</li>
<li class="toc-h1 toc-heading">
Go
</li>
<li class="toc-h1 toc-link ">
<a href="go_readme.html">Go support for Pants</a>
</li>
<li class="toc-h1 toc-heading">
Codegen
</li>
<li class="toc-h1 toc-link ">
<a href="thrift_deps.html">Thrift</a>
</li>
<li class="toc-h1 toc-heading">
Docgen
</li>
<li class="toc-h1 toc-link ">
<a href="page.html">Markdown</a>
</li>
<li class="toc-h1 toc-heading">
Getting Help
</li>
<li class="toc-h1 toc-link ">
<a href="tshoot.html">Troubleshooting</a>
</li>
<li class="toc-h1 toc-link ">
<a href="community.html">Community</a>
</li>
<li class="toc-h1 toc-heading">
Reference
</li>
<li class="toc-h1 toc-link ">
<a href="build_dictionary.html">Pants BUILD Dictionary</a>
</li>
<li class="toc-h1 toc-link ">
<a href="options_reference.html">Pants Reference</a>
</li>
<li class="toc-h1 toc-heading">
Release Notes
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.3.x.html">1.3.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.2.x.html">1.2.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.1.x.html">1.1.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.0.x.html">1.0.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-master.html">Master Pre-Releases</a>
</li>
<li class="toc-h1 toc-heading">
Developer
</li>
<li class="toc-h1 toc-link ">
<a href="dev.html">Pants Developer Center</a>
</li>
<li class="toc-h1 toc-link ">
<a href="export.html">Export Format</a>
</li>
</ul>
</div> <!-- site-toc -->
</div>
<div class="col-md-8">
<div class="content">
<div class="mainflow">
<nav class="pagetoc">
<ul>
<li class="toc-h1"><a href="#running-from-sources">Running from sources</a></li>
<li class="toc-h1"><a href="#building-pants-pex-for-production">Building Pants PEX for Production</a></li>
<li class="toc-h1"><a href="#testing">Testing</a></li>
<li class="toc-h2"><a href="#running-tests">Running Tests</a></li>
<li class="toc-h1"><a href="#debugging">Debugging</a></li>
<li class="toc-h1"><a href="#developing-and-debugging-a-jvm-tool">Developing and Debugging a JVM Tool</a></li>
<li class="toc-h2"><a href="#jvm-tool-development-tips">JVM Tool Development Tips</a></li>
</ul>
</nav>
<!-- main content start -->
<!-- generated by pants! -->
<style>
.codehilite .hll { background-color: #ffffcc }
.codehilite { background: #f0f0f0; }
.codehilite .c { color: #60a0b0; font-style: italic } /* Comment */
.codehilite .err { border: 1px solid #FF0000 } /* Error */
.codehilite .k { color: #007020; font-weight: bold } /* Keyword */
.codehilite .o { color: #666666 } /* Operator */
.codehilite .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
.codehilite .cp { color: #007020 } /* Comment.Preproc */
.codehilite .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
.codehilite .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .gr { color: #FF0000 } /* Generic.Error */
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
.codehilite .go { color: #808080 } /* Generic.Output */
.codehilite .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #0040D0 } /* Generic.Traceback */
.codehilite .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #007020 } /* Keyword.Pseudo */
.codehilite .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #902000 } /* Keyword.Type */
.codehilite .m { color: #40a070 } /* Literal.Number */
.codehilite .s { color: #4070a0 } /* Literal.String */
.codehilite .na { color: #4070a0 } /* Name.Attribute */
.codehilite .nb { color: #007020 } /* Name.Builtin */
.codehilite .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
.codehilite .no { color: #60add5 } /* Name.Constant */
.codehilite .nd { color: #555555; font-weight: bold } /* Name.Decorator */
.codehilite .ni { color: #d55537; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #007020 } /* Name.Exception */
.codehilite .nf { color: #06287e } /* Name.Function */
.codehilite .nl { color: #002070; font-weight: bold } /* Name.Label */
.codehilite .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #062873; font-weight: bold } /* Name.Tag */
.codehilite .nv { color: #bb60d5 } /* Name.Variable */
.codehilite .ow { color: #007020; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
.codehilite .mf { color: #40a070 } /* Literal.Number.Float */
.codehilite .mh { color: #40a070 } /* Literal.Number.Hex */
.codehilite .mi { color: #40a070 } /* Literal.Number.Integer */
.codehilite .mo { color: #40a070 } /* Literal.Number.Oct */
.codehilite .sb { color: #4070a0 } /* Literal.String.Backtick */
.codehilite .sc { color: #4070a0 } /* Literal.String.Char */
.codehilite .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
.codehilite .s2 { color: #4070a0 } /* Literal.String.Double */
.codehilite .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
.codehilite .sh { color: #4070a0 } /* Literal.String.Heredoc */
.codehilite .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
.codehilite .sx { color: #c65d09 } /* Literal.String.Other */
.codehilite .sr { color: #235388 } /* Literal.String.Regex */
.codehilite .s1 { color: #4070a0 } /* Literal.String.Single */
.codehilite .ss { color: #517918 } /* Literal.String.Symbol */
.codehilite .bp { color: #007020 } /* Name.Builtin.Pseudo */
.codehilite .vc { color: #bb60d5 } /* Name.Variable.Class */
.codehilite .vg { color: #bb60d5 } /* Name.Variable.Global */
.codehilite .vi { color: #bb60d5 } /* Name.Variable.Instance */
.codehilite .il { color: #40a070 } /* Literal.Number.Integer.Long */
</style>
<h1 id="pants-developers-guide">Pants Developers Guide</h1>
<p>This page describes the developer workflow when changing Pants itself. (If you wanted
instructions for using Pants to develop other programs, please see
<a href="first_tutorial.html">First Tutorial</a>.)</p>
<p>These instructions assume you've already
<a href="howto_contribute.html#download_source_code" pantsref="download_source_code">downloaded the source code</a>.</p>
<h2 id="running-from-sources">Running from sources</h2>
<p>As pants is implemented in python it can be run directly from sources.</p>
<div class="codehilite"><pre><span class="nv">$ </span>./pants goals
<remainder of output omitted <span class="k">for </span>brevity>
</pre></div>
<p>If you want to run pants from sources, but in another repo to test changes before a release, you
can run it like so:</p>
<div class="codehilite"><pre><span class="o">(</span>other repo<span class="o">)</span> <span class="nv">$ PANTS_PLUGINS</span><span class="o">=</span><span class="s2">"[]"</span> <span class="se">\</span>
<span class="nv">PANTS_PYTHONPATH</span><span class="o">=</span><span class="s2">"['/path/to/pants/repo/contrib/python/src/python']"</span> <span class="se">\</span>
<span class="nv">PANTS_BACKEND_PACKAGES</span><span class="o">=</span><span class="s2">"['pants.contrib.python.checks']"</span> <span class="se">\</span>
/path/to/pants/repo/pants compile ::
</pre></div>
<p>You may hit an error with version mismatch:</p>
<div class="codehilite"><pre>...
Exception message: Version mismatch: Requested version was 1.1.0, our version is 1.2.0-dev0.
</pre></div>
<p>If so, you can add a <code>PANTS_VERSION</code> environment variable like so:</p>
<div class="codehilite"><pre><span class="o">(</span>other repo<span class="o">)</span> <span class="nv">$ PANTS_PLUGINS</span><span class="o">=</span><span class="s2">"[]"</span> <span class="se">\</span>
<span class="nv">PANTS_PYTHONPATH</span><span class="o">=</span><span class="s2">"['/path/to/pants/repo/contrib/python/src/python']"</span> <span class="se">\</span>
<span class="nv">PANTS_BACKEND_PACKAGES</span><span class="o">=</span><span class="s2">"['pants.contrib.python.checks']"</span> <span class="se">\</span>
<span class="nv">PANTS_VERSION</span><span class="o">=</span>1.2.0-dev0 <span class="se">\</span>
/path/to/pants/repo/pants compile ::
</pre></div>
<p>Here the environment variables are used to make sure any pants plugins your other repo uses will
also be run from pants sources. Explaining each environment variable:</p>
<ul>
<li><code>PANTS_PLUGINS</code>: This should always be as-shown, ie: an empty list.</li>
<li><code>PANTS_PYTHONPATH</code>: This is a comma-separated list of PYTHONPATH elements. The values can be
taken from the pants repo pants.ini. You'll need one path per plugin your other repo uses.</li>
<li><code>PANTS_BACKEND_PACKAGES</code>: This is a comma-separated list of plugin package names. These values
can also be taken from the pants repo pants.ini. You'll need one package name per plugin your
other repo uses.</li>
<li><code>PANTS_VERSION</code>: The version of pants required by the repo.</li>
</ul>
<p>If your other repo uses plugins but you don't use this environment variable technique, or you do use
it but miss one or more plugins, pants will still run, but the result can be confusing since the
plugins not covered by the environment variable settings will run from a cached binary distribution
and not from your local edits to pants. It's worth adding temporary print statements to make sure
you're hitting your code edits if you aren't using a debugger.</p>
<h2 id="building-pants-pex-for-production">Building Pants PEX for Production</h2>
<p>You will usually want to use an official published version of pants. But what if you want to
let some of your internal users try out the latest and greatest unreleased code?
What if you want to create a custom build of pants with some unpublished patches?
In that case, you want to build a production ready version of pants including dependencies for
all platforms, not just your development environment.</p>
<p>In the following examples, you'll be using 2 local repos. The path to the pantsbuild/pants clone
will be <code>/tmp/pantsbuild</code> and the path to your repo <code>/your/repo</code> in all the examples below; make
sure to substitute your own paths when adapting this recipe to your environment.</p>
<p>You'll need to setup some files one-time in your own repo:</p>
<div class="codehilite"><pre><span class="nv">$ </span>cat pants-production.requirements.txt
<span class="c"># Replace this path with the path to your pantsbuild.pants clone.</span>
-f /tmp/pantsbuild/dist/
pantsbuild.pants
<span class="nv">$ </span>cat BUILD.pants-production
python_requirements<span class="o">(</span><span class="s1">'pants-production.requirements.txt'</span><span class="o">)</span>
python_binary<span class="o">(</span>
<span class="nv">name</span><span class="o">=</span><span class="s1">'pants'</span>,
<span class="nv">entry_point</span><span class="o">=</span><span class="s1">'pants.bin.pants_loader:main'</span>,
<span class="c"># You may want to tweak the list of supported platforms to match your environment.</span>
<span class="nv">platforms</span><span class="o">=[</span>
<span class="s1">'current'</span>,
<span class="s1">'linux-x86_64'</span>,
<span class="s1">'macosx-10.4-x86_64'</span>,
<span class="o">]</span>,
<span class="c"># You may want to adjust the python interpreter constraints, but note that pants requires</span>
<span class="c"># python2.7 currently.</span>
<span class="nv">compatibility</span><span class="o">=</span><span class="s1">'CPython>=2.7,<3'</span>,
<span class="nv">dependencies</span><span class="o">=[</span>
<span class="s1">':pantsbuild.pants'</span>,
<span class="c"># List any other pants backend local or remote deps here, ie:</span>
<span class="c"># ':pantsbuild.pants.contrib.go' or 'src/python/your/pants/plugin'</span>
<span class="o">]</span>
<span class="o">)</span>
<span class="nv">$ </span>cat pants-production.ini
<span class="o">[</span>python-repos<span class="o">]</span>
<span class="c"># You should replace these repos with your own housing pre-built eggs or wheels for the</span>
<span class="c"># platforms you support.</span>
repos: <span class="o">[</span>
<span class="s2">"https://pantsbuild.github.io/cheeseshop/third_party/python/dist/index.html"</span>,
<span class="s2">"https://pantsbuild.github.io/cheeseshop/third_party/python/index.html"</span>
<span class="o">]</span>
indexes: <span class="o">[</span><span class="s2">"https://pypi.python.org/simple/"</span><span class="o">]</span>
</pre></div>
<p>To (re-)generate a <code>pants.pex</code> you then run these 2 commands:</p>
<ol>
<li>
<p>In your pantsbuild/pants clone, create a local pants release from master:</p>
<div class="codehilite"><pre><span class="nv">$ </span>rm -rf dist <span class="o">&&</span> ./build-support/bin/release.sh -n
</pre></div>
</li>
<li>
<p>In your own repo the following command will create a locally built <code>pants.pex</code> for all platforms:</p>
<div class="codehilite"><pre><span class="nv">$ </span>/tmp/pantsbuild/pants --config-override<span class="o">=</span>pants-production.ini clean-all binary //:pants
</pre></div>
</li>
</ol>
<p>The resulting <code>pants.pex</code> will be in the <code>dist/</code> directory:</p>
<div class="codehilite"><pre><span class="nv">$ </span>ls -l dist/pants.pex
-rwxr-xr-x 1 pantsdev pantsdev 5561254 Oct 8 09:52 dist/pants.pex
</pre></div>
<p>You can see that the pex contains bundled dependencies for both mac and linux:</p>
<div class="codehilite"><pre><span class="nv">$ </span>unzip -l dist/pants.pex | grep -e <span class="s1">'macos\|linux'</span>
</pre></div>
<p>You can distribute the resulting <code>pants.pex</code> file to your users via your favorite method.
A user can just copy this pex to the top of their Pants workspace and use it:</p>
<div class="codehilite"><pre><span class="nv">$ </span>cp /mnt/fd0/pants.pex .
<span class="nv">$ </span>./pants.pex goal <span class="nb">test </span>examples/tests/java/org/pantsbuild/example/hello/greet:
</pre></div>
<h2 id="testing">Testing</h2>
<p><a id="dev_run_all_tests" pantsmark="dev_run_all_tests"> </a></p>
<h3 id="running-tests">Running Tests</h3>
<p>Pants has many tests. There are BUILD targets to run those tests. We try to keep them passing.
<a href="https://travis-ci.org/pantsbuild/pants">A Travis-CI job</a> runs tests on each SHA pushed to
origin on <code>github.com/pantsbuild/pants</code>.</p>
<p>Most test are runnable as regular Pants test targets. To find tests that work with a particular
feature, you might explore <code>tests/python/pants_tests/.../BUILD</code>.</p>
<p>Before <a href="howto_contribute.html">contributing a change to Pants</a>,
make sure it passes <strong>all</strong> of our continuous integration (CI) tests: everything builds,
all tests pass. To try all the CI tests in a few configurations, you can run the same script
that our Travis CI does. This can take a while, but it's a good idea to run it before you
contribute a change or merge it to master:</p>
<div class="codehilite"><pre><span class="nv">$ </span>./build-support/bin/ci.sh
</pre></div>
<p>To run just Pants' <em>unit</em> tests (skipping the can-be-slow integration tests), filter out
the python tests tagged with 'integration':</p>
<div class="codehilite"><pre><span class="nv">$ </span>./pants <span class="nb">test </span>tests/python/pants_test:: --tag<span class="o">=</span>-integration
</pre></div>
<p>For convenience, this is wrapped up in a script <code>build-support/bin/unit-test.sh</code>.</p>
<p>If you only want to run tests for changed targets, then you can use the
<code>test-changed</code> goal:</p>
<div class="codehilite"><pre><span class="nv">$ </span>./pants <span class="nb">test</span>-changed
</pre></div>
<p>You can run your code through the Travis-CI before you submit a change. Travis-CI is integrated
with the pull requests for the <code>pantsbuild/pants</code> repo. Travis-CI will test it soon after the pull
request is created. It will queue up a new job every time you subsequently push your branch.</p>
<p>To kick off a new CI-build, push a branch to
<a href="howto_contribute.html#download_source_code" pantsref="download_source_code">your fork</a> of <code>pantsbuild/pants</code>.
Create a pull request on the <code>pantsbuild/pants</code> <a href="https://github.com/pantsbuild/pants">repo</a>,
not your fork. If you are posting a review request, put the pull request number into the Bug
field. Then, when you close the request, you can navigate from the bug number to easily close
the pull request.</p>
<h2 id="debugging">Debugging</h2>
<p>To run Pants under <code>pdb</code> and set a breakpoint, you can typically add</p>
<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">pdb</span><span class="p">;</span> <span class="n">pdb</span><span class="o">.</span><span class="n">set_trace</span><span class="p">()</span>
</pre></div>
<p>...where you first want to break. If the code is in a test, instead use</p>
<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">pytest</span><span class="p">;</span> <span class="n">pytest</span><span class="o">.</span><span class="n">set_trace</span><span class="p">()</span>
</pre></div>
<p>To run tests and bring up <code>pdb</code> for failing tests, you can instead pass <code>--pdb</code> to
<code>test.pytest --options</code>:</p>
<div class="codehilite"><pre><span class="nv">$ </span>./pants test.pytest --options<span class="o">=</span><span class="s1">'--pdb'</span> tests/python/pants_test/tasks:
... plenty of <span class="nb">test </span>output ...
tests/python/pants_test/tasks/test_targets_help.py E
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<span class="nv">cls</span> <span class="o">=</span> <class <span class="s1">'pants_test.tasks.test_targets_help.TargetsHelpTest'</span>>
@classmethod
def setUpClass<span class="o">(</span>cls<span class="o">)</span>:
> super<span class="o">(</span>TargetsHelpTest, cls<span class="o">)</span>.setUpClass<span class="o">()</span>
E AttributeError: <span class="s1">'super'</span> object has no attribute <span class="s1">'setUpClass'</span>
tests/python/pants_test/tasks/test_targets_help.py:24: AttributeError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /Users/lhosken/workspace/pants/tests/python/pants_test/tasks/test_targets_help.py<span class="o">(</span>24<span class="o">)</span>setUpClass<span class="o">()</span>
-> super<span class="o">(</span>TargetsHelpTest, cls<span class="o">)</span>.setUpClass<span class="o">()</span>
<span class="o">(</span>Pdb<span class="o">)</span>
</pre></div>
<p>Debug quickly; that test target will time out in a couple of minutes,
quitting you out.</p>
<p>To start an interactive Python shell that can <code>import</code> Pants modules,
use the usual <code>./pants repl</code> on a <code>python_library</code> target that builds (or
depends on) the modules you want:</p>
<div class="codehilite"><pre><span class="nv">$ </span>./pants repl src/python/pants/build_graph
/Users/lhosken/workspace/pants src/python/pants/build_graph
Python 2.6.8 <span class="o">(</span>unknown, Mar 9 2014, 22:16:00<span class="o">)</span>
<span class="o">[</span>GCC 4.2.1 Compatible Apple LLVM 5.0 <span class="o">(</span>clang-500.0.68<span class="o">)]</span> on darwin
Type <span class="s2">"help"</span>, <span class="s2">"copyright"</span>, <span class="s2">"credits"</span> or <span class="s2">"license"</span> <span class="k">for </span>more information.
<span class="o">(</span>InteractiveConsole<span class="o">)</span>
>>> from pants.build_graph.target import Target
>>>
</pre></div>
<h2 id="developing-and-debugging-a-jvm-tool">Developing and Debugging a JVM Tool</h2>
<p>Some Pants tools are written in Java and Scala. If you need
to debug one of these tools and change code, keep in mind that these tools don't
run straight from the Pants source tree. They expect their jar dependencies to be
resolved through external jar dependencies. This means that to use a development
version of a tool you will need to adjust the external dependency information
in <code>BUILD.tools</code> to point Pants at a development version of your jar file.</p>
<p>First, create a jar file for the tool with the <code>binary</code> goal.</p>
<div class="codehilite"><pre><span class="nv">$ </span>./pants binary src/java/org/pantsbuild/tools/jar:main
</pre></div>
<p>The above command will create <code>dist/jar-tool.jar</code> according to the <em>jvm_binary</em>
target defined in <code>src/java/org/pantsbuild/tools/jar/BUILD</code></p>
<p>You'll need to update the jar dependency that this tool uses for Pants to see the
development version. See
<a href="3rdparty_jvm.html#test_3rdparty_jvm_snapshot" pantsref="test_3rdparty_jvm_snapshot">Using a SNAPSHOT JVM Dependency</a>
which describes how to specify the <code>url</code> and <code>mutable</code> attributes of a <code>jar</code>
dependency found on the local filesystem:</p>
<div class="codehilite"><pre><span class="n">jar_library</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'jar-tool'</span><span class="p">,</span>
<span class="n">jars</span><span class="o">=</span><span class="p">[</span>
<span class="n">jar</span><span class="p">(</span><span class="n">org</span><span class="o">=</span><span class="s">'org.pantsbuild'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'jar-tool'</span><span class="p">,</span> <span class="n">rev</span><span class="o">=</span><span class="s">'1.2.3-SNAPSHOT'</span><span class="p">,</span>
<span class="n">url</span><span class="o">=</span><span class="s">'file:///Users/squarepants/Src/pants/dist/jar-tool.jar'</span><span class="p">,</span> <span class="n">mutable</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="p">],</span>
<span class="p">)</span>
</pre></div>
<p>For debugging, append JVM args to turn on the debugger for the appropriate tool in
<code>pants.ini</code>:</p>
<div class="codehilite"><pre><span class="k">[jar-tool]</span>
<span class="na">jvm_options: ['-Xdebug', '-Xrunjdwp:transport</span><span class="o">=</span><span class="s">dt_socket,server=y,suspend=y,address=5005']</span>
</pre></div>
<p>Note that most tools run under nailgun by default. The easiest way to
debug them is to disable nailgun by specifying the command line option
<code>--no-use-nailgun</code> or setting <code>use_nailgun: False</code> in the specific tool section or in the
<code>[DEFAULT]</code> section of <code>pants.ini</code>.</p>
<div class="codehilite"><pre><span class="k">[DEFAULT]</span>
<span class="err">use_nailgun:</span> <span class="err">False</span>
</pre></div>
<h3 id="jvm-tool-development-tips">JVM Tool Development Tips</h3>
<p>If you need to debug the tool under nailgun, make
sure you run <code>pants goal ng-killall</code> or <code>pants goal clean-all</code> after you update the
jar file so that any running nailgun servers are restarted on the next invocation
of Pants.</p>
<p>Also, you may need to clean up some additional state when testing a tool. Some tools
cache a shaded version under <code>~/.cache/pants/artifact_cache/</code>. Clear out the cache
before testing a new version of the tool as follows:</p>
<div class="codehilite"><pre><span class="nv">$ </span>rm -rf ~/.cache/pants/artifact_cache
</pre></div>
<p>If you have trouble resolving the file with Ivy after making the
above changes to <code>BUILD.tools</code>:</p>
<ul>
<li>Make sure your url is absolute and contains three slashes (<code>///</code>) at the start
of the path.</li>
<li>
<p>If your repo has an <code>ivysettings.xml</code> file (the pants repo currently does not),
try adding a minimal <code><filesystem></code> resolver that doesn't enforce a pom being
present as follows:</p>
<div class="codehilite"><pre><span class="nt"><resolvers></span>
<span class="nt"><chain</span> <span class="na">name=</span><span class="s">"chain-repos"</span> <span class="na">returnFirst=</span><span class="s">"true"</span><span class="nt">></span>
<span class="nt"><filesystem</span> <span class="na">name=</span><span class="s">"internal"</span><span class="nt">></filesystem></span>
...
<span class="nt"></chain></span>
<span class="nt"></resolvers></span>
</pre></div>
</li>
</ul>
<!-- main content end -->
<div class="generated">
Generated by <a href="docs.html">publish_docs</a>
from dist/markdown/html/src/docs/howto_develop.html 2017-05-29T10:30:50.571417
</div>
</div> <!-- mainflow -->
</div> <!-- content -->
</div>
<div class="col-md-1">
</div>
</div> <!-- row -->
</div> <!-- container-fluid -->
</div> <!-- page -->
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha384-I6F5OKECLVtK/BL+8iSLDEHowSAfUo76ZL9+kGAgTRdiByINKJaqTPH/QVNS1VDb" crossorigin="anonymous"></script>
<script src="bootstrap-custom.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-78111411-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>