@@ -1559,7 +1559,15 @@ 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 ,
1564
+ section_name ,
1565
+ cfgparser ,
1566
+ fallbacksections = None ,
1567
+ factors = (),
1568
+ prefix = None ,
1569
+ posargs = "" ,
1570
+ ):
1563
1571
if prefix is None :
1564
1572
self .section_name = section_name
1565
1573
else :
@@ -1570,6 +1578,7 @@ def __init__(self, section_name, cfgparser, fallbacksections=None, factors=(), p
1570
1578
self ._subs = {}
1571
1579
self ._subststack = []
1572
1580
self ._setenv = None
1581
+ self .posargs = posargs
1573
1582
1574
1583
def get_environ_value (self , name ):
1575
1584
if self ._setenv is None :
@@ -1695,6 +1704,17 @@ def getstring(self, name, default=None, replace=True, crossonly=False, no_fallba
1695
1704
x = self ._replace_if_needed (x , name , replace , crossonly )
1696
1705
return x
1697
1706
1707
+ def getposargs (self , default = None ):
1708
+ if self .posargs :
1709
+ posargs = self .posargs
1710
+ if sys .platform .startswith ("win" ):
1711
+ posargs_string = list2cmdline ([x for x in posargs if x ])
1712
+ else :
1713
+ posargs_string = " " .join ([shlex_quote (x ) for x in posargs if x ])
1714
+ return posargs_string
1715
+ else :
1716
+ return default or ""
1717
+
1698
1718
def _replace_if_needed (self , x , name , replace , crossonly ):
1699
1719
if replace and x and hasattr (x , "replace" ):
1700
1720
x = self ._replace (x , name = name , crossonly = crossonly )
@@ -1781,6 +1801,9 @@ def _replace_match(self, match):
1781
1801
if not any (g .values ()):
1782
1802
return os .pathsep
1783
1803
1804
+ if sub_value == "posargs" :
1805
+ return self .reader .getposargs (match .group ("default_value" ))
1806
+
1784
1807
try :
1785
1808
sub_type = g ["sub_type" ]
1786
1809
except KeyError :
@@ -1794,6 +1817,8 @@ def _replace_match(self, match):
1794
1817
if is_interactive ():
1795
1818
return match .group ("substitution_value" )
1796
1819
return match .group ("default_value" )
1820
+ if sub_type == "posargs" :
1821
+ return self .reader .getposargs (match .group ("substitution_value" ))
1797
1822
if sub_type is not None :
1798
1823
raise tox .exception .ConfigError (
1799
1824
"No support for the {} substitution type" .format (sub_type ),
@@ -1887,28 +1912,17 @@ def getargvlist(cls, reader, value, replace=True):
1887
1912
1888
1913
@classmethod
1889
1914
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
1915
# Iterate through each word of the command substituting as
1897
1916
# appropriate to construct the new command string. This
1898
1917
# string is then broken up into exec argv components using
1899
1918
# shlex.
1900
1919
if replace :
1901
1920
newcommand = ""
1902
1921
for word in CommandParser (command ).words ():
1903
- if word == "{posargs}" or word == " []" :
1904
- newcommand += posargs_string
1922
+ if word == "[]" :
1923
+ newcommand += reader . getposargs ()
1905
1924
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 ]
1925
+
1912
1926
new_arg = ""
1913
1927
new_word = reader ._replace (word )
1914
1928
new_word = reader ._replace (new_word )
0 commit comments