forked from sympy/sympy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
1332 lines (1148 loc) · 46.2 KB
/
fabfile.py
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
# -*- coding: utf-8 -*-
"""
Fab file for releasing
Please read the README in this directory.
Guide for this file
===================
Vagrant is a tool that gives us a reproducible VM, and fabric is a tool that
we use to run commands on that VM.
Each function in this file should be run as
fab vagrant func
Even those functions that do not use vagrant must be run this way, because of
the vagrant configuration at the bottom of this file.
Any function that should be made avaiable from the command line needs to have
the @task decorator.
Save any files that should be reset between runs somewhere in the repos
directory, so that the remove_userspace() function will clear it. It's best
to do a complete vagrant destroy before a full release, but that takes a
while, so the remove_userspace() ensures that things are mostly reset for
testing.
Do not enforce any naming conventions on the release branch. By tradition, the
name of the release branch is the same as the version being released (like
0.7.3), but this is not required. Use get_sympy_version() and
get_sympy_short_version() to get the SymPy version (the SymPy __version__
*must* be changed in sympy/release.py for this to work).
"""
from __future__ import print_function
from collections import defaultdict, OrderedDict
from contextlib import contextmanager
from fabric.api import env, local, run, sudo, cd, hide, task
from fabric.contrib.files import exists
from fabric.colors import blue, red, green
from fabric.utils import error, warn
try:
# Only works in newer versions of fabric
env.colorize_errors = True
except AttributeError:
pass
try:
import requests
from requests.auth import HTTPBasicAuth
from requests_oauthlib import OAuth2
except ImportError:
warn("requests and requests-oauthlib must be installed to upload to GitHub")
requests = False
import unicodedata
import json
from getpass import getpass
import os
import stat
import sys
import time
import ConfigParser
try:
# https://pypi.python.org/pypi/fabric-virtualenv/
from fabvenv import virtualenv, make_virtualenv
# Note, according to fabvenv docs, always use an absolute path with
# virtualenv().
except ImportError:
error("fabvenv is required. See https://pypi.python.org/pypi/fabric-virtualenv/")
# Note, it's actually good practice to use absolute paths
# everywhere. Otherwise, you will get surprising results if you call one
# function from another, because your current working directory will be
# whatever it was in the calling function, not ~. Also, due to what should
# probably be considered a bug, ~ is not treated as an absolute path. You have
# to explicitly write out /home/vagrant/
env.use_ssh_config = True
def full_path_split(path):
"""
Function to do a full split on a path.
"""
# Based on http://stackoverflow.com/a/13505966/161801
rest, tail = os.path.split(path)
if not rest or rest == os.path.sep:
return (tail,)
return full_path_split(rest) + (tail,)
@contextmanager
def use_venv(pyversion):
"""
Change make_virtualenv to use a given cmd
pyversion should be '2' or '3'
"""
pyversion = str(pyversion)
if pyversion == '2':
yield
elif pyversion == '3':
oldvenv = env.virtualenv
env.virtualenv = 'virtualenv -p /usr/bin/python3'
yield
env.virtualenv = oldvenv
else:
raise ValueError("pyversion must be one of '2' or '3', not %s" % pyversion)
@task
def prepare():
"""
Setup the VM
This only needs to be run once. It downloads all the necessary software,
and a git cache. To reset this, use vagrant destroy and vagrant up. Note,
this may take a while to finish, depending on your internet connection
speed.
"""
prepare_apt()
checkout_cache()
@task
def prepare_apt():
"""
Download software from apt
Note, on a slower internet connection, this will take a while to finish,
because it has to download many packages, include latex and all its
dependencies.
"""
sudo("apt-get -qq update")
sudo("apt-get -y install git python3 make python-virtualenv zip python-dev")
# Needed to build the docs
sudo("apt-get -y install graphviz inkscape texlive texlive-xetex texlive-fonts-recommended texlive-latex-extra librsvg2-bin docbook2x")
# Our Ubuntu is too old to include Python 3.3
sudo("apt-get -y install python-software-properties")
sudo("add-apt-repository -y ppa:fkrull/deadsnakes")
sudo("apt-get -y update")
sudo("apt-get -y install python3.3")
@task
def remove_userspace():
"""
Deletes (!) the SymPy changes. Use with great care.
This should be run between runs to reset everything.
"""
run("rm -rf repos")
if os.path.exists("release"):
error("release directory already exists locally. Remove it to continue.")
@task
def checkout_cache():
"""
Checkout a cache of SymPy
This should only be run once. The cache is use as a --reference for git
clone. This makes deleting and recreating the SymPy a la
remove_userspace() and gitrepos() and clone very fast.
"""
run("rm -rf sympy-cache.git")
run("git clone --bare https://github.com/sympy/sympy.git sympy-cache.git")
@task
def gitrepos(branch=None, fork='sympy'):
"""
Clone the repo
fab vagrant prepare (namely, checkout_cache()) must be run first. By
default, the branch checked out is the same one as the one checked out
locally. The master branch is not allowed--use a release branch (see the
README). No naming convention is put on the release branch.
To test the release, create a branch in your fork, and set the fork
option.
"""
with cd("/home/vagrant"):
if not exists("sympy-cache.git"):
error("Run fab vagrant prepare first")
if not branch:
# Use the current branch (of this git repo, not the one in Vagrant)
branch = local("git rev-parse --abbrev-ref HEAD", capture=True)
if branch == "master":
raise Exception("Cannot release from master")
run("mkdir -p repos")
with cd("/home/vagrant/repos"):
run("git clone --reference ../sympy-cache.git https://github.com/{fork}/sympy.git".format(fork=fork))
with cd("/home/vagrant/repos/sympy"):
run("git checkout -t origin/%s" % branch)
@task
def get_sympy_version(version_cache=[]):
"""
Get the full version of SymPy being released (like 0.7.3.rc1)
"""
if version_cache:
return version_cache[0]
if not exists("/home/vagrant/repos/sympy"):
gitrepos()
with cd("/home/vagrant/repos/sympy"):
version = run('python -c "import sympy;print(sympy.__version__)"')
assert '\n' not in version
assert ' ' not in version
assert '\t' not in version
version_cache.append(version)
return version
@task
def get_sympy_short_version():
"""
Get the short version of SymPy being released, not including any rc tags
(like 0.7.3)
"""
version = get_sympy_version()
parts = version.split('.')
non_rc_parts = [i for i in parts if i.isdigit()]
return '.'.join(non_rc_parts) # Remove any rc tags
@task
def test_sympy():
"""
Run the SymPy test suite
"""
with cd("/home/vagrant/repos/sympy"):
run("./setup.py test")
@task
def test_tarball(release='2'):
"""
Test that the tarball can be unpacked and installed, and that sympy
imports in the install.
"""
if release not in {'2', '3'}: # TODO: Add win32
raise ValueError("release must be one of '2', '3', not %s" % release)
venv = "/home/vagrant/repos/test-{release}-virtualenv".format(release=release)
tarball_formatter_dict = tarball_formatter()
with use_venv(release):
make_virtualenv(venv)
with virtualenv(venv):
run("cp /vagrant/release/{source} releasetar.tar".format(**tarball_formatter_dict))
run("tar xvf releasetar.tar")
with cd("/home/vagrant/{source-orig-notar}".format(**tarball_formatter_dict)):
run("python setup.py install")
run('python -c "import sympy; print(sympy.__version__)"')
@task
def release(branch=None, fork='sympy'):
"""
Perform all the steps required for the release, except uploading
In particular, it builds all the release files, and puts them in the
release/ directory in the same directory as this one. At the end, it
prints some things that need to be pasted into various places as part of
the release.
To test the release, push a branch to your fork on GitHub and set the fork
option to your username.
"""
remove_userspace()
gitrepos(branch, fork)
# This has to be run locally because it itself uses fabric. I split it out
# into a separate script so that it can be used without vagrant.
local("../bin/mailmap_update.py")
source_tarball()
build_docs()
copy_release_files()
test_tarball('2')
test_tarball('3')
compare_tar_against_git()
print_authors()
@task
def source_tarball():
"""
Build the source tarball
"""
with cd("/home/vagrant/repos/sympy"):
run("git clean -dfx")
run("./setup.py clean")
run("./setup.py sdist --keep-temp")
run("./setup.py bdist_wininst")
run("mv dist/{win32-orig} dist/{win32}".format(**tarball_formatter()))
@task
def build_docs():
"""
Build the html and pdf docs
"""
with cd("/home/vagrant/repos/sympy"):
run("mkdir -p dist")
venv = "/home/vagrant/docs-virtualenv"
make_virtualenv(venv, dependencies=['sphinx==1.1.3', 'numpy'])
with virtualenv(venv):
with cd("/home/vagrant/repos/sympy/doc"):
run("make clean")
run("make html-errors")
run("make man")
with cd("/home/vagrant/repos/sympy/doc/_build"):
run("mv html {html-nozip}".format(**tarball_formatter()))
run("zip -9lr {html} {html-nozip}".format(**tarball_formatter()))
run("cp {html} ../../dist/".format(**tarball_formatter()))
run("make clean")
run("make latex")
with cd("/home/vagrant/repos/sympy/doc/_build/latex"):
run("make")
run("cp {pdf-orig} ../../../dist/{pdf}".format(**tarball_formatter()))
@task
def copy_release_files():
"""
Move the release files from the VM to release/ locally
"""
with cd("/home/vagrant/repos/sympy"):
run("mkdir -p /vagrant/release")
run("cp dist/* /vagrant/release/")
@task
def show_files(file, print_=True):
"""
Show the contents of a tarball.
The current options for file are
source: The source tarball
win: The Python 2 Windows installer (Not yet implemented!)
html: The html docs zip
Note, this runs locally, not in vagrant.
"""
# TODO: Test the unarchived name. See
# https://github.com/sympy/sympy/issues/7087.
if file == 'source':
ret = local("tar tf release/{source}".format(**tarball_formatter()), capture=True)
elif file == 'win':
# TODO: Windows
raise NotImplementedError("Windows installers")
elif file == 'html':
ret = local("unzip -l release/{html}".format(**tarball_formatter()), capture=True)
else:
raise ValueError(file + " is not valid")
if print_:
print(ret)
return ret
# If a file does not end up in the tarball that should, add it to setup.py if
# it is Python, or MANIFEST.in if it is not. (There is a command at the top
# of setup.py to gather all the things that should be there).
# TODO: Also check that this whitelist isn't growning out of date from files
# removed from git.
# TODO: Address the "why?" comments below.
# Files that are in git that should not be in the tarball
git_whitelist = {
# Git specific dotfiles
'.gitattributes',
'.gitignore',
'.mailmap',
# Travis
'.travis.yml',
# This is the file you should edit if not enough ends up in the tarball
'MANIFEST.in',
# Experimental Cythonization support. Not for production
'Makefile',
# Nothing from bin/ should be shipped unless we intend to install it. Most
# of this stuff is for development anyway. To run the tests from the
# tarball, use setup.py test, or import sympy and run sympy.test() or
# sympy.doctest().
'bin/adapt_paths.py',
'bin/ask_update.py',
'bin/coverage_doctest.py',
'bin/coverage_report.py',
'bin/diagnose_imports',
'bin/doctest',
'bin/get_sympy.py',
'bin/py.bench',
'bin/mailmap_update.py',
'bin/strip_whitespace',
'bin/sympy_time.py',
'bin/sympy_time_cache.py',
'bin/test',
'bin/test_import',
'bin/test_import.py',
'bin/test_isolated',
'bin/test_travis.sh',
# This is also related to Cythonization
'build.py',
# The notebooks are not ready for shipping yet. They need to be cleaned
# up, and preferrably doctested. See also
# https://github.com/sympy/sympy/issues/6039.
'examples/advanced/identitysearch_example.ipynb',
'examples/beginner/plot_advanced.ipynb',
'examples/beginner/plot_colors.ipynb',
'examples/beginner/plot_discont.ipynb',
'examples/beginner/plot_gallery.ipynb',
'examples/beginner/plot_intro.ipynb',
'examples/intermediate/limit_examples_advanced.ipynb',
'examples/intermediate/schwarzschild.ipynb',
'examples/notebooks/density.ipynb',
'examples/notebooks/fidelity.ipynb',
'examples/notebooks/fresnel_integrals.ipynb',
'examples/notebooks/qubits.ipynb',
'examples/notebooks/sho1d_example.ipynb',
'examples/notebooks/spin.ipynb',
'examples/notebooks/trace.ipynb',
# This stuff :)
'release/.gitignore',
'release/README.md',
'release/Vagrantfile',
'release/fabfile.py',
# This is just a distribute version of setup.py. Used mainly for setup.py
# develop, which we don't care about in the release tarball
'setupegg.py',
# We don't ship the benchmarks (why?)
'sympy/benchmarks/bench_meijerint.py',
'sympy/benchmarks/bench_symbench.py',
'sympy/core/benchmarks/bench_arit.py',
'sympy/core/benchmarks/bench_assumptions.py',
'sympy/core/benchmarks/bench_basic.py',
'sympy/core/benchmarks/bench_expand.py',
'sympy/core/benchmarks/bench_numbers.py',
'sympy/core/benchmarks/bench_sympify.py',
'sympy/functions/elementary/benchmarks/bench_exp.py',
'sympy/functions/special/benchmarks/bench_special.py',
# More benchmarks
'sympy/integrals/benchmarks/bench_integrate.py',
'sympy/integrals/benchmarks/bench_trigintegrate.py',
'sympy/logic/benchmarks/input/10.cnf',
'sympy/logic/benchmarks/input/100.cnf',
'sympy/logic/benchmarks/input/105.cnf',
'sympy/logic/benchmarks/input/110.cnf',
'sympy/logic/benchmarks/input/115.cnf',
'sympy/logic/benchmarks/input/120.cnf',
'sympy/logic/benchmarks/input/125.cnf',
'sympy/logic/benchmarks/input/130.cnf',
'sympy/logic/benchmarks/input/135.cnf',
'sympy/logic/benchmarks/input/140.cnf',
'sympy/logic/benchmarks/input/145.cnf',
'sympy/logic/benchmarks/input/15.cnf',
'sympy/logic/benchmarks/input/150.cnf',
'sympy/logic/benchmarks/input/20.cnf',
'sympy/logic/benchmarks/input/25.cnf',
'sympy/logic/benchmarks/input/30.cnf',
'sympy/logic/benchmarks/input/35.cnf',
'sympy/logic/benchmarks/input/40.cnf',
'sympy/logic/benchmarks/input/45.cnf',
'sympy/logic/benchmarks/input/50.cnf',
'sympy/logic/benchmarks/input/55.cnf',
'sympy/logic/benchmarks/input/60.cnf',
'sympy/logic/benchmarks/input/65.cnf',
'sympy/logic/benchmarks/input/70.cnf',
'sympy/logic/benchmarks/input/75.cnf',
'sympy/logic/benchmarks/input/80.cnf',
'sympy/logic/benchmarks/input/85.cnf',
'sympy/logic/benchmarks/input/90.cnf',
'sympy/logic/benchmarks/input/95.cnf',
'sympy/logic/benchmarks/run-solvers.py',
'sympy/logic/benchmarks/test-solver.py',
'sympy/matrices/benchmarks/bench_matrix.py',
# More benchmarks...
'sympy/polys/benchmarks/__init__.py',
'sympy/polys/benchmarks/bench_galoispolys.py',
'sympy/polys/benchmarks/bench_groebnertools.py',
'sympy/polys/benchmarks/bench_solvers.py',
'sympy/series/benchmarks/bench_limit.py',
'sympy/solvers/benchmarks/bench_solvers.py',
# Example on how to use tox to test Sympy. For development.
'tox.ini.sample',
}
# Files that should be in the tarball should not be in git
tarball_whitelist = {
"PKG-INFO", # Generated by setup.py. Contains metadata for PyPI.
}
@task
def compare_tar_against_git():
"""
Compare the contents of the tarball against git ls-files
"""
with hide("commands"):
with cd("/home/vagrant/repos/sympy"):
git_lsfiles = set([i.strip() for i in run("git ls-files").split("\n")])
tar_output_orig = set(show_files('source', print_=False).split("\n"))
tar_output = set()
for file in tar_output_orig:
# The tar files are like sympy-0.7.3/sympy/__init__.py, and the git
# files are like sympy/__init__.py.
split_path = full_path_split(file)
if split_path[-1]:
# Exclude directories, as git ls-files does not include them
tar_output.add(os.path.join(*split_path[1:]))
# print tar_output
# print git_lsfiles
fail = False
print()
print(blue("Files in the tarball from git that should not be there:",
bold=True))
print()
for line in sorted(tar_output.intersection(git_whitelist)):
fail = True
print(line)
print()
print(blue("Files in git but not in the tarball:", bold=True))
print()
for line in sorted(git_lsfiles - tar_output - git_whitelist):
fail = True
print(line)
print()
print(blue("Files in the tarball but not in git:", bold=True))
print()
for line in sorted(tar_output - git_lsfiles - tarball_whitelist):
fail = True
print(line)
if fail:
error("Non-whitelisted files found or not found in the tarball")
@task
def md5(file='*', print_=True):
"""
Print the md5 sums of the release files
"""
out = local("md5sum release/" + file, capture=True)
# Remove the release/ part for printing. Useful for copy-pasting into the
# release notes.
out = [i.split() for i in out.strip().split('\n')]
out = '\n'.join(["%s\t%s" % (i, os.path.split(j)[1]) for i, j in out])
if print_:
print(out)
return out
descriptions = OrderedDict([
('source', "The SymPy source installer.",),
('win32', "Python Windows 32-bit installer.",),
('html', '''Html documentation for the Python 2 version. This is the same as
the <a href="http://docs.sympy.org/latest/index.html">online documentation</a>.''',),
('pdf', '''Pdf version of the <a href="http://docs.sympy.org/latest/index.html"> html documentation</a>.''',),
])
@task
def size(file='*', print_=True):
"""
Print the sizes of the release files
"""
out = local("du -h release/" + file, capture=True)
out = [i.split() for i in out.strip().split('\n')]
out = '\n'.join(["%s\t%s" % (i, os.path.split(j)[1]) for i, j in out])
if print_:
print(out)
return out
@task
def table():
"""
Make an html table of the downloads.
This is for pasting into the GitHub releases page. See GitHub_release().
"""
# TODO: Add the file size
tarball_formatter_dict = tarball_formatter()
shortversion = get_sympy_short_version()
tarball_formatter_dict['version'] = shortversion
md5s = [i.split('\t') for i in md5(print_=False).split('\n')]
md5s_dict = {name: md5 for md5, name in md5s}
sizes = [i.split('\t') for i in size(print_=False).split('\n')]
sizes_dict = {name: size for size, name in sizes}
table = []
# http://docs.python.org/2/library/contextlib.html#contextlib.contextmanager. Not
# recommended as a real way to generate html, but it works better than
# anything else I've tried.
@contextmanager
def tag(name):
table.append("<%s>" % name)
yield
table.append("</%s>" % name)
with tag('table'):
with tag('tr'):
for headname in ["Filename", "Description", "size", "md5"]:
with tag("th"):
table.append(headname)
for key in descriptions:
name = get_tarball_name(key)
with tag('tr'):
with tag('td'):
# code renders better than tt or pre
with tag('code'):
table.append(name)
with tag('td'):
table.append(descriptions[key].format(**tarball_formatter_dict))
with tag('td'):
table.append(sizes_dict[name])
with tag('td'):
table.append(md5s_dict[name])
out = ' '.join(table)
return out
@task
def get_tarball_name(file):
"""
Get the name of a tarball
file should be one of
source-orig: The original name of the source tarball
source-orig-notar: The name of the untarred directory
source: The source tarball (after renaming)
win32-orig: The original name of the win32 installer
win32: The name of the win32 installer (after renaming)
html: The name of the html zip
html-nozip: The name of the html, without ".zip"
pdf-orig: The original name of the pdf file
pdf: The name of the pdf file (after renaming)
"""
version = get_sympy_version()
doctypename = defaultdict(str, {'html': 'zip', 'pdf': 'pdf'})
winos = defaultdict(str, {'win32': 'win32', 'win32-orig': 'linux-i686'})
if file in {'source-orig', 'source'}:
name = 'sympy-{version}.tar.gz'
elif file == 'source-orig-notar':
name = "sympy-{version}"
elif file in {'win32', 'win32-orig'}:
name = "sympy-{version}.{wintype}.exe"
elif file in {'html', 'pdf', 'html-nozip'}:
name = "sympy-docs-{type}-{version}"
if file == 'html-nozip':
# zip files keep the name of the original zipped directory. See
# https://github.com/sympy/sympy/issues/7087.
file = 'html'
else:
name += ".{extension}"
elif file == 'pdf-orig':
name = "sympy-{version}.pdf"
else:
raise ValueError(file + " is not a recognized argument")
ret = name.format(version=version, type=file,
extension=doctypename[file], wintype=winos[file])
return ret
tarball_name_types = {
'source-orig',
'source-orig-notar',
'source',
'win32-orig',
'win32',
'html',
'html-nozip',
'pdf-orig',
'pdf',
}
# This has to be a function, because you cannot call any function here at
# import time (before the vagrant() function is run).
def tarball_formatter():
return {name: get_tarball_name(name) for name in tarball_name_types}
@task
def get_previous_version_tag():
"""
Get the version of the previous release
"""
# We try, probably too hard, to portably get the number of the previous
# release of SymPy. Our strategy is to look at the git tags. The
# following assumptions are made about the git tags:
# - The only tags are for releases
# - The tags are given the consistent naming:
# sympy-major.minor.micro[.rcnumber]
# (e.g., sympy-0.7.2 or sympy-0.7.2.rc1)
# In particular, it goes back in the tag history and finds the most recent
# tag that doesn't contain the current short version number as a substring.
shortversion = get_sympy_short_version()
curcommit = "HEAD"
with cd("/home/vagrant/repos/sympy"):
while True:
curtag = run("git describe --abbrev=0 --tags " +
curcommit).strip()
if shortversion in curtag:
# If the tagged commit is a merge commit, we cannot be sure
# that it will go back in the right direction. This almost
# never happens, so just error
parents = local("git rev-list --parents -n 1 " + curtag,
capture=True).strip().split()
# rev-list prints the current commit and then all its parents
# If the tagged commit *is* a merge commit, just comment this
# out, and make sure `fab vagrant get_previous_version_tag` is correct
assert len(parents) == 2, curtag
curcommit = curtag + "^" # The parent of the tagged commit
else:
print(blue("Using {tag} as the tag for the previous "
"release.".format(tag=curtag), bold=True))
return curtag
error("Could not find the tag for the previous release.")
@task
def get_authors():
"""
Get the list of authors since the previous release
Returns the list in alphabetical order by last name. Authors who
contributed for the first time for this release will have a star appended
to the end of their names.
Note: it's a good idea to use ./bin/mailmap_update.py (from the base sympy
directory) to make AUTHORS and .mailmap up-to-date first before using
this. fab vagrant release does this automatically.
"""
def lastnamekey(name):
"""
Sort key to sort by last name
Note, we decided to sort based on the last name, because that way is
fair. We used to sort by commit count or line number count, but that
bumps up people who made lots of maintenance changes like updating
mpmath or moving some files around.
"""
# Note, this will do the wrong thing for people who have multi-word
# last names, but there are also people with middle initials. I don't
# know of a perfect way to handle everyone. Feel free to fix up the
# list by hand.
# Note, you must call unicode() *before* lower, or else it won't
# lowercase non-ASCII characters like Č -> č
text = unicode(name.strip().split()[-1], encoding='utf-8').lower()
# Convert things like Čertík to Certik
return unicodedata.normalize('NFKD', text).encode('ascii', 'ignore')
old_release_tag = get_previous_version_tag()
with cd("/home/vagrant/repos/sympy"), hide('commands'):
releaseauthors = set(run('git --no-pager log {tag}.. --format="%aN"'.format(tag=old_release_tag)).strip().split('\n'))
priorauthors = set(run('git --no-pager log {tag} --format="%aN"'.format(tag=old_release_tag)).strip().split('\n'))
releaseauthors = {name.strip() for name in releaseauthors if name.strip()}
priorauthors = {name.strip() for name in priorauthors if name.strip()}
newauthors = releaseauthors - priorauthors
starred_newauthors = {name + "*" for name in newauthors}
authors = releaseauthors - newauthors | starred_newauthors
return (sorted(authors, key=lastnamekey), len(releaseauthors), len(newauthors))
@task
def print_authors():
"""
Print authors text to put at the bottom of the release notes
"""
authors, authorcount, newauthorcount = get_authors()
print(blue("Here are the authors to put at the bottom of the release "
"notes.", bold=True))
print()
print("""## Authors
The following people contributed at least one patch to this release (names are
given in alphabetical order by last name). A total of {authorcount} people
contributed to this release. People with a * by their names contributed a
patch for the first time for this release; {newauthorcount} people contributed
for the first time for this release.
Thanks to everyone who contributed to this release!
""".format(authorcount=authorcount, newauthorcount=newauthorcount))
for name in authors:
print("- " + name)
print()
@task
def check_tag_exists():
"""
Check if the tag for this release has been uploaded yet.
"""
version = get_sympy_version()
tag = 'sympy-' + version
with cd("/home/vagrant/repos/sympy"):
all_tags = run("git ls-remote --tags origin")
return tag in all_tags
# ------------------------------------------------
# Updating websites
@task
def update_websites():
"""
Update various websites owned by SymPy.
So far, supports the docs and sympy.org
"""
update_docs()
update_sympy_org()
def get_location(location):
"""
Read/save a location from the configuration file.
"""
locations_file = os.path.expanduser('~/.sympy/sympy-locations')
config = ConfigParser.SafeConfigParser()
config.read(locations_file)
the_location = config.has_option("Locations", location) and config.get("Locations", location)
if not the_location:
the_location = raw_input("Where is the SymPy {location} directory? ".format(location=location))
if not config.has_section("Locations"):
config.add_section("Locations")
config.set("Locations", location, the_location)
save = raw_input("Save this to file [yes]? ")
if save.lower().strip() in ['', 'y', 'yes']:
print("saving to ", locations_file)
with open(locations_file, 'w') as f:
config.write(f)
else:
print("Reading {location} location from config".format(location=location))
return os.path.abspath(os.path.expanduser(the_location))
@task
def update_docs(docs_location=None):
"""
Update the docs hosted at docs.sympy.org
"""
docs_location = docs_location or get_location("docs")
print("Docs location:", docs_location)
# Check that the docs directory is clean
local("cd {docs_location} && git diff --exit-code > /dev/null".format(docs_location=docs_location))
local("cd {docs_location} && git diff --cached --exit-code > /dev/null".format(docs_location=docs_location))
# See the README of the docs repo. We have to remove the old redirects,
# move in the new docs, and create redirects.
current_version = get_sympy_version()
previous_version = get_previous_version_tag().lstrip('sympy-')
print("Removing redirects from previous version")
local("cd {docs_location} && rm -r {previous_version}".format(docs_location=docs_location,
previous_version=previous_version))
print("Moving previous latest docs to old version")
local("cd {docs_location} && mv latest {previous_version}".format(docs_location=docs_location,
previous_version=previous_version))
print("Unzipping docs into repo")
release_dir = os.path.abspath(os.path.expanduser(os.path.join(os.path.curdir, 'release')))
docs_zip = os.path.abspath(os.path.join(release_dir, get_tarball_name('html')))
local("cd {docs_location} && unzip {docs_zip} > /dev/null".format(docs_location=docs_location,
docs_zip=docs_zip))
local("cd {docs_location} && mv {docs_zip_name} {version}".format(docs_location=docs_location,
docs_zip_name=get_tarball_name("html-nozip"), version=current_version))
print("Writing new version to releases.txt")
with open(os.path.join(docs_location, "releases.txt"), 'a') as f:
f.write("{version}:SymPy {version}\n".format(version=current_version))
print("Generating indexes")
local("cd {docs_location} && ./generate_indexes.py".format(docs_location=docs_location))
local("cd {docs_location} && mv {version} latest".format(docs_location=docs_location,
version=current_version))
print("Generating redirects")
local("cd {docs_location} && ./generate_redirects.py latest {version} ".format(docs_location=docs_location,
version=current_version))
print("Committing")
local("cd {docs_location} && git add -A {version} latest".format(docs_location=docs_location,
version=current_version))
local("cd {docs_location} && git commit -a -m \'Updating docs to {version}\'".format(docs_location=docs_location,
version=current_version))
print("Pushing")
local("cd {docs_location} && git push origin".format(docs_location=docs_location))
@task
def update_sympy_org(website_location=None):
"""
Update sympy.org
This just means adding an entry to the news section.
"""
website_location = website_location or get_location("sympy.github.com")
# Check that the website directory is clean
local("cd {website_location} && git diff --exit-code > /dev/null".format(website_location=website_location))
local("cd {website_location} && git diff --cached --exit-code > /dev/null".format(website_location=website_location))
release_date = time.gmtime(os.path.getctime(os.path.join("release",
tarball_formatter()['source'])))
release_year = str(release_date.tm_year)
release_month = str(release_date.tm_mon)
release_day = str(release_date.tm_mday)
version = get_sympy_version()
with open(os.path.join(website_location, "templates", "index.html"), 'r') as f:
lines = f.read().split('\n')
# We could try to use some html parser, but this way is easier
try:
news = lines.index(r" <h3>{% trans %}News{% endtrans %}</h3>")
except ValueError:
error("index.html format not as expected")
lines.insert(news + 2, # There is a <p> after the news line. Put it
# after that.
r""" <span class="date">{{ datetime(""" + release_year + """, """ + release_month + """, """ + release_day + """) }}</span> {% trans v='""" + version + """' %}Version {{ v }} released{% endtrans %} (<a href="https://github.com/sympy/sympy/wiki/Release-Notes-for-""" + version + """">{% trans %}changes{% endtrans %}</a>)<br/>
</p><p>""")
with open(os.path.join(website_location, "templates", "index.html"), 'w') as f:
print("Updating index.html template")
f.write('\n'.join(lines))
print("Generating website pages")
local("cd {website_location} && ./generate".format(website_location=website_location))
print("Committing")
local("cd {website_location} && git commit -a -m \'Add {version} to the news\'".format(website_location=website_location,
version=version))
print("Pushing")
local("cd {website_location} && git push origin".format(website_location=website_location))
# ------------------------------------------------
# Uploading
@task
def upload():
"""
Upload the files everywhere (PyPI and GitHub)
"""
distutils_check()
GitHub_release()
pypi_register()
pypi_upload()
test_pypi(2)
test_pypi(3)
@task
def distutils_check():
"""
Runs setup.py check
"""
with cd("/home/vagrant/repos/sympy"):
run("python setup.py check")
run("python3 setup.py check")
@task
def pypi_register():
"""
Register a release with PyPI
This should only be done for the final release. You need PyPI
authentication to do this.
"""
with cd("/home/vagrant/repos/sympy"):
run("python setup.py register")
@task
def pypi_upload():
"""
Upload files to PyPI. You will need to enter a password.
"""
with cd("/home/vagrant/repos/sympy"):
# See http://stackoverflow.com/a/17657183/161801
run("python setup.py sdist --dry-run upload")
@task
def test_pypi(release='2'):
"""
Test that the sympy can be pip installed, and that sympy imports in the
install.
"""
# This function is similar to test_tarball()
version = get_sympy_version()
release = str(release)
if release not in {'2', '3'}: # TODO: Add win32
raise ValueError("release must be one of '2', '3', not %s" % release)
venv = "/home/vagrant/repos/test-{release}-pip-virtualenv".format(release=release)
with use_venv(release):
make_virtualenv(venv)
with virtualenv(venv):
run("pip install sympy")
run('python -c "import sympy; assert sympy.__version__ == \'{version}\'"'.format(version=version))
@task