Skip to content

Use f-strings to format text and double quotes for strings#126

Merged
tdcmeehan merged 1 commit into
prestodb:masterfrom
dnskr:f-strings
Jan 15, 2026
Merged

Use f-strings to format text and double quotes for strings#126
tdcmeehan merged 1 commit into
prestodb:masterfrom
dnskr:f-strings

Conversation

@dnskr
Copy link
Copy Markdown

@dnskr dnskr commented Sep 20, 2025

Changes

  • The PR replaces the modulo operator (%) with f-strings to format text in a more readable way.
  • The PR replaces all single quotes with double quotes for strings to ensure consistency.

Details

F-strings are the preferred text formatting option introduced in Python 3.6, so migrating to f-strings will drop support for Python 2 and Python < 3.6. However, this should not be a problem, since Python 2.7 reached EOL in 2020 and Python 3.6 reached EOL in 2021 (see Status of Python versions).

Testing

The PR tested by replacing existing launcher.py in Presto installation.

> presto-server start
Started as 59493
> presto-server start
Already running as 59493
> presto-server restart
Stopped 59493
Started as 59528
> presto-server status
Running as 59528
> presto-server kill
Killed 59528
> presto-server status
Not running
> presto-server -D test=true -v status
arguments       = []
config_path     = /usr/local/Cellar/prestodb/0.293/libexec/etc/config.properties
data_dir        = /usr/local/var/presto/data
etc_dir         = /usr/local/Cellar/prestodb/0.293/libexec/etc
install_path    = /usr/local/Cellar/prestodb/0.293/libexec
jvm_config      = /usr/local/Cellar/prestodb/0.293/libexec/etc/jvm.config
launcher_config = /usr/local/Cellar/prestodb/0.293/libexec/bin/launcher.properties
launcher_log    = /usr/local/var/presto/data/var/log/launcher.log
log_levels      = /usr/local/Cellar/prestodb/0.293/libexec/etc/log.properties
log_levels_set  = False
node_config     = /usr/local/Cellar/prestodb/0.293/libexec/etc/node.properties
pid_file        = /usr/local/var/presto/data/var/run/launcher.pid
properties      = {'test': 'true', 'node.environment': 'production', 'node.id': 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'node.data-dir': '/usr/local/var/presto/data'}
server_log      = /usr/local/var/presto/data/var/log/server.log
verbose         = True

Not running

@dnskr dnskr requested a review from a team as a code owner September 20, 2025 10:46
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Sep 20, 2025

Reviewer's Guide

This PR refactors the launcher script by migrating all legacy ’%’-based string formatting to f-strings and unifying every string literal to use double quotes for consistency.

File-Level Changes

Change Details Files
Migrate legacy %-formatting to f-strings
  • Replace exception message constructions with f-strings
  • Convert print statements to use f-strings
  • Refactor list comprehensions and other formatting expressions to f-strings
launcher/src/main/scripts/bin/launcher.py
Standardize string literals to double quotes
  • Switch all single-quoted literals (including docstrings and comments) to double-quoted
  • Update ArgumentParser definitions and help texts to use double quotes
launcher/src/main/scripts/bin/launcher.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Update project metadata, CI configs, and documentation to reflect the new minimum Python 3.6 requirement after migrating to f-strings.
  • Consider using context managers (with open(...)) for file I/O to ensure file handles are closed properly instead of bare open().
  • To reduce manual churn and enforce consistent quoting, consider adopting an automated formatter like Black to normalize string quotes and formatting.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Update project metadata, CI configs, and documentation to reflect the new minimum Python 3.6 requirement after migrating to f-strings.
- Consider using context managers (with open(...)) for file I/O to ensure file handles are closed properly instead of bare open().
- To reduce manual churn and enforce consistent quoting, consider adopting an automated formatter like Black to normalize string quotes and formatting.

## Individual Comments

### Comment 1
<location> `launcher/src/main/scripts/bin/launcher.py:405` </location>
<code_context>
     args = parser.parse_args()

-    if 'command' not in args:
+    if "command" not in args:
         parser.print_help()
         sys.exit()
</code_context>

<issue_to_address>
**issue (bug_risk):** Checking for 'command' in args may not work as expected with argparse.Namespace.

Since args is an argparse.Namespace, use 'hasattr(args, "command")' or 'getattr(args, "command", None)' to check for the attribute instead.
</issue_to_address>

### Comment 2
<location> `launcher/src/main/scripts/bin/launcher.py:440` </location>
<code_context>
+    options.launcher_log = realpath(args.launcher_log_file or pathjoin(options.data_dir, "var/log/launcher.log"))
+    options.server_log = realpath(args.server_log_file or pathjoin(options.data_dir, "var/log/server.log"))

     options.properties = parse_properties(parser, args.properties or {})
     for k, v in node_properties.items():
</code_context>

<issue_to_address>
**issue (bug_risk):** Passing an empty dict to parse_properties may cause issues.

Use 'args.properties or []' to ensure parse_properties always receives a list, preventing unexpected behavior.
</issue_to_address>

### Comment 3
<location> `launcher/src/main/scripts/bin/launcher.py:25` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 4
<location> `launcher/src/main/scripts/bin/launcher.py:28` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 5
<location> `launcher/src/main/scripts/bin/launcher.py:104` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 6
<location> `launcher/src/main/scripts/bin/launcher.py:111` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 7
<location> `launcher/src/main/scripts/bin/launcher.py:116` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 8
<location> `launcher/src/main/scripts/bin/launcher.py:118` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 9
<location> `launcher/src/main/scripts/bin/launcher.py:146` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 10
<location> `launcher/src/main/scripts/bin/launcher.py:182` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 11
<location> `launcher/src/main/scripts/bin/launcher.py:184` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 12
<location> `launcher/src/main/scripts/bin/launcher.py:186` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 13
<location> `launcher/src/main/scripts/bin/launcher.py:188` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 14
<location> `launcher/src/main/scripts/bin/launcher.py:302` </location>
<code_context>

</code_context>

<issue_to_address>
**issue (code-quality):** Raise a specific error instead of the general `Exception` or `BaseException` ([`raise-specific-error`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/raise-specific-error))

<details><summary>Explanation</summary>If a piece of code raises a specific exception type
rather than the generic
[`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException)
or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception),
the calling code can:

- get more information about what type of error it is
- define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

- Use one of the [built-in exceptions](https://docs.python.org/3/library/exceptions.html) of the standard library.
- [Define your own error class](https://docs.python.org/3/tutorial/errors.html#tut-userexceptions) that subclasses `Exception`.

So instead of having code raising `Exception` or `BaseException` like

```python
if incorrect_input(value):
    raise Exception("The input is incorrect")
```

you can have code raising a specific error like

```python
if incorrect_input(value):
    raise ValueError("The input is incorrect")
```

or

```python
class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")
```
</details>
</issue_to_address>

### Comment 15
<location> `launcher/src/main/scripts/bin/launcher.py:53` </location>
<code_context>
def load_lines(f):
    """Load lines from a file, ignoring blank or comment lines"""
    lines = []
    for line in open(f, "r").readlines():
        line = line.strip()
        if len(line) > 0 and not line.startswith("#"):
            lines.append(line)
    return lines

</code_context>

<issue_to_address>
**suggestion (code-quality):** Iterate over files directly rather than using readlines() ([`use-file-iterator`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/use-file-iterator/))

```suggestion
    for line in open(f, "r"):
```
</issue_to_address>

### Comment 16
<location> `launcher/src/main/scripts/bin/launcher.py:104` </location>
<code_context>
    def alive(self):
        self.refresh()
        if self.locked:
            return False

        pid = self.read_pid()
        try:
            os.kill(pid, 0)
            return True
        except OSError as e:
            raise Exception(f"Signaling pid {pid} failed: {e}")

</code_context>

<issue_to_address>
**suggestion (code-quality):** Explicitly raise from a previous error ([`raise-from-previous-error`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/raise-from-previous-error/))

```suggestion
            raise Exception(f"Signaling pid {pid} failed: {e}") from e
```
</issue_to_address>

### Comment 17
<location> `launcher/src/main/scripts/bin/launcher.py:115-116` </location>
<code_context>
    def read_pid(self):
        assert not self.locked, "pid file is locked by us"
        self.pid_file.seek(0)
        line = self.pid_file.readline().strip()
        if len(line) == 0:
            raise Exception(f"Pid file '{self.path}' is empty")

        try:
            pid = int(line)
        except ValueError:
            raise Exception(f"Pid file '{self.path}' contains garbage: {line}")
        if pid <= 0:
            raise Exception(f"Pid file '{self.path}' contains an invalid pid: {pid}")
        return pid

</code_context>

<issue_to_address>
**suggestion (code-quality):** Explicitly raise from a previous error ([`raise-from-previous-error`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/raise-from-previous-error/))

```suggestion
        except ValueError as e:
            raise Exception(f"Pid file '{self.path}' contains garbage: {line}") from e
```
</issue_to_address>

### Comment 18
<location> `launcher/src/main/scripts/bin/launcher.py:202` </location>
<code_context>
def build_java_execution(options, daemon):
    if not exists(options.config_path):
        raise Exception(f"Config file is missing: {options.config_path}")
    if not exists(options.jvm_config):
        raise Exception(f"JVM config file is missing: {options.jvm_config}")
    if not exists(options.launcher_config):
        raise Exception(f"Launcher config file is missing: {options.launcher_config}")
    if options.log_levels_set and not exists(options.log_levels):
        raise Exception(f"Log levels file is missing: {options.log_levels}")

    properties = options.properties.copy()

    if exists(options.log_levels):
        properties["log.levels-file"] = options.log_levels

    if daemon:
        properties["log.path"] = options.server_log
        properties["log.enable-console"] = "false"

    jvm_properties = load_lines(options.jvm_config)
    launcher_properties = load_properties(options.launcher_config)

    try:
        main_class = launcher_properties["main-class"]
    except KeyError:
        raise Exception("Launcher config is missing 'main-class' property")

    properties["config"] = options.config_path

    system_properties = [f"-D{key}={value}" for key, value in properties.items()]
    classpath = pathjoin(options.install_path, "lib", "*")

    java_binary_prefix = ""
    if os.getenv("JAVA_HOME"):
        java_binary_prefix = os.getenv("JAVA_HOME") + "/bin/"
    command = [java_binary_prefix + "java", "-cp", classpath]
    command += jvm_properties + system_properties
    command += [main_class]
    command += options.arguments

    if options.verbose:
        print(command)
        print("")

    env = os.environ.copy()

    # set process name: https://github.com/electrum/procname
    process_name = launcher_properties.get("process-name", "")
    if len(process_name) > 0:
        system = platform.system() + "-" + platform.machine()
        shim = pathjoin(options.install_path, "bin", "procname", system, "libprocname.so")
        if exists(shim):
            env["LD_PRELOAD"] = (env.get("LD_PRELOAD", "") + ":" + shim).strip()
            env["PROCNAME"] = process_name

    return command, env

</code_context>

<issue_to_address>
**issue (code-quality):** We've found these issues:

- Use f-string instead of string concatenation [×3] ([`use-fstring-for-concatenation`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/use-fstring-for-concatenation/))
- Explicitly raise from a previous error ([`raise-from-previous-error`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/raise-from-previous-error/))
</issue_to_address>

### Comment 19
<location> `launcher/src/main/scripts/bin/launcher.py:302` </location>
<code_context>
def _terminate(process, signal, message):
    if not process.alive():
        print("Not running")
        return

    pid = process.read_pid()

    while True:
        try:
            os.kill(pid, signal)
        except OSError as e:
            if e.errno != errno.ESRCH:
                raise Exception(f"Signaling pid {pid} failed: {e}")

        if not process.alive():
            process.clear_pid()
            break

        sleep(0.1)

    print(f"{message} {pid}")

</code_context>

<issue_to_address>
**suggestion (code-quality):** Explicitly raise from a previous error ([`raise-from-previous-error`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/raise-from-previous-error/))

```suggestion
                raise Exception(f"Signaling pid {pid} failed: {e}") from e
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
Comment thread launcher/src/main/scripts/bin/launcher.py
@tdcmeehan tdcmeehan self-assigned this Sep 20, 2025
@tdcmeehan
Copy link
Copy Markdown

Thanks @dnskr

@tdcmeehan tdcmeehan merged commit a6f50dd into prestodb:master Jan 15, 2026
3 checks passed
@NikhilCollooru
Copy link
Copy Markdown

@dnskr i am getting unit test failures when trying to use the new airlift version
prestodb/presto#27070

I see syntax error
Screenshot 2026-02-08 at 12 33 12 AM

can you please help look into it ?

@dnskr
Copy link
Copy Markdown
Author

dnskr commented Feb 8, 2026

@NikhilCollooru The cause is likely that the ubuntu-latest image (Ubuntu 22.04 LTS) is utilizing Python 2.7 to execute launcher.py. This can be fixed by updating the reference(

) to Python 3 or deleting the line entirely, as Python 3 should be the default. I’ll take a closer look on Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants