@@ -1559,7 +1559,9 @@ def __repr__(self):
1559
1559
1560
1560
1561
1561
class SectionReader :
1562
- def __init__ (self , section_name , cfgparser , fallbacksections = None , factors = (), prefix = None ):
1562
+ def __init__ (
1563
+ self , section_name , cfgparser , fallbacksections = None , factors = (), prefix = None , posargs = ""
1564
+ ):
1563
1565
if prefix is None :
1564
1566
self .section_name = section_name
1565
1567
else :
@@ -1570,6 +1572,7 @@ def __init__(self, section_name, cfgparser, fallbacksections=None, factors=(), p
1570
1572
self ._subs = {}
1571
1573
self ._subststack = []
1572
1574
self ._setenv = None
1575
+ self .posargs = posargs
1573
1576
1574
1577
def get_environ_value (self , name ):
1575
1578
if self ._setenv is None :
@@ -1695,6 +1698,17 @@ def getstring(self, name, default=None, replace=True, crossonly=False, no_fallba
1695
1698
x = self ._replace_if_needed (x , name , replace , crossonly )
1696
1699
return x
1697
1700
1701
+ def getposargs (self , default = None ):
1702
+ if self .posargs :
1703
+ posargs = self .posargs
1704
+ if sys .platform .startswith ("win" ):
1705
+ posargs_string = list2cmdline ([x for x in posargs if x ])
1706
+ else :
1707
+ posargs_string = " " .join ([shlex_quote (x ) for x in posargs if x ])
1708
+ return posargs_string
1709
+ else :
1710
+ return default or ""
1711
+
1698
1712
def _replace_if_needed (self , x , name , replace , crossonly ):
1699
1713
if replace and x and hasattr (x , "replace" ):
1700
1714
x = self ._replace (x , name = name , crossonly = crossonly )
@@ -1781,6 +1795,9 @@ def _replace_match(self, match):
1781
1795
if not any (g .values ()):
1782
1796
return os .pathsep
1783
1797
1798
+ if sub_value == "posargs" :
1799
+ return self .reader .getposargs (match .group ("default_value" ))
1800
+
1784
1801
try :
1785
1802
sub_type = g ["sub_type" ]
1786
1803
except KeyError :
@@ -1794,6 +1811,8 @@ def _replace_match(self, match):
1794
1811
if is_interactive ():
1795
1812
return match .group ("substitution_value" )
1796
1813
return match .group ("default_value" )
1814
+ if sub_type == "posargs" :
1815
+ return self .reader .getposargs (match .group ("substitution_value" ))
1797
1816
if sub_type is not None :
1798
1817
raise tox .exception .ConfigError (
1799
1818
"No support for the {} substitution type" .format (sub_type ),
@@ -1887,28 +1906,17 @@ def getargvlist(cls, reader, value, replace=True):
1887
1906
1888
1907
@classmethod
1889
1908
def processcommand (cls , reader , command , replace = True ):
1890
- posargs = getattr (reader , "posargs" , "" )
1891
- if sys .platform .startswith ("win" ):
1892
- posargs_string = list2cmdline ([x for x in posargs if x ])
1893
- else :
1894
- posargs_string = " " .join ([shlex_quote (x ) for x in posargs if x ])
1895
-
1896
1909
# Iterate through each word of the command substituting as
1897
1910
# appropriate to construct the new command string. This
1898
1911
# string is then broken up into exec argv components using
1899
1912
# shlex.
1900
1913
if replace :
1901
1914
newcommand = ""
1902
1915
for word in CommandParser (command ).words ():
1903
- if word == "{posargs}" or word == " []" :
1904
- newcommand += posargs_string
1916
+ if word == "[]" :
1917
+ newcommand += reader . getposargs ()
1905
1918
continue
1906
- elif word .startswith ("{posargs:" ) and word .endswith ("}" ):
1907
- if posargs :
1908
- newcommand += posargs_string
1909
- continue
1910
- else :
1911
- word = word [9 :- 1 ]
1919
+
1912
1920
new_arg = ""
1913
1921
new_word = reader ._replace (word )
1914
1922
new_word = reader ._replace (new_word )
0 commit comments