forked from sympy/sympy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
spt-printable.html
1395 lines (1262 loc) · 57.3 KB
/
spt-printable.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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
<title>SymPy Patches Tutorial</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 5196 2007-06-03 20:25:28Z wiemann $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left {
clear: left }
img.align-right {
clear: right }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font-family: serif ;
font-size: 100% }
pre.literal-block, pre.doctest-block {
margin-left: 2em ;
margin-right: 2em }
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="sympy-patches-tutorial">
<span id="patches-tutorial"></span>
<h1 class="title">SymPy Patches Tutorial</h1>
<p>(<a class="reference external" href="spt-printable.html">printable version</a>)</p>
<!-- TODO reenable it when we fix sidebar handling in sphinx -->
<!-- .. sidebar:: Talk is cheap. Show me the code. -->
<blockquote class="epigraph">
<p>Talk is cheap. Show me the code.</p>
<p class="attribution">—Linus Torvalds <a class="footnote-reference" href="#id9" id="id1">[1]</a></p>
</blockquote>
<div class="section" id="for-impatient">
<h1>For impatient</h1>
<p>If you just want to create a couple of patches in 5 minutes and be done with
it, follow the <a class="reference internal" href="#quick-start">Quick Start</a> in the Appendix. However, if you want to make your
work more effective and also learn how we work, read this whole tutorial.</p>
</div>
<div class="section" id="introduction">
<h1>Introduction</h1>
<p>In <a class="reference external" href="http://sympy.org/">SymPy</a> we encourage collaborative work.</p>
<p>Everyone is welcome to join and to implement new feature, fix some bug, give
general advice, etc... Also, we try to discuss everything and to review each
other's work so that many eyes can see more thus raising the quality.</p>
<p>General discussion takes place on <a class="reference external" href="http://groups.google.com/group/sympy">sympy@googlecode.com</a> mailing list and in
the <a class="reference external" href="http://code.google.com/p/sympy/issues/list">issues</a>, and the code is discussed in <a class="reference external" href="http://groups.google.com/group/sympy-patches">sympy-patches@googlecode.com</a>
mailing list.</p>
<p>As someone of you already know, software development is not just coding. A lot
of non-coding tasks have to be done in order to produce <em>good</em> code. Just to
mention a few: setting up infrastructure, designing, testing, documenting,
assisting new developers (we are doing it here), and of course programming.</p>
<p>But even programming is not all about writing the code, it is about writing the
code <em>and</em> preparing it so that the code can be included into the project.</p>
<p>Both producing the code and bringing it to the project are important parts of
the game -- without the code there is nothing to bring in, and having the code
outside is a nowin for anyone.</p>
<p>As already said above, we review changes. This idea was borrowed from
successful projects like Linux, Python, SAGE and a lot more. In short each
change is first reviewed by other developers and only when it is approved the
code is pushed in.</p>
<p>Like it takes effort to write good and clear code, reviewing other's work needs
effort too. There are good practices how to do things so that reviewing is fun
for both the author and the reviewer. We try to follow them, and we'll try to
show you how to follow too.</p>
<p>This tutorial will guide you how to do SymPy development with Mercurial and
patches.</p>
<!-- .. sidebar:: By the way -->
<div class="admonition-by-the-way admonition">
<p class="first admonition-title">By the way</p>
<p class="last">when reviewing other's patches you <em>learn</em> a lot, so why not to join as a
reviewer too?</p>
</div>
</div>
<div class="section" id="workflow">
<h1>Workflow</h1>
<p>Here we'll describe the workflow using real world example where we fix some bug.</p>
<div class="section" id="hacking">
<h2>Hacking</h2>
<p>Suppose I want to fix issue <cite>#755</cite></p>
<img alt="pics/1b.png" src="pics/1b.png" />
<p>I go there</p>
<img alt="pics/2.png" src="pics/2.png" />
<p>Look at the problem description</p>
<img alt="pics/3b.png" src="pics/3b.png" />
<p>...</p>
<img alt="pics/4b.png" src="pics/4b.png" />
<p>Aah, it looks like printing code in <cite>sympy/printing/printer.py</cite> tries to treat
<cite>expr</cite> as an instance of a new-style class. I think I know how to fix this!</p>
<img alt="pics/5b.png" src="pics/5b.png" />
<p>Ok, going to dive into the problem.</p>
<p>First of all there exist two approaches to work:</p>
<ol class="arabic simple">
<li>doing all the work in one repository, and</li>
<li>creating new repository for each task</li>
</ol>
<p>In practice both of them have pros and cons, but we'll consider the second one
as it does the job and is simpler.</p>
<p>So, let's clone main repo, and go hacking</p>
<div class="admonition-by-the-way admonition">
<p class="first admonition-title">By the way</p>
<p>if you haven't already done so, do</p>
<pre class="last literal-block">
$ <strong class="input">hg clone http://hg.sympy.org/sympy</strong>
</pre>
</div>
<pre class="literal-block">
$ <strong class="input">hg clone sympy sympy-fix755</strong>
updating working directory
386 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ <strong class="input">cd sympy-fix755</strong>
</pre>
<div class="note">
<p class="first admonition-title">Note</p>
<p>This is a real-life example. If you want to repeat the exact steps, update
your working directory to 4962f6641827 revision now:</p>
<pre class="last literal-block">
$ <strong class="input">hg up 4962f6641827</strong>
</pre>
</div>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">We now recommend to use git. This tutorial was written when we still used
mercurial. See our <a class="reference internal" href="#quick-start">Quick Start</a> for an introduction to git and use our
<a class="reference external" href="http://wiki.sympy.org/wiki/Git_hg_rosetta_stone">Git hg rosetta stone</a>
wiki page to learn how to translate commands between mercurial and git. The
ideas in this tutorial stay correct, the exact commands can be a little
different with git though.</p>
</div>
<p>I use <a class="reference external" href="http://www.vim.org/">vim</a> editor, and usually it is very handy to navigate by tags, so I build
tags database first, then invoke my editor <a class="footnote-reference" href="#id10" id="id2">[2]</a></p>
<pre class="literal-block">
$ <strong class="input">ctags -R</strong>
$ <strong class="input">vim</strong>
</pre>
<p>It was in <cite>_print</cite> function, so I locate it using tags</p>
<img alt="pics/6.png" src="pics/6.png" />
<p>here it is</p>
<img alt="pics/7.png" src="pics/7.png" />
<p>and here is the failing code</p>
<img alt="pics/8.png" src="pics/8.png" />
<p>Aah, it seems old classes do not have the attribute <cite>__class__</cite>. Let's see if
this is the gist of the problem.</p>
<pre class="literal-block">
$ <strong class="input">./bin/isympy</strong>
In [1]: <strong class="input">class C: pass</strong>
...:
In [2]: <strong class="input">C</strong>
---------------------------------------------------------------------------
exceptions.AttributeError Traceback (most recent call last)
...
AttributeError: class C has no attribute '__class__'
</pre>
<p>Yes, it is. So I change it to what would always work. Then I invoke <cite>hq</cite> <a class="footnote-reference" href="#id11" id="id3">[3]</a>
to see what I've changed:</p>
<pre class="literal-block">
$ <strong class="input">hq</strong>
</pre>
<img alt="pics/9.png" src="pics/9.png" />
<p>and its time to see whether this fixes the problem</p>
<pre class="literal-block">
In [1]: <strong class="input">import sympy</strong>
In [2]: <strong class="input">sympy.__dict__</strong>
</pre>
<p>oops, another bug seems to be sitting there:</p>
<img alt="pics/10.png" src="pics/10.png" />
<p>after some examination it turned out to be a problem related to pretty-printing
of sequences with even height</p>
<pre class="literal-block">
In [3] <strong class="input">{x**2: 1}</strong>
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most recent call last)
...
ValueError: xobj: expect length = 2*k+1
</pre>
<p>I decided to add another row for this case</p>
<pre class="literal-block">
$ <strong class="input">hqq</strong> # <a class="reference external" href="spt-patches/1.patch">full diff at this stage</a>
</pre>
<img alt="pics/11.png" src="pics/11.png" />
<p>since after all it looks good:</p>
<pre class="literal-block">
In [1]: <strong class="input">[x**2]</strong>
Out[1]:
⎡ 2⎤
⎣x ⎦
In [2]: <strong class="input">(x**2,)</strong>
Out[2]:
⎛ 2⎞
⎝x ⎠
In [3]: <strong class="input">{x**2: 1}</strong>
Out[3]:
⎧ 2 ⎫
⎨x : 1⎬
⎩ ⎭
</pre>
<p>so why not?</p>
<p>Now let's verify that printing tests pass</p>
<pre class="literal-block">
$ <strong class="input">py.test sympy/printing/</strong>
============================= test process starts ==============================
executable: /usr/bin/python2.5 (2.5.0-final-0)
using py lib: /home/kirr/src/tools/py/py-0.9.0/py <rev unknown>
sympy/printing/tests/test_gtk.py[1] f
sympy/printing/tests/test_latex.py[8] .......f
sympy/printing/tests/test_mathml.py[6] .....f
sympy/printing/tests/test_pretty.py[10] .........f
sympy/printing/tests/test_pretty_unicode.py[10] ..........
sympy/printing/tests/test_python.py[6] ......
============== tests finished: 37 passed, 4 xfail in 0.30 seconds =============
</pre>
<p>Everything seems to be ok with pprinting evenly heighted sequences. Let's
get back to original problem:</p>
<pre class="literal-block">
In [1]: <strong class="input">class C: pass</strong>
...:
In [2]: <strong class="input">C</strong>
Out[2]: __main__.C
In [3]: <strong class="input">import sympy</strong>
In [4]: <strong class="input">sympy.__dict__</strong>
(a lot is printed)
</pre>
<p>ok, it works.</p>
<p>Let's write tests (this is important)</p>
<pre class="literal-block">
$ <strong class="input">hqq</strong> # <a class="reference external" href="spt-patches/2.patch">2.patch</a>
</pre>
<img alt="pics/12.png" src="pics/12.png" />
<p>Also, when looking at <cite>_print</cite> function again, I've noticed there are typos in
<cite>printer.py</cite> so I've spellchecked the whole file</p>
<pre class="literal-block">
$ <strong class="input">hqq</strong> # <a class="reference external" href="spt-patches/3.patch">3.patch</a>
</pre>
<img alt="pics/13.png" src="pics/13.png" />
<p>It seems we have done the job now.</p>
<p>To ensure everything stays in shape, let's see if all tests pass</p>
<pre class="literal-block">
$ <strong class="input">./setup.py test</strong>
running test
============================= test process starts ==============================
executable: /usr/bin/python2.5 (2.5.0-final-0)
using py lib: /home/kirr/src/tools/py/py-0.9.0/py <rev unknown>
sympy/concrete/tests/test_gosper.py[2] ..
sympy/concrete/tests/test_products.py[3] ...
sympy/concrete/tests/test_sums_products.py[9] ......fff
sympy/core/tests/test_arit.py[35] .................................ff
sympy/core/tests/test_assumptions.py[18] ................ff
sympy/core/tests/test_basic.py[24] ........................
sympy/core/tests/test_complex.py[10] ..........
sympy/core/tests/test_count_ops.py[1] .
sympy/core/tests/test_diff.py[3] ...
sympy/core/tests/test_equal.py[4] ....
sympy/core/tests/test_eval.py[8] .......f
sympy/core/tests/test_eval_power.py[6] ......
sympy/core/tests/test_functions.py[20] ................fff.
sympy/core/tests/test_match.py[24] .......................f
sympy/core/tests/test_numbers.py[20] ....................
sympy/core/tests/test_relational.py[2] ..
sympy/core/tests/test_str.py[8] ........
sympy/core/tests/test_subs.py[13] .............
...
== tests finished: 712 passed, 1 xpass, 60 xfail, 4 skipped in 125.20 seconds ==
Testing docstrings.
</pre>
<p>Good.</p>
</div>
<div class="section" id="back-to-version-control">
<h2>Back to version control</h2>
<p>We've finished hacking, and it's time to remember about version control. The
goal is to prepare our work for inclusion into the project.</p>
<p>First, there are three semantically independent changes made:</p>
<ol class="arabic simple">
<li><cite>_print</cite> dispatcher was fixed to handle old-style classes correctly</li>
<li>we fixed pretty-printing to handle vertical objects of even height</li>
<li>typos in <cite>sympy/printing/printer.py</cite> were fixed</li>
</ol>
<p>It is good to structure changes, and as said in the <a class="reference internal" href="#introduction">Introduction</a> we try to
make the whole process fun for all, so let's prepare three separate patches for
each change. This way it would be easier to review them.</p>
<p>For this we are going to use <a class="reference external" href="http://www.selenic.com/mercurial/wiki/index.cgi/MqExtension">Mercurial Queues</a> and <a class="reference external" href="http://www.selenic.com/mercurial/wiki/index.cgi/RecordExtension">Record</a> extensions.</p>
<div class="admonition-by-the-way admonition">
<p class="first admonition-title">By the way</p>
<p>if you haven't already done so, include the following lines into your <cite>~/.hgrc</cite>:</p>
<pre class="last literal-block">
[extensions]
hgext.mq =
hgext.record =
</pre>
</div>
<p>I'm going to record fix for <cite>#755</cite> first</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">The command <cite>qrecord</cite> below was introduced in Mercurial 1.0. If you have an
older version of Mercurial, consider upgrading it. If that is not possible,
you can use <cite>hg qnew -f</cite> and <cite>hg qrefresh</cite> commands -- they'll do the job,
although they are not-so-convenient when you work on several things
at once (that's why <cite>qrecord</cite> was invented).</p>
</div>
<pre class="literal-block">
$ <strong class="input">hg qrecord --edit pprint-fix-old-classes.patch</strong>
diff --git a/sympy/printing/pretty/pretty_symbology.py b/sympy/printing/pretty/pretty_symbology.py
1 hunks, 5 lines changed
examine changes to 'sympy/printing/pretty/pretty_symbology.py'? [Ynsfdaq?] <strong class="input">n</strong>
diff --git a/sympy/printing/printer.py b/sympy/printing/printer.py
3 hunks, 6 lines changed
examine changes to 'sympy/printing/printer.py'? [Ynsfdaq?] <strong class="input">y</strong>
@@ -22,7 +22,7 @@
Also, if BAR is a subclass of FOO, _print_FOO(bar) will be called for
instance of BAR, if no _print_BAR is provided. Thus, usually, we don't
- need to provide prining routines for every class we want to support --
+ need to provide printing routines for every class we want to support --
only generic routine has to be provided for a set of classes.
A good example for this are functions - for example PrettyPrinter only
record this change to 'sympy/printing/printer.py'? [Ynsfdaq?] <strong class="input">n</strong>
@@ -52,7 +52,7 @@
It's job is to loop through expr classes (class + it's bases), and
try to dispatch the work to _print_<EXPR_CLASS>
- e.g., suppose we have the following class hierarcy::
+ e.g., suppose we have the following class hierarchy::
Basic
|
record this change to 'sympy/printing/printer.py'? [Ynsfdaq?] <strong class="input">n</strong>
@@ -90,7 +90,7 @@
# See if the class of expr is known, or if one of its super
# classes is known, and use that print function
res = None
- for cls in expr.__class__.__mro__:
+ for cls in type(expr).__mro__:
if hasattr(self, '_print_'+cls.__name__):
res = getattr(self, '_print_'+cls.__name__)(expr, *args)
break
record this change to 'sympy/printing/printer.py'? [Ynsfdaq?] <strong class="input">y</strong>
diff --git a/sympy/printing/tests/test_pretty.py b/sympy/printing/tests/test_pretty.py
1 hunks, 9 lines changed
examine changes to 'sympy/printing/tests/test_pretty.py'? [Ynsfdaq?] <strong class="input">y</strong>
@@ -215,3 +215,12 @@
def test_pretty_limits():
assert pretty( limit(x, x, oo, evaluate=False) ) == ' lim x\nx->oo '
assert pretty( limit(x**2, x, 0, evaluate=False) ) == ' 2\nlim x \nx->0 '
+
+def test_pretty_class():
+ """test that printer dispatcher correctly handles classes"""
+ class C: pass # C has no .__class__ and this was causing problems
+ class D(object): pass
+
+ assert pretty( C ) == "test_pretty.C"
+ assert pretty( D ) == "<class 'test_pretty.D'>"
+
record this change to 'sympy/printing/tests/test_pretty.py'? [Ynsfdaq?] <strong class="input">y</strong>
diff --git a/sympy/printing/tests/test_pretty_unicode.py b/sympy/printing/tests/test_pretty_unicode.py
1 hunks, 27 lines changed
examine changes to 'sympy/printing/tests/test_pretty_unicode.py'? [Ynsfdaq?] <strong class="input">n</strong>
</pre>
<p>Pay attention to how I carefully choose which hunks go into this patch and
which do not. Especially note how <strong>some</strong> changes made to <cite>printer.py</cite> were
recorded and other changes (spelling fixes) were left intact in the work dir.</p>
<p>Then an editor is popped up and asks about commit message:</p>
<pre class="literal-block">
<strong class="input">pprint: fix handling of old-style classes (#755)</strong>
<strong class="input">We used to dispatch based on expr.__class__.__mro__, but when expr is an</strong>
<strong class="input">old-style class we failed, because old-style classes do not have __class__</strong>
<strong class="input">attribute.</strong>
<strong class="input">Let's just use type(expr).__mro__ which works in all cases.</strong>
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: --
HG: user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
HG: branch 'default'
HG: changed sympy/printing/printer.py
HG: changed sympy/printing/tests/test_pretty.py
</pre>
<p>Now you have one patch applied</p>
<pre class="literal-block">
$ <strong class="input">hg qapplied</strong>
<a class="reference external" href="spt-patches/pprint-fix-old-classes.patch">pprint-fix-old-classes.patch</a>
</pre>
<p>and work-dir changes shrinked somewhat</p>
<pre class="literal-block">
$ <strong class="input">hqq</strong> # <a class="reference external" href="spt-patches/4.patch">4.patch</a>
</pre>
<img alt="pics/14.png" src="pics/14.png" />
<p>note, how there is no more <cite>expr.__class__</cite> -> <cite>type(expr)</cite> change in <cite>hqq</cite> output.</p>
<p>Congratulations, you've recorded your first patch!</p>
<p>Let's proceed with pprint</p>
<pre class="literal-block">
$ <strong class="input">hg qrecord -e xobj-fix-even-height.patch</strong>
diff --git a/sympy/printing/pretty/pretty_symbology.py b/sympy/printing/pretty/pretty_symbology.py
1 hunks, 5 lines changed
examine changes to 'sympy/printing/pretty/pretty_symbology.py'? [Ynsfdaq?] <strong class="input">y</strong>
@@ -311,7 +311,10 @@
if bot is None: bot = ext
if mid is not None:
if (length % 2) == 0:
- raise ValueError('xobj: expect length = 2*k+1')
+ # even height, but we have to print it somehow anyway...
+ # XXX is it ok?
+ length += 1
+
else:
mid = ext
record this change to 'sympy/printing/pretty/pretty_symbology.py'? [Ynsfdaq?] <strong class="input">y</strong>
diff --git a/sympy/printing/printer.py b/sympy/printing/printer.py
2 hunks, 4 lines changed
examine changes to 'sympy/printing/printer.py'? [Ynsfdaq?] <strong class="input">n</strong>
diff --git a/sympy/printing/tests/test_pretty_unicode.py b/sympy/printing/tests/test_pretty_unicode.py
1 hunks, 27 lines changed
examine changes to 'sympy/printing/tests/test_pretty_unicode.py'? [Ynsfdaq?] <strong class="input">y</strong>
@@ -198,3 +198,30 @@
assert u == s
+def test_upretty_seq_even():
+ """there used to be a bug when pprinting sequences with even height"""
+ u = upretty([x**2])
+ s = \
+u"""\
+⎡ 2⎤
+⎣x ⎦\
+"""
+ assert u == s
+
+ u = upretty((x**2,))
+ s = \
+u"""\
+⎛ 2⎞
+⎝x ⎠\
+"""
+ assert u == s
+
+ u = upretty({x**2: 1})
+ s = \
+u"""\
+⎧ 2 ⎫
+⎨x : 1⎬
+⎩ ⎭\
+"""
+ assert u == s
+
record this change to 'sympy/printing/tests/test_pretty_unicode.py'? [Ynsfdaq?] <strong class="input">y</strong>
</pre>
<p>entering patch description...</p>
<pre class="literal-block">
<strong class="input">pretty: fix xobj for even height</strong>
<strong class="input">Previously pprint({x**2: 1}) was failing with cryptic exception</strong>
<strong class="input">ValueError: xobj: expect length = 2*k+1</strong>
<strong class="input">And this is a wrong approach.</strong>
<strong class="input">Things need to just work, so I've modified xobj to tweak evenly heighted</strong>
<strong class="input">objects somewhat. After all it looks good, so why not?</strong>
<strong class="input">In [1]: [x**2]</strong>
<strong class="input">Out[1]:</strong>
<strong class="input">⎡ 2⎤</strong>
<strong class="input">⎣x ⎦</strong>
<strong class="input">In [2]: (x**2,)</strong>
<strong class="input">Out[2]:</strong>
<strong class="input">⎛ 2⎞</strong>
<strong class="input">⎝x ⎠</strong>
<strong class="input">In [3]: {x**2: 1}</strong>
<strong class="input">Out[3]:</strong>
<strong class="input">⎧ 2 ⎫</strong>
<strong class="input">⎨x : 1⎬</strong>
<strong class="input">⎩ ⎭</strong>
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: --
HG: user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
HG: branch 'default'
HG: changed sympy/printing/pretty/pretty_symbology.py
HG: changed sympy/printing/tests/test_pretty_unicode.py
</pre>
<p>Congrats, now we have two patches recorded:</p>
<pre class="literal-block">
$ <strong class="input">hg qapplied</strong>
<a class="reference external" href="spt-patches/pprint-fix-old-classes.patch">pprint-fix-old-classes.patch</a>
<a class="reference external" href="spt-patches/xobj-fix-even-height.patch">xobj-fix-even-height.patch</a>
</pre>
<p>and workdir is left with only spelling fixes:</p>
<pre class="literal-block">
$ <strong class="input">hqq</strong> # <a class="reference external" href="spt-patches/5.patch">5.patch</a>
</pre>
<img alt="pics/15.png" src="pics/15.png" />
<p>Let's finish it</p>
<pre class="literal-block">
$ <strong class="input">hg qrecord -e printer-fix-typos.patch</strong>
diff --git a/sympy/printing/printer.py b/sympy/printing/printer.py
2 hunks, 4 lines changed
examine changes to 'sympy/printing/printer.py'? [Ynsfdaq?] <strong class="input">y</strong>
@@ -22,7 +22,7 @@
Also, if BAR is a subclass of FOO, _print_FOO(bar) will be called for
instance of BAR, if no _print_BAR is provided. Thus, usually, we don't
- need to provide prining routines for every class we want to support --
+ need to provide printing routines for every class we want to support --
only generic routine has to be provided for a set of classes.
A good example for this are functions - for example PrettyPrinter only
record this change to 'sympy/printing/printer.py'? [Ynsfdaq?] <strong class="input">y</strong>
@@ -52,7 +52,7 @@
It's job is to loop through expr classes (class + it's bases), and
try to dispatch the work to _print_<EXPR_CLASS>
- e.g., suppose we have the following class hierarcy::
+ e.g., suppose we have the following class hierarchy::
Basic
|
record this change to 'sympy/printing/printer.py'? [Ynsfdaq?] <strong class="input">y</strong>
</pre>
<pre class="literal-block">
<strong class="input">printer.py: fix typos</strong>
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: --
HG: user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
HG: branch 'default'
HG: changed sympy/printing/printer.py
</pre>
<p>Now we have three patches applied</p>
<pre class="literal-block">
$ <strong class="input">hg qapplied</strong>
<a class="reference external" href="spt-patches/pprint-fix-old-classes.patch">pprint-fix-old-classes.patch</a>
<a class="reference external" href="spt-patches/xobj-fix-even-height.patch">xobj-fix-even-height.patch</a>
<a class="reference external" href="spt-patches/printer-fix-typos.patch">printer-fix-typos.patch</a>
</pre>
<p>and clean workdir</p>
<pre class="literal-block">
$ <strong class="input">hg st</strong>
$ <strong class="input">hg diff</strong>
$
</pre>
<p>Here is a bit of history:</p>
<pre class="literal-block">
$ <strong class="input">hg glog -l4</strong>
@ changeset: 1902:dff9895d1d23
| tag: qtip
| tag: printer-fix-typos.patch
| tag: tip
| user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
| date: Mon Mar 24 22:44:05 2008 +0300
| summary: printer.py: fix typos
|
o changeset: 1901:787707e1a28c
| tag: xobj-fix-even-height.patch
| user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
| date: Mon Mar 24 22:44:04 2008 +0300
| summary: pretty: fix xobj for even height
|
o changeset: 1900:b2321483936b
| tag: pprint-fix-old-classes.patch
| tag: qbase
| user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
| date: Mon Mar 24 22:44:04 2008 +0300
| summary: pprint: fix handling of old-style classes (#755)
|
o changeset: 1899:4962f6641827
| tag: qparent
| user: Ondrej Certik <<a class="reference external" href="mailto:ondrej@certik.cz">ondrej@certik.cz</a>>
| date: Sat Mar 22 13:35:55 2008 +0100
| summary: Failing doctests were fixed. This was triggered by a different ordering.
|
</pre>
<p>and a nice graphical history browser is handy</p>
<pre class="literal-block">
$ <strong class="input">hg view</strong>
</pre>
<img alt="pics/16.png" src="pics/16.png" />
<p>Yep!</p>
</div>
<div class="section" id="patches-are-ready-lets-send-them-for-review">
<h2>Patches are ready, lets send them for review</h2>
<p>At this stage we are done with preparing our patches, and it is time to send
them for review.</p>
<p>First, let's rebase them to the latest tip.</p>
<p>For this we go to <cite>sympy</cite> mirroring repository, see whats new, and pull updates:</p>
<pre class="literal-block">
$ <strong class="input">cd ../sympy/</strong>
$ <strong class="input">hg in</strong>
comparing with <a class="reference external" href="http://hg.sympy.org/sympy">http://hg.sympy.org/sympy</a>
searching for changes
changeset: 1900:0bc73e367102
user: Ondrej Certik <<a class="reference external" href="mailto:ondrej@certik.cz">ondrej@certik.cz</a>>
date: Sat Mar 22 16:06:47 2008 +0100
summary: The print ordering of Add has been improved.
changeset: 1901:7cd8948a664a
user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
date: Mon Mar 24 00:17:12 2008 +0300
summary: [1/2] let's use __slots__
changeset: 1902:529ba5e4a7c6
user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
date: Mon Mar 24 00:17:13 2008 +0300
summary: [2/2] let's use __slots__
changeset: 1903:115df7b1ee75
user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
date: Mon Mar 24 00:17:14 2008 +0300
summary: add comments to Mul.flatten
changeset: 1904:75544c92be1d
tag: tip
user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
date: Mon Mar 24 01:19:27 2008 +0300
summary: slightly speedup Basic.__getattr__
$ <strong class="input">hg pull --update</strong>
pulling from <a class="reference external" href="http://hg.sympy.org/sympy">http://hg.sympy.org/sympy</a>
searching for changes
adding changesets
adding manifests
adding file changes
added 5 changesets with 26 changes to 21 files
21 files updated, 0 files merged, 0 files removed, 0 files unresolved
</pre>
<p>Now let's get back to <cite>sympy-fix755</cite></p>
<pre class="literal-block">
$ <strong class="input">cd ../sympy-fix755/</strong>
</pre>
<p>We have three patches applied</p>
<pre class="literal-block">
$ <strong class="input">hg qapplied</strong>
<a class="reference external" href="spt-patches/pprint-fix-old-classes.patch">pprint-fix-old-classes.patch</a>
<a class="reference external" href="spt-patches/xobj-fix-even-height.patch">xobj-fix-even-height.patch</a>
<a class="reference external" href="spt-patches/printer-fix-typos.patch">printer-fix-typos.patch</a>
</pre>
<p>Let's rebase them.</p>
<p>First we <em>unapply</em> all patches</p>
<pre class="literal-block">
$ <strong class="input">hg qpop -a</strong>
Patch queue now empty
</pre>
<p>Then pull recent changes in from our mirror repo</p>
<pre class="literal-block">
$ <strong class="input">hg pull -u</strong>
pulling from /home/kirr/src/sympy/spt-work/sympy
searching for changes
adding changesets
adding manifests
adding file changes
added 5 changesets with 26 changes to 21 files
21 files updated, 0 files merged, 0 files removed, 0 files unresolved
</pre>
<p>Then apply patches back</p>
<pre class="literal-block">
$ <strong class="input">hg qpush --all</strong>
applying pprint-fix-old-classes.patch
applying xobj-fix-even-height.patch
applying printer-fix-typos.patch
Now at: printer-fix-typos.patch
</pre>
<p>Now we have our patches applied on top of the latest tip.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p>We were lucky.</p>
<p>Sometimes changes we've made <em>overlap</em> with the changes made by other
developers. This situation is called <a class="reference external" href="http://www.selenic.com/mercurial/wiki/index.cgi/Conflict">conflict</a> and has to be resolved using
automated merge programs or by hands.</p>
<p class="last">This topic is out of scope of this tutorial, but an interested reader is
encouraged to read <a class="reference external" href="http://hgbook.red-bean.com/hgbookch3.html">chapter 3</a> in <a class="reference external" href="http://hgbook.red-bean.com/">hgbook</a> and <a class="reference external" href="http://www.selenic.com/mercurial/wiki/index.cgi/TutorialConflict">TutorialConflict</a> HG wiki
page.</p>
</div>
<p>Ok, it time to send patches for review!</p>
<p>Ensure last time on outgoing changes</p>
<pre class="literal-block">
$ <strong class="input">hg out</strong>
comparing with /home/kirr/src/sympy/spt-work/sympy
searching for changes
changeset: 1905:95b5af645143
tag: pprint-fix-old-classes.patch
tag: qbase
user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
date: Wed Mar 26 15:18:09 2008 +0300
summary: pprint: fix handling of old-style classes (#755)
changeset: 1906:316070047993
tag: xobj-fix-even-height.patch
user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
date: Wed Mar 26 15:18:09 2008 +0300
summary: pretty: fix xobj for even height
changeset: 1907:63eb63c9f098
tag: qtip
tag: printer-fix-typos.patch
tag: tip
user: Kirill Smelkov <<a class="reference external" href="mailto:kirr@landau.phys.spbu.ru">kirr@landau.phys.spbu.ru</a>>
date: Wed Mar 26 15:18:09 2008 +0300
summary: printer.py: fix typos
</pre>
<p>And let's finally send them:</p>
<pre class="literal-block">
$ <strong class="input">hg email --outgoing</strong>
comparing with /home/kirr/src/sympy/spt-work/sympy
searching for changes
This patch series consists of 3 patches.
Subject: [PATCH 0 of 3] <strong class="input">Fix for #755 + two more</strong>
Write the introductory message for the patch series.
<strong class="input">While working on #755 (pprint fails on old style classes) I've spot a couple</strong>
<strong class="input">of other inconveniences.</strong>
<strong class="input">Please review.</strong>
To: <strong class="input">sympy-patches@googlegroups.com</strong> TODO put this into .hgrc
Cc:
Sending [PATCH 0 of 3] Fix for #755 + two more ...
Sending [PATCH 1 of 3] pprint: fix handling of old-style classes (#755) ...
Sending [PATCH 2 of 3] pretty: fix xobj for even height ...
Sending [PATCH 3 of 3] printer.py: fix typos ...
</pre>
<p>Ok, patches sent.</p>
<p>Usually I use <a class="reference external" href="http://www.mutt.org/">Mutt</a>, but I'm having temporary problems with mail delivery