Skip to content

Commit 0d79f78

Browse files
committed
Attempt to fix path issues on Windows
1 parent c1c35e7 commit 0d79f78

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

pyfpga/project.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2019-2024 PyFPGA Project
2+
# Copyright (C) 2019-2025 PyFPGA Project
33
#
44
# SPDX-License-Identifier: GPL-3.0-or-later
55
#
@@ -73,17 +73,17 @@ def add_include(self, path):
7373
:raises NotADirectoryError: if path is not a directory
7474
"""
7575
self.logger.debug('Executing add_include: %s', path)
76-
path = Path(path).resolve()
77-
if not path.is_dir():
76+
path = self._get_absolute(path, self.conf['make_ext'])
77+
if not Path(path).is_dir():
7878
raise NotADirectoryError(path)
79-
self.data.setdefault('includes', []).append(path.as_posix())
79+
self.data.setdefault('includes', []).append(path)
8080

8181
def _add_file(self, pathname, hdl=None, lib=None):
8282
files = glob.glob(pathname, recursive=True)
8383
if len(files) == 0:
8484
raise FileNotFoundError(pathname)
8585
for file in files:
86-
path = Path(file).resolve().as_posix()
86+
path = self._get_absolute(file, self.conf['make_ext'])
8787
attr = {}
8888
if hdl:
8989
attr['hdl'] = hdl
@@ -134,11 +134,11 @@ def add_cons(self, path):
134134
:raises FileNotFoundError: if path is not found
135135
"""
136136
self.logger.debug('Executing add_cons: %s', path)
137-
path = Path(path).resolve()
138-
if not path.is_file():
137+
path = self._get_absolute(path, self.conf['make_ext'])
138+
if not Path(path).is_file():
139139
raise FileNotFoundError(path)
140140
attr = {}
141-
self.data.setdefault('constraints', {})[path.as_posix()] = attr
141+
self.data.setdefault('constraints', {})[path] = attr
142142

143143
def add_param(self, name, value):
144144
"""Add a Parameter/Generic Value.
@@ -170,7 +170,7 @@ def add_fileset(self, pathname):
170170
:raises FileNotFoundError: when pathname is not found
171171
"""
172172
self.logger.debug('Executing add_fileset: %s', pathname)
173-
if not os.path.exists(pathname):
173+
if not Path(pathname).is_file():
174174
raise FileNotFoundError(pathname)
175175
raise NotImplementedError()
176176

@@ -255,13 +255,12 @@ def prog(self, bitstream=None, position=1):
255255
if not bitstream:
256256
for ext in self.conf['prog_bit']:
257257
candidate = Path(self.odir) / f'{self.data["project"]}.{ext}'
258-
if candidate.exists():
259-
bitstream = candidate.resolve()
258+
if candidate.is_file():
259+
bitstream = candidate
260260
break
261-
else:
262-
bitstream = Path(bitstream).resolve()
263-
if not bitstream or not bitstream.exists():
261+
if not bitstream or not Path(bitstream).is_file():
264262
raise FileNotFoundError(bitstream)
263+
bitstream = self._get_absolute(bitstream, self.conf['prog_ext'])
265264
self.data['bitstream'] = bitstream
266265
self._prog_custom()
267266
self._create_file(f'{self.conf["tool"]}-prog', self.conf['prog_ext'])
@@ -322,3 +321,11 @@ def _run(self, command, logname):
322321
)
323322
if error:
324323
raise RuntimeError('Problem with the underlying tool')
324+
325+
@staticmethod
326+
def _get_absolute(path, ext):
327+
path = Path(path).resolve()
328+
if ext == 'tcl':
329+
return path.as_posix()
330+
else:
331+
return path

0 commit comments

Comments
 (0)