Skip to content

Commit 2b23be5

Browse files
cleanup
1 parent 7e134aa commit 2b23be5

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

PySpice/Spice/StringTools.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,32 @@
2828

2929
####################################################################################################
3030

31+
from typing import Any, Iterable
3132
import os
3233

3334
from .unit import str_spice
3435

3536
####################################################################################################
3637

37-
def prefix_lines(items, prefix=''):
38-
return [prefix + str(item)
39-
for item in items
40-
if item is not None] # Fixme: and item
38+
NEWLINE = os.linesep
4139

4240
####################################################################################################
4341

44-
def join_lines(items, prefix=''):
45-
return os.linesep.join(prefix_lines(items, prefix))
42+
def prefix_lines(items: Iterable[Any], prefix: str = '') -> list[str]:
43+
return [
44+
prefix + str(item)
45+
for item in items
46+
if item is not None
47+
] # Fixme: and item
4648

4749
####################################################################################################
4850

49-
def join_list(items):
51+
def join_lines(items: Iterable[Any], prefix: str = '') -> str:
52+
return NEWLINE.join(prefix_lines(items, prefix))
53+
54+
####################################################################################################
55+
56+
def join_list(items: Iterable[Any]) -> str:
5057
# return ' '.join([str_spice(item)
5158
# for item in items
5259
# if item is not None and str_spice(item)])
@@ -68,11 +75,13 @@ def join_list(items):
6875
#
6976
####################################################################################################
7077

71-
def join_dict(d):
78+
def join_dict(d: dict[str, Any]) -> str:
7279
# Fixme: remove trailing _ to key ???
73-
return ' '.join([f'{key}={str_spice(value)}'
74-
for key, value in sorted(d.items())
75-
if value is not None])
80+
return ' '.join([
81+
f'{key}={str_spice(value)}'
82+
for key, value in sorted(d.items())
83+
if value is not None
84+
])
7685

7786
####################################################################################################
7887

PySpice/Tools/PathTools.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,26 @@
2929

3030
####################################################################################################
3131

32-
def find(file_name, directories):
32+
def find(file_name: str, directories: list[str]) -> Path:
3333
# Fixme: bytes ???
34-
if isinstance(directories, bytes):
35-
directories = (directories,)
34+
# on Linux path are bytes, thus some files can be invalid utf8...
35+
# if isinstance(directories, bytes):
36+
# directories = (directories,)
3637
for directory in directories:
37-
for directory_path, _, file_names in os.walk(directory):
38+
directory = Path(directory)
39+
# for directory_path, _, file_names in os.walk(directory):
40+
for directory_path, _, file_names in directory.walk():
41+
directory_path = Path(directory_path)
3842
if file_name in file_names:
39-
return os.path.join(directory_path, file_name)
40-
raise NameError("File %s not found in directories %s" % (file_name, str(directories)))
43+
return directory_path.joinpath(file_name)
44+
raise NameError(f"File {file_name} not found in directories {directories}")
4145

4246
####################################################################################################
4347

44-
def expand_path(path) -> Path:
48+
def expand_path(path: Path | str) -> Path:
49+
# Substrings of the form $name or ${name} are replaced by the value of environment variable name.
50+
# On Unix and Windows, return the argument with an initial component of ~ or ~user
51+
# replaced by that user’s home directory.
4552
_ = os.path.expandvars(path)
4653
return Path(_).expanduser().absolute()
4754

0 commit comments

Comments
 (0)