You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running pytest for test_basic.py on Windows, it returns an error:
==================================================================== test session starts ====================================================================
platform win32 -- Python 3.9.9, pytest-7.1.2, pluggy-1.0.0
rootdir: C:\Users\sygo\Sylvain\Codes\temporary\ontopy2\EMMO-python
collected 2 items
def move(src, dst, copy_function=copy2):
"""Recursively move a file or directory to another location. This is
similar to the Unix "mv" command. Return the file or directory's
destination.
If the destination is a directory or a symlink to a directory, the source
is moved inside the directory. The destination path must not already
exist.
If the destination already exists but is not a directory, it may be
overwritten depending on os.rename() semantics.
If the destination is on our current filesystem, then rename() is used.
Otherwise, src is copied to the destination and then removed. Symlinks are
recreated under the new name if os.rename() fails because of cross
filesystem renames.
The optional `copy_function` argument is a callable that will be used
to copy the source or it will be delegated to `copytree`.
By default, copy2() is used, but any function that supports the same
signature (like copy()) can be used.
A lot more could be done here... A look at a mv.c shows a lot of
the issues this implementation glosses over.
"""
sys.audit("shutil.move", src, dst)
real_dst = dst
if os.path.isdir(dst):
if _samefile(src, dst):
# We might be on a case insensitive filesystem,
# perform the rename anyway.
os.rename(src, dst)
return
# Using _basename instead of os.path.basename is important, as we must
# ignore any trailing slash to avoid the basename returning ''
real_dst = os.path.join(dst, _basename(src))
if os.path.exists(real_dst):
raise Error("Destination path '%s' already exists" % real_dst)
try:
os.rename(src, real_dst)
E FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:\Users\sygo\AppData\Local\Temp\tmpfvrqt25p' -> 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
def copyfile(src, dst, *, follow_symlinks=True):
"""Copy data from src to dst in the most efficient way possible.
If follow_symlinks is not set and src is a symbolic link, a new
symlink will be created instead of copying the file it points to.
"""
sys.audit("shutil.copyfile", src, dst)
if _samefile(src, dst):
raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
file_size = 0
for i, fn in enumerate([src, dst]):
try:
st = _stat(fn)
except OSError:
# File most likely does not exist
pass
else:
# XXX What about other special files? (sockets, devices...)
if stat.S_ISFIFO(st.st_mode):
fn = fn.path if isinstance(fn, os.DirEntry) else fn
raise SpecialFileError("`%s` is a named pipe" % fn)
if _WINDOWS and i == 0:
file_size = st.st_size
if not follow_symlinks and _islink(src):
os.symlink(os.readlink(src), dst)
else:
with open(src, 'rb') as fsrc:
try:
with open(dst, 'wb') as fdst:
E PermissionError: [Errno 13] Permission denied: 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
C:\Python\Python39\lib\shutil.py:266: PermissionError
------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------
*** Prepare graph
*** Run FaCT++ reasoner (and postprocess)
================================================================== short test summary info ==================================================================
FAILED test_basic.py::test_sync_reasoner - PermissionError: [Errno 13] Permission denied: 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
================================================================ 1 failed, 1 passed in 2.18s ================================================================
The text was updated successfully, but these errors were encountered:
Hello EMMO-Python developers,
I posted an issue yesterday, without noticing this issue, however, i think they are related. The issue mentioned is #451, in which the first sub-Issue "temp.NamedTemporaryFile instead of temp.TemporaryDirectory". I hope the extended log file and text in #451 can help you. To explain a possible result in a simple manner, i think that a NamedTemporyFile is created in the OwlApiInterface, while a TemporaryDirectory must be created instead, in order to handle correctly from graph.serialize. The code i used to correct this issue is given below, where the section replaced is "python"-commented in order to see the changes.
with kind regards
Hendrik Borgelt
class OwlApiInterface:
"""Interface to the FaCT++ reasoner via OWLAPI."""
def __init__(self):
"""Initialize the interface."""
def reason(self, graph):
"""Generate the inferred axioms for a given Graph.
Args:
graph (Graph): An rdflib graph to execute the reasoner on.
"""
# with tempfile.NamedTemporaryFile("wt") as tmpdir:
# graph.serialize(tmpdir.name, format="xml")
# return self._run(tmpdir.name, command="--run-reasoner")
with tempfile.TemporaryDirectory("wt") as tmpdir:
graph.serialize(tmpdir, format="xml")
temp_file_name = os.listdir(tmpdir)[0]
temp_file_path = tmpdir + '\\' + temp_file_name # tmpdir.name
return self._run(temp_file_path, command="--run-reasoner")
With master branch commit 02b3c84
When running pytest for test_basic.py on Windows, it returns an error:
==================================================================== test session starts ====================================================================
platform win32 -- Python 3.9.9, pytest-7.1.2, pluggy-1.0.0
rootdir: C:\Users\sygo\Sylvain\Codes\temporary\ontopy2\EMMO-python
collected 2 items
test_basic.py .F [100%]
========================================================================= FAILURES ==========================================================================
____________________________________________________________________ test_sync_reasoner _____________________________________________________________________
src = 'C:\Users\sygo\AppData\Local\Temp\tmpfvrqt25p', dst = 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
copy_function = <function copy2 at 0x000001CC8FCA7790>
E FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:\Users\sygo\AppData\Local\Temp\tmpfvrqt25p' -> 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
C:\Python\Python39\lib\shutil.py:815: FileExistsError
During handling of the above exception, another exception occurred:
testonto = get_ontology("http://emmo.info/testonto#")
test_basic.py:60:
..\ontopy\ontology.py:1073: in sync_reasoner
sync(self, **kwargs)
..\ontopy\factpluspluswrapper\sync_factpp.py:80: in sync_reasoner_factpp
graph2 = FaCTPPGraph(graph1).inferred_graph()
..\ontopy\factpluspluswrapper\factppgraph.py:66: in inferred_graph
self.add_base_annotations()
..\ontopy\factpluspluswrapper\factppgraph.py:76: in add_base_annotations
inferred = self.inferred
..\ontopy\factpluspluswrapper\factppgraph.py:32: in inferred
self._inferred = self.raw_inferred_graph()
..\ontopy\factpluspluswrapper\factppgraph.py:62: in raw_inferred_graph
return OwlApiInterface().reason(self.graph)
..\ontopy\factpluspluswrapper\owlapi_interface.py:34: in reason
graph.serialize(tmpdir.name, format="xml")
C:\Users\sygo\Envs\ontopy2\lib\site-packages\rdflib\graph.py:1210: in serialize
shutil.move(name, dest)
C:\Python\Python39\lib\shutil.py:835: in move
copy_function(src, real_dst)
C:\Python\Python39\lib\shutil.py:444: in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
src = 'C:\Users\sygo\AppData\Local\Temp\tmpfvrqt25p', dst = 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
E PermissionError: [Errno 13] Permission denied: 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
C:\Python\Python39\lib\shutil.py:266: PermissionError
------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------
*** Prepare graph
*** Run FaCT++ reasoner (and postprocess)
================================================================== short test summary info ==================================================================
FAILED test_basic.py::test_sync_reasoner - PermissionError: [Errno 13] Permission denied: 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
================================================================ 1 failed, 1 passed in 2.18s ================================================================
The text was updated successfully, but these errors were encountered: