Skip to content

Commit 79fb969

Browse files
committed
refactor: support non-string paths
1 parent 84c916a commit 79fb969

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

hatch_nodejs_version/version_source.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ def __init__(self, *args, **kwargs):
7979

8080
self.__path = None
8181

82+
@property
83+
def path(self):
84+
if self.__path is None:
85+
version_file = self.config.get("path", "package.json")
86+
if not isinstance(version_file, (str, bytes, os.PathLike)):
87+
raise TypeError(
88+
"Option `path` for version source `{}` must be a string".format(
89+
self.PLUGIN_NAME
90+
)
91+
)
92+
93+
self.__path = os.fspath(version_file)
94+
95+
return self.__path
96+
8297
@staticmethod
8398
def node_version_to_python(version: str) -> str:
8499
# NodeJS version strings are a near superset of Python version strings
@@ -126,21 +141,6 @@ def python_version_to_node(version: str) -> str:
126141
parts.append("+{local}".format_map(match))
127142
return "".join(parts)
128143

129-
@property
130-
def path(self):
131-
if self.__path is None:
132-
version_file = self.config.get("path", "package.json")
133-
if not isinstance(version_file, str):
134-
raise TypeError(
135-
"Option `path` for build hook `{}` must be a string".format(
136-
self.PLUGIN_NAME
137-
)
138-
)
139-
140-
self.__path = version_file
141-
142-
return self.__path
143-
144144
def get_version_data(self):
145145
path = os.path.normpath(os.path.join(self.root, self.path))
146146
if not os.path.isfile(path):

0 commit comments

Comments
 (0)