Keep explicit newlines with help texts
This makes a difference for e.g. pytest-xdist:
Before:
```
  --dist=distmode       set mode for distributing tests to exec environments. each: …
                        available environment. loadscope: …
                        grouped by file to any available environment. (default) no: …
```
After:
```
  --dist=distmode       set mode for distributing tests to exec environments.
                        each: send each test to all available environments.
                        load: load balance by sending any pending test to any available environment.
                        …
                        (default) no: run tests inprocess, don't distribute.
```
This might also result in unexpected changes (hard wrapping), when line
endings where used unintentionally, e.g. with:
```
help="""
    some long
    help text
    """
```
But the benefits from that are worth it, and it is easy to fix, as will
be done for the internal `assertmode` option.
			
			
This commit is contained in:
		
							parent
							
								
									d05ef61e95
								
							
						
					
					
						commit
						87423d3cc8
					
				| 
						 | 
				
			
			@ -509,3 +509,15 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
 | 
			
		|||
        formatted_action_invocation = ", ".join(return_list)
 | 
			
		||||
        action._formatted_action_invocation = formatted_action_invocation  # type: ignore
 | 
			
		||||
        return formatted_action_invocation
 | 
			
		||||
 | 
			
		||||
    def _split_lines(self, text, width):
 | 
			
		||||
        """Wrap lines after splitting on original newlines.
 | 
			
		||||
 | 
			
		||||
        This allows to have explicit line breaks in the help text.
 | 
			
		||||
        """
 | 
			
		||||
        import textwrap
 | 
			
		||||
 | 
			
		||||
        lines = []
 | 
			
		||||
        for line in text.splitlines():
 | 
			
		||||
            lines.extend(textwrap.wrap(line.strip(), width))
 | 
			
		||||
        return lines
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue