Skip to content

Commit 91d8c74

Browse files
committed
mitoge/parent: Refactor _get_source_first_stage
Add comments so it's clearer what is meant with. -mitogen.parent 99212 96.9KiB 51385 50.2KiB 51.8% 12999 12.7KiB 13.1% +mitogen.parent 99532 97.2KiB 51483 50.3KiB 51.7% 13033 12.7KiB 13.1% Signed-off-by: Marc Hartmayer <[email protected]>
1 parent 57a5ec7 commit 91d8c74

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mitogen/parent.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,10 +1478,16 @@ def get_python_argv(self):
14781478
return self.options.python_path
14791479
return [self.options.python_path]
14801480

1481+
def _get_source_first_stage(self):
1482+
# Remove the staticmethod decorator and the function name. If we ever
1483+
# add a docstring to `_first_stage` we need to change this.
1484+
source = inspect.getsourcelines(self._first_stage)[0][2:]
1485+
# Remove line comments, leading indentation, trailing newline
1486+
source = textwrap.dedent(''.join(s for s in source if '#' not in s))[:-1]
1487+
return source.replace(' ', ' ')
1488+
14811489
def get_boot_command(self):
1482-
source = inspect.getsource(self._first_stage)
1483-
source = textwrap.dedent('\n'.join(source.strip().split('\n')[2:]))
1484-
source = source.replace(' ', ' ')
1490+
source = self._get_source_first_stage()
14851491
compressor = zlib.compressobj(
14861492
zlib.Z_BEST_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS,
14871493
)

0 commit comments

Comments
 (0)