Skip to content

Commit

Permalink
Minor jnius_config.py refactors
Browse files Browse the repository at this point in the history
Simple `check_vm_running()` for a single source of truth, refs:
#502 (review)
  • Loading branch information
AndreMiras committed May 2, 2020
1 parent 088fa1a commit 2942576
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions jnius_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,28 @@
classpath = None


def set_options(*opts):
"Sets the list of options to the JVM. Removes any previously set options."
def check_vm_running():
"""Raises a ValueError if the VM is already running."""
if vm_running:
raise ValueError("VM is already running, can't set options; VM started at" + vm_started_at)
raise ValueError("VM is already running, can't set classpath/options; VM started at" + vm_started_at)


def set_options(*opts):
"""Sets the list of options to the JVM. Removes any previously set options."""
check_vm_running()
global options
options = list(opts)


def add_options(*opts):
"Appends options to the list of VM options."
if vm_running:
raise ValueError("VM is already running, can't set options; VM started at" + vm_started_at)
"""Appends options to the list of VM options."""
check_vm_running()
global options
options.extend(opts)


def get_options():
"Retrieves the current list of VM options."
"""Retrieves the current list of VM options."""
global options
return list(options)

Expand All @@ -40,8 +44,7 @@ def set_classpath(*path):
"""
Sets the classpath for the JVM to use. Replaces any existing classpath, overriding the CLASSPATH environment variable.
"""
if vm_running:
raise ValueError("VM is already running, can't set classpath; VM started at" + vm_started_at)
check_vm_running()
global classpath
classpath = list(path)

Expand All @@ -51,8 +54,7 @@ def add_classpath(*path):
Appends items to the classpath for the JVM to use.
Replaces any existing classpath, overriding the CLASSPATH environment variable.
"""
if vm_running:
raise ValueError("VM is already running, can't set classpath; VM started at" + vm_started_at)
check_vm_running()
global classpath
if classpath is None:
classpath = list(path)
Expand Down

0 comments on commit 2942576

Please sign in to comment.