7
7
8
8
import os
9
9
import re
10
- from collections import namedtuple
11
10
from contextlib import contextmanager
12
11
13
12
import six
14
13
15
14
from .find import find_one
15
+ from .models import Build , Conda , Mkdocs , Python , Sphinx , Submodules
16
16
from .parser import ParseError , parse
17
17
from .validation import (
18
18
ValidationError , validate_bool , validate_choice , validate_dict ,
@@ -177,7 +177,7 @@ def python_interpreter(self):
177
177
178
178
@property
179
179
def python_full_version (self ):
180
- ver = self .python_version
180
+ ver = self .python . version
181
181
if ver in [2 , 3 ]:
182
182
# Get the highest version of the major series version if user only
183
183
# gave us a version of '2', or '3'
@@ -361,12 +361,9 @@ def validate_python(self):
361
361
version = self .defaults .get ('python_version' , 2 )
362
362
python = {
363
363
'use_system_site_packages' : use_system_packages ,
364
- 'pip_install ' : False ,
364
+ 'install_with_pip ' : False ,
365
365
'extra_requirements' : [],
366
- 'setup_py_install' : install_project ,
367
- 'setup_py_path' : os .path .join (
368
- os .path .dirname (self .source_file ),
369
- 'setup.py' ),
366
+ 'install_with_setup' : install_project ,
370
367
'version' : version ,
371
368
}
372
369
@@ -388,7 +385,7 @@ def validate_python(self):
388
385
# Validate pip_install.
389
386
if 'pip_install' in raw_python :
390
387
with self .catch_validation_error ('python.pip_install' ):
391
- python ['pip_install ' ] = validate_bool (
388
+ python ['install_with_pip ' ] = validate_bool (
392
389
raw_python ['pip_install' ])
393
390
394
391
# Validate extra_requirements.
@@ -399,26 +396,22 @@ def validate_python(self):
399
396
'python.extra_requirements' ,
400
397
self .PYTHON_EXTRA_REQUIREMENTS_INVALID_MESSAGE ,
401
398
code = PYTHON_INVALID )
402
- for extra_name in raw_extra_requirements :
403
- with self .catch_validation_error (
404
- 'python.extra_requirements' ):
405
- python ['extra_requirements' ].append (
406
- validate_string (extra_name )
407
- )
399
+ if not python ['install_with_pip' ]:
400
+ python ['extra_requirements' ] = []
401
+ else :
402
+ for extra_name in raw_extra_requirements :
403
+ with self .catch_validation_error (
404
+ 'python.extra_requirements' ):
405
+ python ['extra_requirements' ].append (
406
+ validate_string (extra_name )
407
+ )
408
408
409
409
# Validate setup_py_install.
410
410
if 'setup_py_install' in raw_python :
411
411
with self .catch_validation_error ('python.setup_py_install' ):
412
- python ['setup_py_install ' ] = validate_bool (
412
+ python ['install_with_setup ' ] = validate_bool (
413
413
raw_python ['setup_py_install' ])
414
414
415
- # Validate setup_py_path.
416
- if 'setup_py_path' in raw_python :
417
- with self .catch_validation_error ('python.setup_py_path' ):
418
- base_path = os .path .dirname (self .source_file )
419
- python ['setup_py_path' ] = validate_file (
420
- raw_python ['setup_py_path' ], base_path )
421
-
422
415
if 'version' in raw_python :
423
416
with self .catch_validation_error ('python.version' ):
424
417
# Try to convert strings to an int first, to catch '2', then
@@ -451,11 +444,14 @@ def validate_conda(self):
451
444
self .PYTHON_INVALID_MESSAGE ,
452
445
code = PYTHON_INVALID )
453
446
447
+ conda_environment = None
454
448
if 'file' in raw_conda :
455
449
with self .catch_validation_error ('conda.file' ):
456
450
base_path = os .path .dirname (self .source_file )
457
- conda ['file' ] = validate_file (
458
- raw_conda ['file' ], base_path )
451
+ conda_environment = validate_file (
452
+ raw_conda ['file' ], base_path
453
+ )
454
+ conda ['environment' ] = conda_environment
459
455
460
456
return conda
461
457
return None
@@ -511,58 +507,24 @@ def formats(self):
511
507
@property
512
508
def python (self ):
513
509
"""Python related configuration."""
514
- return self ._config .get ('python' , {})
515
-
516
- @property
517
- def python_version (self ):
518
- """Python version."""
519
- return self ._config ['python' ]['version' ]
520
-
521
- @property
522
- def pip_install (self ):
523
- """True if the project should be installed using pip."""
524
- return self ._config ['python' ]['pip_install' ]
525
-
526
- @property
527
- def install_project (self ):
528
- """True if the project should be installed."""
529
- if self .pip_install :
530
- return True
531
- return self ._config ['python' ]['setup_py_install' ]
532
-
533
- @property
534
- def extra_requirements (self ):
535
- """Extra requirements to be installed with pip."""
536
- if self .pip_install :
537
- return self ._config ['python' ]['extra_requirements' ]
538
- return []
539
-
540
- @property
541
- def use_system_site_packages (self ):
542
- """True if the project should have access to the system packages."""
543
- return self ._config ['python' ]['use_system_site_packages' ]
544
-
545
- @property
546
- def use_conda (self ):
547
- """True if the project use Conda."""
548
- return self ._config .get ('conda' ) is not None
510
+ requirements = self ._config ['requirements_file' ]
511
+ self ._config ['python' ]['requirements' ] = requirements
512
+ return Python (** self ._config ['python' ])
549
513
550
514
@property
551
- def conda_file (self ):
552
- """The Conda environment file."""
553
- if self .use_conda :
554
- return self ._config ['conda' ].get ('file' )
515
+ def conda (self ):
516
+ if self ._config ['conda' ] is not None :
517
+ return Conda (** self ._config ['conda' ])
555
518
return None
556
519
557
520
@property
558
- def requirements_file (self ):
559
- """The project requirements file ."""
560
- return self ._config ['requirements_file' ]
521
+ def build (self ):
522
+ """The docker image used by the builders ."""
523
+ return Build ( ** self ._config ['build' ])
561
524
562
525
@property
563
- def build_image (self ):
564
- """The docker image used by the builders."""
565
- return self ._config ['build' ]['image' ]
526
+ def doctype (self ):
527
+ return self .defaults ['doctype' ]
566
528
567
529
568
530
class BuildConfigV2 (BuildConfigBase ):
@@ -888,47 +850,26 @@ def formats(self):
888
850
889
851
@property
890
852
def conda (self ):
891
- Conda = namedtuple ('Conda' , ['environment' ]) # noqa
892
853
if self ._config ['conda' ]:
893
854
return Conda (** self ._config ['conda' ])
894
855
return None
895
856
896
857
@property
897
858
def build (self ):
898
- Build = namedtuple ('Build' , ['image' ]) # noqa
899
859
return Build (** self ._config ['build' ])
900
860
901
861
@property
902
862
def python (self ):
903
- Python = namedtuple ( # noqa
904
- 'Python' ,
905
- [
906
- 'version' ,
907
- 'requirements' ,
908
- 'install_with_pip' ,
909
- 'install_with_setup' ,
910
- 'extra_requirements' ,
911
- 'use_system_site_packages' ,
912
- ],
913
- )
914
863
return Python (** self ._config ['python' ])
915
864
916
865
@property
917
866
def sphinx (self ):
918
- Sphinx = namedtuple ( # noqa
919
- 'Sphinx' ,
920
- ['builder' , 'configuration' , 'fail_on_warning' ],
921
- )
922
867
if self ._config ['sphinx' ]:
923
868
return Sphinx (** self ._config ['sphinx' ])
924
869
return None
925
870
926
871
@property
927
872
def mkdocs (self ):
928
- Mkdocs = namedtuple ( # noqa
929
- 'Mkdocs' ,
930
- ['configuration' , 'fail_on_warning' ],
931
- )
932
873
if self ._config ['mkdocs' ]:
933
874
return Mkdocs (** self ._config ['mkdocs' ])
934
875
return None
@@ -941,10 +882,6 @@ def doctype(self):
941
882
942
883
@property
943
884
def submodules (self ):
944
- Submodules = namedtuple ( # noqa
945
- 'Submodules' ,
946
- ['include' , 'exclude' , 'recursive' ],
947
- )
948
885
return Submodules (** self ._config ['submodules' ])
949
886
950
887
0 commit comments