-
Notifications
You must be signed in to change notification settings - Fork 203
/
easyconfig.py
5124 lines (4410 loc) · 228 KB
/
easyconfig.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
# #
# Copyright 2012-2024 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
# #
"""
Unit tests for easyconfig.py
@author: Toon Willems (Ghent University)
@author: Kenneth Hoste (Ghent University)
@author: Stijn De Weirdt (Ghent University)
"""
import copy
import glob
import os
import re
import shutil
import stat
import sys
import tempfile
import textwrap
from collections import OrderedDict
from easybuild.tools import LooseVersion
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered, init_config
from unittest import TextTestRunner
import easybuild.tools.build_log
import easybuild.framework.easyconfig as easyconfig
import easybuild.tools.github as gh
import easybuild.tools.systemtools as st
from easybuild.framework.easyblock import EasyBlock
from easybuild.framework.easyconfig.constants import EXTERNAL_MODULE_MARKER
from easybuild.framework.easyconfig.easyconfig import ActiveMNS, EasyConfig, create_paths, copy_easyconfigs
from easybuild.framework.easyconfig.easyconfig import det_subtoolchain_version, fix_deprecated_easyconfigs
from easybuild.framework.easyconfig.easyconfig import is_generic_easyblock, get_easyblock_class, get_module_path
from easybuild.framework.easyconfig.easyconfig import letter_dir_for, process_easyconfig, resolve_template
from easybuild.framework.easyconfig.easyconfig import triage_easyconfig_params, verify_easyconfig_filename
from easybuild.framework.easyconfig.licenses import License, LicenseGPLv3
from easybuild.framework.easyconfig.parser import EasyConfigParser, fetch_parameters_from_easyconfig
from easybuild.framework.easyconfig.templates import template_constant_dict, to_template_str
from easybuild.framework.easyconfig.style import check_easyconfigs_style
from easybuild.framework.easyconfig.tools import alt_easyconfig_paths, categorize_files_by_type, check_sha256_checksums
from easybuild.framework.easyconfig.tools import dep_graph, det_copy_ec_specs, find_related_easyconfigs, get_paths_for
from easybuild.framework.easyconfig.tools import parse_easyconfigs
from easybuild.framework.easyconfig.tweak import obtain_ec_for, tweak, tweak_one
from easybuild.framework.extension import resolve_exts_filter_template
from easybuild.toolchains.system import SystemToolchain
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import build_option, get_module_syntax, module_classes, update_build_option
from easybuild.tools.configobj import ConfigObj
from easybuild.tools.docs import avail_easyconfig_constants, avail_easyconfig_templates
from easybuild.tools.filetools import adjust_permissions, change_dir, copy_file, mkdir, read_file
from easybuild.tools.filetools import remove_dir, remove_file, symlink, write_file
from easybuild.tools.module_naming_scheme.toolchain import det_toolchain_compilers, det_toolchain_mpi
from easybuild.tools.module_naming_scheme.utilities import det_full_ec_version
from easybuild.tools.options import parse_external_modules_metadata
from easybuild.tools.py2vs3 import reload
from easybuild.tools.robot import det_robot_path, resolve_dependencies
from easybuild.tools.systemtools import AARCH64, KNOWN_ARCH_CONSTANTS, POWER, X86_64
from easybuild.tools.systemtools import get_cpu_architecture, get_shared_lib_ext, get_os_name, get_os_version
from easybuild.tools.toolchain.utilities import search_toolchain
from easybuild.tools.utilities import quote_str, quote_py_str
from test.framework.github import GITHUB_TEST_ACCOUNT
from test.framework.utilities import find_full_path
try:
import pycodestyle # noqa
except ImportError:
try:
import pep8 # noqa
except ImportError:
pass
EXPECTED_DOTTXT_TOY_DEPS = """digraph graphname {
toy;
"GCC/6.4.0-2.28 (EXT)";
intel;
toy -> intel;
toy -> "GCC/6.4.0-2.28 (EXT)";
}
"""
class EasyConfigTest(EnhancedTestCase):
""" easyconfig tests """
contents = None
eb_file = ''
def setUp(self):
"""Set up everything for running a unit test."""
super(EasyConfigTest, self).setUp()
self.orig_get_cpu_architecture = st.get_cpu_architecture
self.cwd = os.getcwd()
self.all_stops = [x[0] for x in EasyBlock.get_steps()]
if os.path.exists(self.eb_file):
os.remove(self.eb_file)
github_token = gh.fetch_github_token(GITHUB_TEST_ACCOUNT)
self.skip_github_tests = github_token is None and os.getenv('FORCE_EB_GITHUB_TESTS') is None
def prep(self):
"""Prepare for test."""
# (re)cleanup last test file
if os.path.exists(self.eb_file):
os.remove(self.eb_file)
if self.contents is not None:
fd, self.eb_file = tempfile.mkstemp(prefix='easyconfig_test_file_', suffix='.eb')
os.close(fd)
write_file(self.eb_file, self.contents)
def tearDown(self):
""" make sure to remove the temporary file """
st.get_cpu_architecture = self.orig_get_cpu_architecture
super(EasyConfigTest, self).tearDown()
if os.path.exists(self.eb_file):
os.remove(self.eb_file)
def test_empty(self):
""" empty files should not parse! """
self.assertErrorRegex(EasyBuildError, "expected a valid path", EasyConfig, "")
self.contents = "# empty string"
self.prep()
self.assertRaises(EasyBuildError, EasyConfig, self.eb_file)
self.contents = ""
self.prep()
self.assertErrorRegex(EasyBuildError, "is empty", EasyConfig, self.eb_file)
def test_mandatory(self):
""" make sure all checking of mandatory parameters works """
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
])
self.prep()
self.assertErrorRegex(EasyBuildError, "mandatory parameters not provided", EasyConfig, self.eb_file)
self.contents += '\n' + '\n'.join([
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
])
self.prep()
ec = EasyConfig(self.eb_file)
self.assertEqual(ec['name'], "pi")
self.assertEqual(ec['version'], "3.14")
self.assertEqual(ec['homepage'], "http://example.com")
self.assertEqual(ec['toolchain'], {"name": "system", "version": "system"})
self.assertEqual(ec['description'], "test easyconfig")
for key in ['name', 'version', 'homepage', 'toolchain', 'description']:
self.assertTrue(ec.is_mandatory_param(key))
for key in ['buildopts', 'dependencies', 'easyblock', 'sources']:
self.assertFalse(ec.is_mandatory_param(key))
def test_validation(self):
""" test other validations beside mandatory parameters """
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
'stop = "notvalid"',
])
self.prep()
ec = EasyConfig(self.eb_file, validate=False)
self.assertErrorRegex(EasyBuildError, r"\w* provided '\w*' is not valid", ec.validate)
ec['stop'] = 'patch'
# this should now not crash
ec.validate()
ec['osdependencies'] = ['non-existent-dep']
self.assertErrorRegex(EasyBuildError, "OS dependencies were not found", ec.validate)
# system toolchain, installversion == version
self.assertEqual(det_full_ec_version(ec), "3.14")
os.chmod(self.eb_file, 0o000)
self.assertErrorRegex(EasyBuildError, "Permission denied", EasyConfig, self.eb_file)
os.chmod(self.eb_file, 0o755)
self.contents += "\nsyntax_error'"
self.prep()
# exact error message depends on Python version (different starting with Python 3.10)
if sys.version_info >= (3, 10):
error_pattern = "Parsing easyconfig file failed: unterminated string literal"
else:
error_pattern = "Parsing easyconfig file failed: EOL while scanning string literal"
self.assertErrorRegex(EasyBuildError, error_pattern, EasyConfig, self.eb_file)
# introduce "TypeError: format requires mapping" issue"
self.contents = self.contents.replace("syntax_error'", "foo = '%(name)s %s' % version")
self.prep()
error_pattern = r"Parsing easyconfig file failed: format requires a mapping \(line 8\)"
self.assertErrorRegex(EasyBuildError, error_pattern, EasyConfig, self.eb_file)
def test_system_toolchain_constant(self):
"""Test use of SYSTEM constant to specify toolchain."""
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
])
self.prep()
eb = EasyConfig(self.eb_file)
self.assertEqual(eb['toolchain'], {'name': 'system', 'version': 'system'})
self.assertIsInstance(eb.toolchain, SystemToolchain)
def test_shlib_ext(self):
""" inside easyconfigs shared_lib_ext should be set """
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
'sanity_check_paths = { "files": ["lib/lib.%s" % SHLIB_EXT] }',
])
self.prep()
eb = EasyConfig(self.eb_file)
self.assertEqual(eb['sanity_check_paths']['files'][0], "lib/lib.%s" % get_shared_lib_ext())
def test_dependency(self):
""" test all possible ways of specifying dependencies """
init_config(build_options={'silent': True})
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'versionsuffix = "-test"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name":"GCC", "version": "4.6.3"}',
'dependencies = ['
' ("first", "1.1"),'
' {"name": "second", "version": "2.2"},',
# funky way of referring to version(suffix), but should work!
' ("foo", "%(version)s", versionsuffix),',
' ("bar", "1.2.3", "%(versionsuffix)s-123"),',
']',
'builddependencies = [',
' ("first", "1.1"),',
' {"name": "second", "version": "2.2"},',
']',
])
self.prep()
eb = EasyConfig(self.eb_file)
# should include builddependencies
self.assertEqual(len(eb.dependencies()), 6)
self.assertEqual(len(eb.builddependencies()), 2)
first = eb.dependencies()[0]
second = eb.dependencies()[1]
self.assertEqual(first['name'], "first")
self.assertEqual(first['version'], "1.1")
self.assertEqual(first['versionsuffix'], '')
self.assertEqual(second['name'], "second")
self.assertEqual(second['version'], "2.2")
self.assertEqual(second['versionsuffix'], '')
self.assertEqual(eb['dependencies'][2]['name'], 'foo')
self.assertEqual(eb['dependencies'][2]['version'], '3.14')
self.assertEqual(eb['dependencies'][2]['versionsuffix'], '-test')
self.assertEqual(eb['dependencies'][3]['name'], 'bar')
self.assertEqual(eb['dependencies'][3]['version'], '1.2.3')
self.assertEqual(eb['dependencies'][3]['versionsuffix'], '-test-123')
self.assertEqual(det_full_ec_version(first), '1.1-GCC-4.6.3')
self.assertEqual(det_full_ec_version(second), '2.2-GCC-4.6.3')
self.assertEqual(eb.dependency_names(), {'first', 'second', 'foo', 'bar'})
# same tests for builddependencies
self.assertEqual(eb.dependency_names(build_only=True), {'first', 'second'})
first = eb.builddependencies()[0]
second = eb.builddependencies()[1]
self.assertEqual(first['name'], "first")
self.assertEqual(second['name'], "second")
self.assertEqual(first['version'], "1.1")
self.assertEqual(second['version'], "2.2")
self.assertEqual(det_full_ec_version(first), '1.1-GCC-4.6.3')
self.assertEqual(det_full_ec_version(second), '2.2-GCC-4.6.3')
self.assertErrorRegex(EasyBuildError, "Dependency foo of unsupported type", eb._parse_dependency, "foo")
self.assertErrorRegex(EasyBuildError, "without name", eb._parse_dependency, ())
self.assertErrorRegex(EasyBuildError, "without version", eb._parse_dependency, {'name': 'test'})
err_msg = "Incorrect external dependency specification"
self.assertErrorRegex(EasyBuildError, err_msg, eb._parse_dependency, (EXTERNAL_MODULE_MARKER,))
self.assertErrorRegex(EasyBuildError, err_msg, eb._parse_dependency, ('foo', '1.2.3', EXTERNAL_MODULE_MARKER))
def test_false_dep_version(self):
"""
Test use False as dependency version via dict using 'arch=' keys,
which should result in filtering the dependency.
"""
# silence warnings about missing easyconfigs for dependencies, we don't care
init_config(build_options={'silent': True})
arch = get_cpu_architecture()
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'versionsuffix = "-test"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name":"GCC", "version": "4.6.3"}',
'builddependencies = [',
' ("first_build", {"arch=%s": False}),' % arch,
' ("second_build", "2.0"),',
']',
'dependencies = ['
' ("first", "1.0"),',
' ("second", {"arch=%s": False}),' % arch,
']',
])
self.prep()
eb = EasyConfig(self.eb_file)
deps = eb.dependencies()
self.assertEqual(len(deps), 2)
self.assertEqual(deps[0]['name'], 'second_build')
self.assertEqual(deps[1]['name'], 'first')
self.assertEqual(eb.dependency_names(), {'first', 'second_build'})
# more realistic example: only filter dep for POWER
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'versionsuffix = "-test"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name":"GCC", "version": "4.6.3"}',
'dependencies = ['
' ("not_on_power", {"arch=*": "1.2.3", "arch=POWER": False}),',
']',
])
self.prep()
# only non-POWER arch, dependency is retained
for arch in (AARCH64, X86_64):
st.get_cpu_architecture = lambda: arch
eb = EasyConfig(self.eb_file)
deps = eb.dependencies()
self.assertEqual(len(deps), 1)
self.assertEqual(deps[0]['name'], 'not_on_power')
self.assertEqual(eb.dependency_names(), {'not_on_power'})
# only power, dependency gets filtered
st.get_cpu_architecture = lambda: POWER
eb = EasyConfig(self.eb_file)
deps = eb.dependencies()
self.assertEqual(deps, [])
self.assertEqual(eb.dependency_names(), set())
def test_extra_options(self):
""" extra_options should allow other variables to be stored """
init_config(build_options={'silent': True})
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name":"GCC", "version": "4.6.3"}',
'toolchainopts = { "static": True}',
'dependencies = [("first", "1.1"), {"name": "second", "version": "2.2"}]',
])
self.prep()
eb = EasyConfig(self.eb_file)
self.assertErrorRegex(EasyBuildError, "unknown easyconfig parameter", lambda: eb['custom_key'])
extra_vars = {'custom_key': ['default', "This is a default key", easyconfig.CUSTOM]}
ec = EasyConfig(self.eb_file, extra_options=extra_vars)
self.assertEqual(ec['custom_key'], 'default')
self.assertFalse(ec.is_mandatory_param('custom_key'))
ec['custom_key'] = "not so default"
self.assertEqual(ec['custom_key'], 'not so default')
self.contents += "\ncustom_key = 'test'"
self.prep()
ec = EasyConfig(self.eb_file, extra_options=extra_vars)
self.assertEqual(ec['custom_key'], 'test')
ec['custom_key'] = "not so default"
self.assertEqual(ec['custom_key'], 'not so default')
# test if extra toolchain options are being passed
self.assertEqual(ec.toolchain.options['static'], True)
# test extra mandatory parameters
extra_vars.update({'mandatory_key': ['default', 'another mandatory key', easyconfig.MANDATORY]})
self.assertErrorRegex(EasyBuildError, r"mandatory parameters not provided",
EasyConfig, self.eb_file, extra_options=extra_vars)
self.contents += '\nmandatory_key = "value"'
self.prep()
ec = EasyConfig(self.eb_file, extra_options=extra_vars)
self.assertEqual(ec['mandatory_key'], 'value')
self.assertTrue(ec.is_mandatory_param('mandatory_key'))
# check whether mandatory key is retained in dumped easyconfig file, even if it's set to the default value
ec['mandatory_key'] = 'default'
test_ecfile = os.path.join(self.test_prefix, 'test_dump_mandatory.eb')
ec.dump(test_ecfile)
regex = re.compile("^mandatory_key = 'default'$", re.M)
ectxt = read_file(test_ecfile)
self.assertTrue(regex.search(ectxt), "Pattern '%s' found in: %s" % (regex.pattern, ectxt))
# parsing again should work fine (if mandatory easyconfig parameters are indeed retained)
ec = EasyConfig(test_ecfile, extra_options=extra_vars)
self.assertEqual(ec['mandatory_key'], 'default')
def test_exts_list(self):
"""Test handling of list of extensions."""
topdir = os.path.dirname(os.path.abspath(__file__))
os.environ['EASYBUILD_SOURCEPATH'] = ':'.join([
os.path.join(topdir, 'easyconfigs', 'test_ecs', 'g', 'gzip'),
os.path.join(topdir, 'easyconfigs', 'test_ecs', 't', 'toy'),
])
init_config()
self.contents = textwrap.dedent("""
easyblock = "ConfigureMake"
name = "PI"
version = "3.14"
homepage = "http://example.com"
description = "test easyconfig"
toolchain = SYSTEM
exts_default_options = {
"source_tmpl": "gzip-1.4.eb", # dummy source template to avoid download fail
"source_urls": ["http://example.com/%(name)s/%(version)s"]
}
exts_list = [
("ext1", "1.0"),
("ext2", "2.0", {
"source_urls": [("http://example.com", "suffix")],
"patches": [("toy-0.0.eb", ".")], # dummy patch to avoid download fail
"checksums": [
# SHA256 checksum for source (gzip-1.4.eb)
"6a5abcab719cefa95dca4af0db0d2a9d205d68f775a33b452ec0f2b75b6a3a45",
# SHA256 checksum for 'patch' (toy-0.0.eb)
"2d964e0e8f05a7cce0dd83a3e68c9737da14b87b61b8b8b0291d58d4c8d1031c",
],
}),
# Can use templates in name and version
("ext-%(name)s", "%(version)s"),
("ext-%(namelower)s", "%(version_major)s.0"),
]
""")
self.prep()
ec = EasyConfig(self.eb_file)
eb = EasyBlock(ec)
exts_sources = eb.collect_exts_file_info()
self.assertEqual(len(exts_sources), 4)
self.assertEqual(exts_sources[0]['name'], 'ext1')
self.assertEqual(exts_sources[0]['version'], '1.0')
self.assertEqual(exts_sources[0]['options'], {
'source_tmpl': 'gzip-1.4.eb',
'source_urls': ['http://example.com/%(name)s/%(version)s'],
})
self.assertEqual(exts_sources[1]['name'], 'ext2')
self.assertEqual(exts_sources[1]['version'], '2.0')
self.assertEqual(exts_sources[1]['options'], {
'checksums': ['6a5abcab719cefa95dca4af0db0d2a9d205d68f775a33b452ec0f2b75b6a3a45',
'2d964e0e8f05a7cce0dd83a3e68c9737da14b87b61b8b8b0291d58d4c8d1031c'],
'patches': [('toy-0.0.eb', '.')],
'source_tmpl': 'gzip-1.4.eb',
'source_urls': [('http://example.com', 'suffix')],
})
self.assertEqual(exts_sources[2]['name'], 'ext-PI')
self.assertEqual(exts_sources[2]['version'], '3.14')
self.assertEqual(exts_sources[3]['name'], 'ext-pi')
self.assertEqual(exts_sources[3]['version'], '3.0')
modfile = os.path.join(eb.make_module_step(), 'PI', '3.14' + eb.module_generator.MODULE_FILE_EXTENSION)
modtxt = read_file(modfile)
regex = re.compile('EBEXTSLISTPI.*ext1-1.0,ext2-2.0')
self.assertTrue(regex.search(modtxt), "Pattern '%s' found in: %s" % (regex.pattern, modtxt))
def test_extensions_templates(self):
"""Test whether templates used in exts_list are resolved properly."""
# put dummy source file in place to avoid download fail
toy_tar_gz = os.path.join(self.test_sourcepath, 'toy', 'toy-0.0.tar.gz')
copy_file(toy_tar_gz, os.path.join(self.test_prefix, 'toy-0.0-py3-test.tar.gz'))
toy_patch_fn = 'toy-0.0_fix-silly-typo-in-printf-statement.patch'
toy_patch = os.path.join(self.test_sourcepath, 'toy', toy_patch_fn)
copy_file(toy_patch, self.test_prefix)
os.environ['EASYBUILD_SOURCEPATH'] = self.test_prefix
init_config(build_options={'silent': True})
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'versionsuffix = "-test"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
'dependencies = [("Python", "3.6.6")]',
'exts_defaultclass = "EB_Toy"',
# bogus, but useful to check whether this get resolved
'exts_default_options = {"source_urls": [PYPI_SOURCE]}',
'exts_list = [',
' ("toy", "0.0", {',
# %(name)s and %(version_major_minor)s should be resolved using name/version of extension (not parent)
# %(pymajver)s should get resolved because Python is listed as a (runtime) dep
# %(versionsuffix)s should get resolved with value of parent
' "source_tmpl": "%(name)s-%(version_major_minor)s-py%(pymajver)s%(versionsuffix)s.tar.gz",',
' "patches": ["%(name)s-%(version)s_fix-silly-typo-in-printf-statement.patch"],',
# use hacky prebuildopts that is picked up by 'EB_Toy' easyblock, to check whether templates are resolved
' "prebuildopts": "gcc -O2 %(name)s.c -o toy-%(version)s &&' +
' mv toy-%(version)s toy # echo installdir is %(installdir)s #",',
' }),',
']',
])
self.prep()
ec = EasyConfig(self.eb_file)
eb = EasyBlock(ec)
eb.fetch_step()
# inject OS dependency that can not be fullfilled,
# to check whether OS deps are validated again for each extension (they shouldn't be);
# we need to tweak the contents of the easyconfig file via cfg.rawtxt, since that's what is used to re-parse
# the easyconfig file for the extension
eb.cfg.rawtxt += "\nosdependencies = ['this_os_dep_does_not_exist']"
# run extensions step to install 'toy' extension
eb.extensions_step()
# check whether template values were resolved correctly in Extension instances that were created/used
toy_ext = eb.ext_instances[0]
self.assertEqual(os.path.basename(toy_ext.src), 'toy-0.0-py3-test.tar.gz')
patches = []
for patch in toy_ext.patches:
patches.append(patch['path'])
self.assertEqual(patches, [os.path.join(self.test_prefix, toy_patch_fn)])
# define actual installation dir
pi_installdir = os.path.join(self.test_installpath, 'software', 'pi', '3.14-test')
expected_prebuildopts = 'gcc -O2 toy.c -o toy-0.0 && mv toy-0.0 toy # echo installdir is %s #' % pi_installdir
expected = {
'patches': ['toy-0.0_fix-silly-typo-in-printf-statement.patch'],
'prebuildopts': expected_prebuildopts,
'source_tmpl': 'toy-0.0-py3-test.tar.gz',
'source_urls': ['https://pypi.python.org/packages/source/t/toy'],
}
self.assertEqual(toy_ext.options, expected)
# also .cfg of Extension instance was updated correctly
self.assertEqual(toy_ext.cfg['source_urls'], ['https://pypi.python.org/packages/source/t/toy'])
self.assertEqual(toy_ext.cfg['patches'], [toy_patch_fn])
self.assertEqual(toy_ext.cfg['prebuildopts'], expected_prebuildopts)
# check whether files expected to be installed for 'toy' extension are in place
self.assertExists(os.path.join(pi_installdir, 'bin', 'toy'))
self.assertExists(os.path.join(pi_installdir, 'lib', 'libtoy.a'))
def test_suggestions(self):
""" If a typo is present, suggestions should be provided (if possible) """
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name":"GCC", "version": "4.6.3"}',
'dependencis = [("first", "1.1"), {"name": "second", "version": "2.2"}]',
'source_uls = ["http://example.com"]',
'source_URLs = ["http://example.com"]',
'sourceURLs = ["http://example.com"]',
])
self.prep()
self.assertErrorRegex(EasyBuildError, "dependencis -> dependencies", EasyConfig, self.eb_file)
self.assertErrorRegex(EasyBuildError, "source_uls -> source_urls", EasyConfig, self.eb_file)
self.assertErrorRegex(EasyBuildError, "source_URLs -> source_urls", EasyConfig, self.eb_file)
self.assertErrorRegex(EasyBuildError, "sourceURLs -> source_urls", EasyConfig, self.eb_file)
# No error for known params prefixed by "local_"
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name":"GCC", "version": "4.6.3"}',
'local_source_urls = "https://example.com"',
'source_urls = [local_source_urls]',
'local_cuda_compute_capabilities = ["3.3"]', # This is known that it triggered the typo detection before
'cuda_compute_capabilities = local_cuda_compute_capabilities',
])
self.prep()
# Should not raise any error, sanity check that something was done below
ec = EasyConfig(self.eb_file)
self.assertEqual(ec['version'], '3.14')
def test_tweaking(self):
"""test tweaking ability of easyconfigs"""
fd, tweaked_fn = tempfile.mkstemp(prefix='easybuild-tweaked-', suffix='.eb')
os.close(fd)
remove_file(tweaked_fn)
patches = ["t1.patch", ("t2.patch", 1), ("t3.patch", "test"), ("t4.h", "include")]
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'homepage = "http://www.example.com"',
'description = "dummy description"',
'version = "3.14"',
'toolchain = {"name": "GCC", "version": "4.6.3"}',
'patches = %s',
'parallel = 1',
'keepsymlinks = True',
]) % str(patches)
self.prep()
ver = "1.2.3"
verpref = "myprefix"
versuff = "mysuffix"
tcname = "gompi"
tcver = "2018a"
new_patches = ['t5.patch', 't6.patch']
homepage = "http://www.justatest.com"
tweaks = {
'version': ver,
'versionprefix': verpref,
'versionsuffix': versuff,
'toolchain_version': tcver,
'patches': new_patches,
'keepsymlinks': 'True', # Don't change this
# It should be possible to overwrite values with True/False/None as they often have special meaning
'runtest': 'False',
'hidden': 'True',
'parallel': 'None', # Good example: parallel=None means "Auto detect"
# Adding new options (added only by easyblock) should also be possible
# and in case the string "True/False/None" is really wanted it is possible to quote it first
'test_none': '"False"',
'test_bool': '"True"',
'test_123': '"None"',
}
tweak_one(self.eb_file, tweaked_fn, tweaks)
eb = EasyConfig(tweaked_fn)
self.assertEqual(eb['version'], ver)
self.assertEqual(eb['versionprefix'], verpref)
self.assertEqual(eb['versionsuffix'], versuff)
self.assertEqual(eb['toolchain']['version'], tcver)
self.assertEqual(eb['patches'], new_patches)
self.assertIs(eb['runtest'], False)
self.assertIs(eb['hidden'], True)
self.assertIsNone(eb['parallel'])
self.assertEqual(eb['test_none'], 'False')
self.assertEqual(eb['test_bool'], 'True')
self.assertEqual(eb['test_123'], 'None')
remove_file(tweaked_fn)
eb = EasyConfig(self.eb_file)
# eb['toolchain']['version'] = tcver does not work as expected with templating enabled
with eb.disable_templating():
eb['version'] = ver
eb['toolchain']['version'] = tcver
eb.dump(self.eb_file)
tweaks = {
'toolchain_name': tcname,
'patches': new_patches[:1],
'homepage': homepage,
}
tweak_one(self.eb_file, tweaked_fn, tweaks)
eb = EasyConfig(tweaked_fn)
self.assertEqual(eb['toolchain']['name'], tcname)
self.assertEqual(eb['toolchain']['version'], tcver)
self.assertEqual(eb['patches'], new_patches[:1])
self.assertEqual(eb['version'], ver)
self.assertEqual(eb['homepage'], homepage)
# specify patches as string, eb should promote it to a list because original value was a list
tweaks['patches'] = new_patches[0]
eb = EasyConfig(tweaked_fn)
self.assertEqual(eb['patches'], [new_patches[0]])
# cleanup
os.remove(tweaked_fn)
def test_alt_easyconfig_paths(self):
"""Test alt_easyconfig_paths function that collects list of additional paths for easyconfig files."""
tweaked_ecs_path, extra_ecs_path = alt_easyconfig_paths(self.test_prefix)
self.assertEqual(tweaked_ecs_path, None)
self.assertEqual(extra_ecs_path, [])
tweaked_ecs_path, extra_ecs_path = alt_easyconfig_paths(self.test_prefix, tweaked_ecs=True)
self.assertTrue(tweaked_ecs_path)
self.assertTrue(isinstance(tweaked_ecs_path, tuple))
self.assertEqual(len(tweaked_ecs_path), 2)
self.assertEqual(tweaked_ecs_path[0], os.path.join(self.test_prefix, 'tweaked_easyconfigs'))
self.assertEqual(tweaked_ecs_path[1], os.path.join(self.test_prefix, 'tweaked_dep_easyconfigs'))
self.assertEqual(extra_ecs_path, [])
tweaked_ecs_path, extra_ecs_path = alt_easyconfig_paths(self.test_prefix, from_prs=[123, 456])
self.assertEqual(tweaked_ecs_path, None)
self.assertTrue(extra_ecs_path)
self.assertTrue(isinstance(extra_ecs_path, list))
self.assertEqual(len(extra_ecs_path), 2)
self.assertEqual(extra_ecs_path[0], os.path.join(self.test_prefix, 'files_pr123'))
self.assertEqual(extra_ecs_path[1], os.path.join(self.test_prefix, 'files_pr456'))
tweaked_ecs_path, extra_ecs_path = alt_easyconfig_paths(self.test_prefix, from_prs=[123, 456],
review_pr=789, from_commit='c0ff33')
self.assertEqual(tweaked_ecs_path, None)
self.assertTrue(extra_ecs_path)
self.assertTrue(isinstance(extra_ecs_path, list))
self.assertEqual(len(extra_ecs_path), 4)
self.assertEqual(extra_ecs_path[0], os.path.join(self.test_prefix, 'files_pr123'))
self.assertEqual(extra_ecs_path[1], os.path.join(self.test_prefix, 'files_pr456'))
self.assertEqual(extra_ecs_path[2], os.path.join(self.test_prefix, 'files_pr789'))
self.assertEqual(extra_ecs_path[3], os.path.join(self.test_prefix, 'files_commit_c0ff33'))
def test_tweak_multiple_tcs(self):
"""Test that tweaking variables of ECs from multiple toolchains works"""
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
# Create directories to store the tweaked easyconfigs
tweaked_ecs_paths, pr_path = alt_easyconfig_paths(self.test_prefix, tweaked_ecs=True)
robot_path = det_robot_path([test_easyconfigs], tweaked_ecs_paths, pr_path, auto_robot=True)
init_config(build_options={
'valid_module_classes': module_classes(),
'robot_path': robot_path,
'check_osdeps': False,
})
# Allow tweaking of non-toolchain values for multiple ECs of different toolchains
untweaked_openmpi_1 = os.path.join(test_easyconfigs, 'o', 'OpenMPI', 'OpenMPI-2.1.2-GCC-4.6.4.eb')
untweaked_openmpi_2 = os.path.join(test_easyconfigs, 'o', 'OpenMPI', 'OpenMPI-3.1.1-GCC-7.3.0-2.30.eb')
easyconfigs, _ = parse_easyconfigs([(untweaked_openmpi_1, False), (untweaked_openmpi_2, False)])
tweak_specs = {'moduleclass': 'debugger'}
easyconfigs = tweak(easyconfigs, tweak_specs, self.modtool, targetdirs=tweaked_ecs_paths)
# Check that all expected tweaked easyconfigs exists
tweaked_openmpi_1 = os.path.join(tweaked_ecs_paths[0], os.path.basename(untweaked_openmpi_1))
tweaked_openmpi_2 = os.path.join(tweaked_ecs_paths[0], os.path.basename(untweaked_openmpi_2))
self.assertTrue(os.path.isfile(tweaked_openmpi_1))
self.assertTrue(os.path.isfile(tweaked_openmpi_2))
tweaked_openmpi_content_1 = read_file(tweaked_openmpi_1)
tweaked_openmpi_content_2 = read_file(tweaked_openmpi_2)
self.assertTrue('moduleclass = "debugger"' in tweaked_openmpi_content_1,
"Tweaked value not found in " + tweaked_openmpi_content_1)
self.assertTrue('moduleclass = "debugger"' in tweaked_openmpi_content_2,
"Tweaked value not found in " + tweaked_openmpi_content_2)
def test_installversion(self):
"""Test generation of install version."""
ver = "3.14"
verpref = "myprefix|"
versuff = "|mysuffix"
tcname = "GCC"
tcver = "4.6.3"
system = "system"
correct_installver = "%s%s-%s-%s%s" % (verpref, ver, tcname, tcver, versuff)
cfg = {
'version': ver,
'toolchain': {'name': tcname, 'version': tcver},
'versionprefix': verpref,
'versionsuffix': versuff,
}
installver = det_full_ec_version(cfg)
self.assertEqual(installver, "%s%s-%s-%s%s" % (verpref, ver, tcname, tcver, versuff))
correct_installver = "%s%s%s" % (verpref, ver, versuff)
cfg = {
'version': ver,
'toolchain': {'name': system, 'version': tcver},
'versionprefix': verpref,
'versionsuffix': versuff,
}
installver = det_full_ec_version(cfg)
self.assertEqual(installver, correct_installver)
# only version key is strictly needed
self.assertEqual(det_full_ec_version({'version': '1.2.3'}), '1.2.3')
# versionprefix/versionsuffix can also be set to None,
# see https://github.com/easybuilders/easybuild-framework/issues/4281
cfg['versionprefix'] = None
cfg['versionsuffix'] = None
self.assertEqual(det_full_ec_version(cfg), '3.14')
# check how faulty dep spec is handled
faulty_dep_spec = {
'name': 'test',
'version': '1.2.3',
'versionsuffix': {'name': 'system', 'version': 'system'},
}
error_pattern = "versionsuffix value should be a string, found 'dict'"
self.assertErrorRegex(EasyBuildError, error_pattern, det_full_ec_version, faulty_dep_spec)
def test_obtain_easyconfig(self):
"""test obtaining an easyconfig file given certain specifications"""
init_config(build_options={'silent': True})
change_dir(self.test_prefix)
tcname = 'GCC'
tcver = '4.6.3'
patches = ["one.patch"]
# prepare a couple of eb files to test again
fns = ["pi-3.14.eb",
"pi-3.13-GCC-4.6.3.eb",
"pi-3.15-GCC-4.6.3.eb",
"pi-3.15-GCC-4.8.3.eb",
"foo-1.2.3-GCC-4.6.3.eb"]
eb_files = [
(fns[0], "\n".join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.12"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = SYSTEM',
'patches = %s' % patches
])),
(fns[1], "\n".join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.13"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name": "%s", "version": "%s"}' % (tcname, tcver),
'patches = %s' % patches
])),
(fns[2], "\n".join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.15"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name": "%s", "version": "%s"}' % (tcname, tcver),
'patches = %s' % patches
])),
(fns[3], "\n".join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.15"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name": "%s", "version": "4.9.2"}' % tcname,
'patches = %s' % patches
])),
(fns[4], "\n".join([
'easyblock = "ConfigureMake"',
'name = "foo"',
'version = "1.2.3"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
'toolchain = {"name": "%s", "version": "%s"}' % (tcname, tcver),
'local_foo_extra1 = "bar"',
]))
]
for (fn, txt) in eb_files:
write_file(os.path.join(self.test_prefix, fn), txt)
# should crash when no suited easyconfig file (or template) is available
specs = {'name': 'nosuchsoftware'}
error_regexp = ".*No easyconfig files found for software %s, and no templates available. I'm all out of ideas."
error_regexp = error_regexp % specs['name']
self.assertErrorRegex(EasyBuildError, error_regexp, obtain_ec_for, specs, [self.test_prefix], None)
# should find matching easyconfig file
specs = {
'name': 'foo',
'version': '1.2.3'
}
res = obtain_ec_for(specs, [self.test_prefix], None)
self.assertEqual(res[0], False)
self.assertEqual(res[1], os.path.join(self.test_prefix, fns[-1]))
remove_file(res[1])
# should not pick between multiple available toolchain names
name = "pi"
ver = "3.12"
suff = "mysuff"
specs.update({
'name': name,
'version': ver,
'versionsuffix': suff
})
error_regexp = ".*No toolchain name specified, and more than one available: .*"
self.assertErrorRegex(EasyBuildError, error_regexp, obtain_ec_for, specs, [self.test_prefix], None)
# should be able to generate an easyconfig file that slightly differs
ver = '3.16'
specs.update({
'toolchain_name': tcname,
'toolchain_version': tcver,
'version': ver,
'start_dir': 'bar123'
})
res = obtain_ec_for(specs, [self.test_prefix], None)
self.assertEqual(res[1], "%s-%s-%s-%s%s.eb" % (name, ver, tcname, tcver, suff))
self.assertEqual(res[0], True)
ec = EasyConfig(res[1])
self.assertEqual(ec['name'], specs['name'])
self.assertEqual(ec['version'], specs['version'])
self.assertEqual(ec['versionsuffix'], specs['versionsuffix'])
self.assertEqual(ec['toolchain'], {'name': tcname, 'version': tcver})
self.assertEqual(ec['start_dir'], specs['start_dir'])
remove_file(res[1])
# should pick correct version, i.e. not newer than what's specified, if a choice needs to be made
ver = '3.14'
specs.update({'version': ver})
res = obtain_ec_for(specs, [self.test_prefix], None)
self.assertEqual(res[0], True)
ec = EasyConfig(res[1])
self.assertEqual(ec['version'], specs['version'])
txt = read_file(res[1])
self.assertTrue(re.search("^version = [\"']%s[\"']$" % ver, txt, re.M))
remove_file(res[1])
# should pick correct toolchain version as well, i.e. now newer than what's specified,
# if a choice needs to be made
specs.update({
'version': '3.15',
'toolchain_version': '4.8.3',
})
res = obtain_ec_for(specs, [self.test_prefix], None)
self.assertEqual(res[0], True)
ec = EasyConfig(res[1])
self.assertEqual(ec['version'], specs['version'])
self.assertEqual(ec['toolchain']['version'], specs['toolchain_version'])
txt = read_file(res[1])
pattern = "^toolchain = .*version.*[\"']%s[\"'].*}$" % specs['toolchain_version']
self.assertTrue(re.search(pattern, txt, re.M))
os.remove(res[1])
# should be able to prepend to list of patches and handle list of dependencies
new_patches = ['two.patch', 'three.patch']
specs.update({
'patches': new_patches[:],
'builddependencies': [('testbuildonly', '4.9.3-2.25')],