Skip to content

Commit

Permalink
Java classpath separator should be ';' on Windows
Browse files Browse the repository at this point in the history
See https://stackoverflow.com/a/60211688 for an explanation of this. Fixes #31.
  • Loading branch information
dlenski committed Jan 9, 2024
1 parent ec5bcfb commit 178c50b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions zxing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pathlib
import re
import subprocess as sp
import sys
import urllib.parse
import zipfile
from enum import Enum
Expand Down Expand Up @@ -41,18 +42,19 @@ def __init__(self, message, filename=None):

class BarCodeReader(object):
cls = "com.google.zxing.client.j2se.CommandLineRunner"
classpath_sep = ';' if sys.platform == 'nt' else ':' # https://stackoverflow.com/a/60211688

def __init__(self, classpath=None, java=None):
self.java = java or 'java'
self.zxing_version = self.zxing_version_info = None
if classpath:
self.classpath = classpath if isinstance(classpath, str) else ':'.join(classpath)
self.classpath = classpath if isinstance(classpath, str) else self.classpath_sep.join(classpath)
elif "ZXING_CLASSPATH" in os.environ:
self.classpath = os.environ.get("ZXING_CLASSPATH", "")
else:
self.classpath = os.path.join(os.path.dirname(__file__), 'java', '*')

for fn in chain.from_iterable(glob.glob(cp) for cp in self.classpath.split(':')):
for fn in chain.from_iterable(glob.glob(cp) for cp in self.classpath.split(self.classpath_sep)):
if os.path.basename(fn) == 'core.jar':
self.core_jar = fn
with zipfile.ZipFile(self.core_jar) as c:
Expand Down

0 comments on commit 178c50b

Please sign in to comment.