-
Notifications
You must be signed in to change notification settings - Fork 170
/
tests.py
3796 lines (3255 loc) · 108 KB
/
tests.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 -*-
##############################################################################
#
# Copyright (c) 2004-2009 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from zc.buildout.buildout import print_
from zope.testing import renormalizing, setupstack
import doctest
import manuel.capture
import manuel.doctest
import manuel.testing
from multiprocessing import Process
import os
import pkg_resources
import re
import shutil
import sys
import tempfile
import unittest
import zc.buildout.easy_install
import zc.buildout.testing
import zipfile
os_path_sep = os.path.sep
if os_path_sep == '\\':
os_path_sep *= 2
def develop_w_non_setuptools_setup_scripts():
"""
We should be able to deal with setup scripts that aren't setuptools based.
>>> mkdir('foo')
>>> write('foo', 'setup.py',
... '''
... from distutils.core import setup
... setup(name="foo")
... ''')
>>> write('buildout.cfg',
... '''
... [buildout]
... develop = foo
... parts =
... ''')
>>> print_(system(join('bin', 'buildout')), end='')
Develop: '/sample-buildout/foo'
>>> ls('develop-eggs')
- foo.egg-link
- zc.recipe.egg.egg-link
"""
def develop_verbose():
"""
We should be able to deal with setup scripts that aren't setuptools based.
>>> mkdir('foo')
>>> write('foo', 'setup.py',
... '''
... from setuptools import setup
... setup(name="foo")
... ''')
>>> write('buildout.cfg',
... '''
... [buildout]
... develop = foo
... parts =
... ''')
>>> print_(system(join('bin', 'buildout')+' -vv'), end='')
... # doctest: +ELLIPSIS
Installing...
Develop: '/sample-buildout/foo'
...
Installed /sample-buildout/foo
...
>>> ls('develop-eggs')
- foo.egg-link
- zc.recipe.egg.egg-link
>>> print_(system(join('bin', 'buildout')+' -vvv'), end='')
... # doctest: +ELLIPSIS
Installing...
Develop: '/sample-buildout/foo'
in: '/sample-buildout/foo'
... -q develop -mN -d /sample-buildout/develop-eggs/...
"""
def buildout_error_handling():
r"""Buildout error handling
Asking for a section that doesn't exist, yields a missing section error:
>>> import os
>>> os.chdir(sample_buildout)
>>> import zc.buildout.buildout
>>> buildout = zc.buildout.buildout.Buildout('buildout.cfg', [])
>>> buildout['eek']
Traceback (most recent call last):
...
MissingSection: The referenced section, 'eek', was not defined.
Asking for an option that doesn't exist, a MissingOption error is raised:
>>> buildout['buildout']['eek']
Traceback (most recent call last):
...
MissingOption: Missing option: buildout:eek
It is an error to create a variable-reference cycle:
>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... parts =
... x = ${buildout:y}
... y = ${buildout:z}
... z = ${buildout:x}
... ''')
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end='')
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
While:
Initializing.
Getting section buildout.
Initializing section buildout.
Getting option buildout:x.
Getting option buildout:y.
Getting option buildout:z.
Getting option buildout:x.
Error: Circular reference in substitutions.
It is an error to use funny characters in variable references:
>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... develop = recipes
... parts = data_dir debug
... x = ${bui$ldout:y}
... ''')
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end='')
While:
Initializing.
Getting section buildout.
Initializing section buildout.
Getting option buildout:x.
Error: The section name in substitution, ${bui$ldout:y},
has invalid characters.
>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... develop = recipes
... parts = data_dir debug
... x = ${buildout:y{z}
... ''')
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end='')
While:
Initializing.
Getting section buildout.
Initializing section buildout.
Getting option buildout:x.
Error: The option name in substitution, ${buildout:y{z},
has invalid characters.
and too have too many or too few colons:
>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... develop = recipes
... parts = data_dir debug
... x = ${parts}
... ''')
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end='')
While:
Initializing.
Getting section buildout.
Initializing section buildout.
Getting option buildout:x.
Error: The substitution, ${parts},
doesn't contain a colon.
>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... develop = recipes
... parts = data_dir debug
... x = ${buildout:y:z}
... ''')
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end='')
While:
Initializing.
Getting section buildout.
Initializing section buildout.
Getting option buildout:x.
Error: The substitution, ${buildout:y:z},
has too many colons.
All parts have to have a section:
>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... parts = x
... ''')
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end='')
While:
Installing.
Getting section x.
Error: The referenced section, 'x', was not defined.
and all parts have to have a specified recipe:
>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... parts = x
...
... [x]
... foo = 1
... ''')
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end='')
While:
Installing.
Error: Missing option: x:recipe
"""
make_dist_that_requires_setup_py_template = """
from setuptools import setup
setup(name=%r, version=%r,
install_requires=%r,
)
"""
def make_dist_that_requires(dest, name, requires=[], version=1, egg=''):
os.mkdir(os.path.join(dest, name))
open(os.path.join(dest, name, 'setup.py'), 'w').write(
make_dist_that_requires_setup_py_template
% (name, version, requires)
)
def show_who_requires_when_there_is_a_conflict():
"""
It's a pain when we require eggs that have requirements that are
incompatible. We want the error we get to tell us what is missing.
Let's make a few develop distros, some of which have incompatible
requirements.
>>> make_dist_that_requires(sample_buildout, 'sampley',
... ['demoneeded ==1.0'])
>>> make_dist_that_requires(sample_buildout, 'samplez',
... ['demoneeded ==1.1'])
Now, let's create a buildout that requires y and z:
>>> write('buildout.cfg',
... '''
... [buildout]
... parts = eggs
... develop = sampley samplez
... find-links = %(link_server)s
...
... [eggs]
... recipe = zc.recipe.egg
... eggs = sampley
... samplez
... ''' % globals())
>>> print_(system(buildout), end='')
Develop: '/sample-buildout/sampley'
Develop: '/sample-buildout/samplez'
Installing eggs.
Getting distribution for 'demoneeded==1.1'.
Got demoneeded 1.1.
Version and requirements information containing demoneeded:
Requirement of samplez: demoneeded==1.1
Requirement of sampley: demoneeded==1.0
While:
Installing eggs.
Error: There is a version conflict.
We already have: demoneeded 1.1
but sampley 1 requires 'demoneeded==1.0'.
Here, we see that sampley required an older version of demoneeded. What
if we hadn't required sampley ourselves:
>>> make_dist_that_requires(sample_buildout, 'samplea', ['sampleb'])
>>> make_dist_that_requires(sample_buildout, 'sampleb',
... ['sampley', 'samplea'])
>>> write('buildout.cfg',
... '''
... [buildout]
... parts = eggs
... develop = sampley samplez samplea sampleb
... find-links = %(link_server)s
...
... [eggs]
... recipe = zc.recipe.egg
... eggs = samplea
... samplez
... ''' % globals())
If we use the verbose switch, we can see where requirements are coming from:
>>> print_(system(buildout+' -v'), end='') # doctest: +ELLIPSIS
Installing 'zc.buildout', 'setuptools'.
We have a develop egg: zc.buildout 1.0.0
We have the best distribution that satisfies 'setuptools'.
Picked: setuptools = 0.7
...
Develop: '/sample-buildout/sampley'
Develop: '/sample-buildout/samplez'
Develop: '/sample-buildout/samplea'
Develop: '/sample-buildout/sampleb'
...Installing eggs.
Installing 'samplea', 'samplez'.
We have a develop egg: samplea 1
We have a develop egg: samplez 1
Getting required 'demoneeded==1.1'
required by samplez 1.
We have the distribution that satisfies 'demoneeded==1.1'.
Getting required 'sampleb'
required by samplea 1.
We have a develop egg: sampleb 1
Getting required 'sampley'
required by sampleb 1.
We have a develop egg: sampley 1
Version and requirements information containing demoneeded:
Requirement of samplez: demoneeded==1.1
Requirement of sampley: demoneeded==1.0
While:
Installing eggs.
Error: There is a version conflict.
We already have: demoneeded 1.1
but sampley 1 requires 'demoneeded==1.0'.
"""
def version_conflict_rendering():
"""
We use the arguments passed by pkg_resources.VersionConflict to construct a
nice error message:
>>> error = pkg_resources.VersionConflict('pkg1 2.1', 'pkg1 1.0')
>>> ws = [] # Not relevant for this test
>>> print_(zc.buildout.easy_install.VersionConflict(
... error, ws)) # doctest: +ELLIPSIS
There is a version conflict...
But sometimes pkg_resources passes a nicely formatted string itself already.
Extracting the original arguments fails in that case, so we just show the string.
>>> error = pkg_resources.VersionConflict('pkg1 2.1 is simply wrong')
>>> ws = [] # Not relevant for this test
>>> print_(zc.buildout.easy_install.VersionConflict(
... error, ws)) # doctest: +ELLIPSIS
There is a version conflict.
pkg1 2.1 is simply wrong
"""
def show_who_requires_missing_distributions():
"""
When working with a lot of eggs, which require eggs recursively, it
can be hard to tell why we're requiring things we can't
find. Fortunately, buildout will tell us who's asking for something
that we can't find. when run in verbose mode
>>> make_dist_that_requires(sample_buildout, 'sampley', ['demoneeded'])
>>> make_dist_that_requires(sample_buildout, 'samplea', ['sampleb'])
>>> make_dist_that_requires(sample_buildout, 'sampleb',
... ['sampley', 'samplea'])
>>> write('buildout.cfg',
... '''
... [buildout]
... parts = eggs
... develop = sampley samplea sampleb
...
... [eggs]
... recipe = zc.recipe.egg
... eggs = samplea
... ''')
>>> print_(system(buildout+' -v'), end='') # doctest: +ELLIPSIS
Installing ...
Installing 'samplea'.
We have a develop egg: samplea 1
Getting required 'sampleb'
required by samplea 1.
We have a develop egg: sampleb 1
Getting required 'sampley'
required by sampleb 1.
We have a develop egg: sampley 1
Getting required 'demoneeded'
required by sampley 1.
We have no distributions for demoneeded that satisfies 'demoneeded'.
...
While:
Installing eggs.
Getting distribution for 'demoneeded'.
Error: Couldn't find a distribution for 'demoneeded'.
"""
def show_who_requires_picked_versions():
"""
The show-picked-versions prints the versions, but it also prints who
required the picked distributions.
We do not need to run in verbose mode for that to work:
>>> make_dist_that_requires(sample_buildout, 'sampley', ['setuptools'])
>>> make_dist_that_requires(sample_buildout, 'samplea', ['sampleb'])
>>> make_dist_that_requires(sample_buildout, 'sampleb',
... ['sampley', 'samplea'])
>>> write('buildout.cfg',
... '''
... [buildout]
... parts = eggs
... show-picked-versions = true
... develop = sampley samplea sampleb
...
... [eggs]
... recipe = zc.recipe.egg
... eggs = samplea
... ''')
>>> print_(system(buildout), end='') # doctest: +ELLIPSIS
Develop: ...
Installing eggs.
Versions had to be automatically picked.
The following part definition lists the versions picked:
[versions]
...
<BLANKLINE>
# Required by:
# sampley==1
setuptools = 0.7
"""
def test_comparing_saved_options_with_funny_characters():
"""
If an option has newlines, extra/odd spaces or a %, we need to make sure
the comparison with the saved value works correctly.
>>> mkdir(sample_buildout, 'recipes')
>>> write(sample_buildout, 'recipes', 'debug.py',
... '''
... class Debug:
... def __init__(self, buildout, name, options):
... options['debug'] = \"\"\" <zodb>
...
... <filestorage>
... path foo
... </filestorage>
...
... </zodb>
... \"\"\"
... options['debug1'] = \"\"\"
... <zodb>
...
... <filestorage>
... path foo
... </filestorage>
...
... </zodb>
... \"\"\"
... options['debug2'] = ' x '
... options['debug3'] = '42'
... options['format'] = '%3d'
...
... def install(self):
... open('t', 'w').write('t')
... return 't'
...
... update = install
... ''')
>>> write(sample_buildout, 'recipes', 'setup.py',
... '''
... from setuptools import setup
... setup(
... name = "recipes",
... entry_points = {'zc.buildout': ['default = debug:Debug']},
... )
... ''')
>>> write(sample_buildout, 'recipes', 'README.txt', " ")
>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... develop = recipes
... parts = debug
...
... [debug]
... recipe = recipes
... ''')
>>> os.chdir(sample_buildout)
>>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
>>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Installing debug.
If we run the buildout again, we shoudn't get a message about
uninstalling anything because the configuration hasn't changed.
>>> print_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Updating debug.
"""
def finding_eggs_as_local_directories():
r"""
It is possible to set up find-links so that we could install from
a local directory that may contained unzipped eggs.
>>> src = tmpdir('src')
>>> write(src, 'setup.py',
... '''
... from setuptools import setup
... setup(name='demo', py_modules=[''],
... zip_safe=False, version='1.0', author='bob', url='bob',
... author_email='bob')
... ''')
>>> write(src, 't.py', '#\n')
>>> write(src, 'README.txt', '')
>>> _ = system(join('bin', 'buildout')+' setup ' + src + ' bdist_egg')
Install it so it gets unzipped:
>>> d1 = tmpdir('d1')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], d1, links=[join(src, 'dist')],
... )
>>> ls(d1)
d demo-1.0-py2.4.egg
Then try to install it again:
>>> d2 = tmpdir('d2')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], d2, links=[d1],
... )
>>> ls(d2)
d demo-1.0-py2.4.egg
"""
def create_sections_on_command_line():
"""
>>> write('buildout.cfg',
... '''
... [buildout]
... parts =
... x = ${foo:bar}
... ''')
>>> print_(system(buildout + ' foo:bar=1 -vv'), end='')
... # doctest: +ELLIPSIS
Installing 'zc.buildout', 'setuptools'.
...
[foo]
bar = 1
...
"""
def test_help():
"""
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')+' -h'))
... # doctest: +ELLIPSIS
Usage: buildout [options] [assignments] [command [command arguments]]
<BLANKLINE>
Options:
<BLANKLINE>
-h, --help
...
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')
... +' --help'))
... # doctest: +ELLIPSIS
Usage: buildout [options] [assignments] [command [command arguments]]
<BLANKLINE>
Options:
<BLANKLINE>
-h, --help
...
"""
def test_version():
"""
>>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
>>> print_(system(buildout+' --version'))
... # doctest: +ELLIPSIS
buildout version ...
"""
def test_bootstrap_with_extension():
"""
We had a problem running a bootstrap with an extension. Let's make
sure it is fixed. Basically, we don't load extensions when
bootstrapping.
>>> d = tmpdir('sample-bootstrap')
>>> write(d, 'buildout.cfg',
... '''
... [buildout]
... extensions = some_awsome_extension
... parts =
... ''')
>>> os.chdir(d)
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')
... + ' bootstrap'), end='')
Creating directory '/sample-bootstrap/eggs'.
Creating directory '/sample-bootstrap/bin'.
Creating directory '/sample-bootstrap/parts'.
Creating directory '/sample-bootstrap/develop-eggs'.
Generated script '/sample-bootstrap/bin/buildout'.
"""
def bug_92891_bootstrap_crashes_with_egg_recipe_in_buildout_section():
"""
>>> d = tmpdir('sample-bootstrap')
>>> write(d, 'buildout.cfg',
... '''
... [buildout]
... parts = buildout
... eggs-directory = eggs
...
... [buildout]
... recipe = zc.recipe.egg
... eggs = zc.buildout
... scripts = buildout=buildout
... ''')
>>> os.chdir(d)
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')
... + ' bootstrap'), end='')
Creating directory '/sample-bootstrap/eggs'.
Creating directory '/sample-bootstrap/bin'.
Creating directory '/sample-bootstrap/parts'.
Creating directory '/sample-bootstrap/develop-eggs'.
Generated script '/sample-bootstrap/bin/buildout'.
>>> print_(system(os.path.join('bin', 'buildout')), end='')
Unused options for buildout: 'scripts' 'eggs'.
"""
def removing_eggs_from_develop_section_causes_egg_link_to_be_removed():
'''
>>> cd(sample_buildout)
Create a develop egg:
>>> mkdir('foo')
>>> write('foo', 'setup.py',
... """
... from setuptools import setup
... setup(name='foox')
... """)
>>> write('buildout.cfg',
... """
... [buildout]
... develop = foo
... parts =
... """)
>>> print_(system(join('bin', 'buildout')), end='')
Develop: '/sample-buildout/foo'
>>> ls('develop-eggs')
- foox.egg-link
- zc.recipe.egg.egg-link
Create another:
>>> mkdir('bar')
>>> write('bar', 'setup.py',
... """
... from setuptools import setup
... setup(name='fooy')
... """)
>>> write('buildout.cfg',
... """
... [buildout]
... develop = foo bar
... parts =
... """)
>>> print_(system(join('bin', 'buildout')), end='')
Develop: '/sample-buildout/foo'
Develop: '/sample-buildout/bar'
>>> ls('develop-eggs')
- foox.egg-link
- fooy.egg-link
- zc.recipe.egg.egg-link
Remove one:
>>> write('buildout.cfg',
... """
... [buildout]
... develop = bar
... parts =
... """)
>>> print_(system(join('bin', 'buildout')), end='')
Develop: '/sample-buildout/bar'
It is gone
>>> ls('develop-eggs')
- fooy.egg-link
- zc.recipe.egg.egg-link
Remove the other:
>>> write('buildout.cfg',
... """
... [buildout]
... parts =
... """)
>>> print_(system(join('bin', 'buildout')), end='')
All gone
>>> ls('develop-eggs')
- zc.recipe.egg.egg-link
'''
def add_setuptools_to_dependencies_when_namespace_packages():
'''
Often, a package depends on setuptools solely by virtue of using
namespace packages. In this situation, package authors often forget to
declare setuptools as a dependency. This is a mistake, but,
unfortunately, a common one that we need to work around. If an egg
uses namespace packages and does not include setuptools as a dependency,
we will still include setuptools in the working set. If we see this for
a develop egg, we will also generate a warning.
>>> mkdir('foo')
>>> mkdir('foo', 'src')
>>> mkdir('foo', 'src', 'stuff')
>>> write('foo', 'src', 'stuff', '__init__.py',
... """__import__('pkg_resources').declare_namespace(__name__)
... """)
>>> mkdir('foo', 'src', 'stuff', 'foox')
>>> write('foo', 'src', 'stuff', 'foox', '__init__.py', '')
>>> write('foo', 'setup.py',
... """
... from setuptools import setup
... setup(name='foox',
... namespace_packages = ['stuff'],
... package_dir = {'': 'src'},
... packages = ['stuff', 'stuff.foox'],
... )
... """)
>>> write('foo', 'README.txt', '')
>>> write('buildout.cfg',
... """
... [buildout]
... develop = foo
... parts =
... """)
>>> print_(system(join('bin', 'buildout')), end='')
Develop: '/sample-buildout/foo'
Now, if we generate a working set using the egg link, we will get a warning
and we will get setuptools included in the working set.
>>> import logging, zope.testing.loggingsupport
>>> handler = zope.testing.loggingsupport.InstalledHandler(
... 'zc.buildout.easy_install', level=logging.WARNING)
>>> logging.getLogger('zc.buildout.easy_install').propagate = False
>>> [dist.project_name
... for dist in zc.buildout.easy_install.working_set(
... ['foox'], sys.executable,
... [join(sample_buildout, 'eggs'),
... join(sample_buildout, 'develop-eggs'),
... ])]
['foox', 'setuptools']
>>> print_(handler)
zc.buildout.easy_install WARNING
Develop distribution: foox 0.0.0
uses namespace packages but the distribution does not require setuptools.
>>> handler.clear()
On the other hand, if we have a regular egg, rather than a develop egg:
>>> os.remove(join('develop-eggs', 'foox.egg-link'))
>>> _ = system(join('bin', 'buildout') + ' setup foo bdist_egg -d'
... + join(sample_buildout, 'eggs'))
>>> ls('develop-eggs')
- zc.recipe.egg.egg-link
>>> ls('eggs') # doctest: +ELLIPSIS
d...
- foox-0.0.0-py2.4.egg
...
d setuptools.eggpyN.N.egg
...
We do not get a warning, but we do get setuptools included in the working set:
>>> [dist.project_name
... for dist in zc.buildout.easy_install.working_set(
... ['foox'], sys.executable,
... [join(sample_buildout, 'eggs'),
... join(sample_buildout, 'develop-eggs'),
... ])]
['foox', 'setuptools']
>>> print_(handler, end='')
We get the same behavior if the it is a dependency that uses a
namespace package.
>>> mkdir('bar')
>>> write('bar', 'setup.py',
... """
... from setuptools import setup
... setup(name='bar', install_requires = ['foox'])
... """)
>>> write('bar', 'README.txt', '')
>>> write('buildout.cfg',
... """
... [buildout]
... develop = foo bar
... parts =
... """)
>>> print_(system(join('bin', 'buildout')), end='')
Develop: '/sample-buildout/foo'
Develop: '/sample-buildout/bar'
>>> [dist.project_name
... for dist in zc.buildout.easy_install.working_set(
... ['bar'], sys.executable,
... [join(sample_buildout, 'eggs'),
... join(sample_buildout, 'develop-eggs'),
... ])]
['bar', 'foox', 'setuptools']
>>> print_(handler, end='')
zc.buildout.easy_install WARNING
Develop distribution: foox 0.0.0
uses namespace packages but the distribution does not require setuptools.
>>> logging.getLogger('zc.buildout.easy_install').propagate = True
>>> handler.uninstall()
'''
def develop_preserves_existing_setup_cfg():
"""
See "Handling custom build options for extensions in develop eggs" in
easy_install.txt. This will be very similar except that we'll have an
existing setup.cfg:
>>> write(extdemo, "setup.cfg",
... '''
... # sampe cfg file
...
... [foo]
... bar = 1
...
... [build_ext]
... define = X,Y
... ''')
>>> mkdir('include')
>>> write('include', 'extdemo.h',
... '''
... #define EXTDEMO 42
... ''')
>>> dest = tmpdir('dest')
>>> zc.buildout.easy_install.develop(
... extdemo, dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')})
'/dest/extdemo.egg-link'
>>> ls(dest)
- extdemo.egg-link
>>> cat(extdemo, "setup.cfg")
<BLANKLINE>
# sampe cfg file
<BLANKLINE>
[foo]
bar = 1
<BLANKLINE>
[build_ext]
define = X,Y
"""
def uninstall_recipes_used_for_removal():
r"""
Uninstall recipes need to be called when a part is removed too:
>>> mkdir("recipes")
>>> write("recipes", "setup.py",
... '''
... from setuptools import setup
... setup(name='recipes',
... entry_points={
... 'zc.buildout': ["demo=demo:Install"],
... 'zc.buildout.uninstall': ["demo=demo:uninstall"],
... })
... ''')
>>> write("recipes", "demo.py",
... r'''
... import sys
... class Install:
... def __init__(*args): pass
... def install(self):
... sys.stdout.write('installing\n')
... return ()
... def uninstall(name, options):
... sys.stdout.write('uninstalling\n')
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... develop = recipes
... parts = demo
... [demo]
... recipe = recipes:demo
... ''')
>>> print_(system(join('bin', 'buildout')), end='')
Develop: '/sample-buildout/recipes'
Installing demo.
installing
>>> write('buildout.cfg', '''
... [buildout]