Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPython Issue with pathlib #1287

Closed
CyrilWaechter opened this issue Jun 24, 2021 · 3 comments
Closed

CPython Issue with pathlib #1287

CyrilWaechter opened this issue Jun 24, 2021 · 3 comments
Labels
Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to Heisenbug Bug that is very hard to find [class] Python 3 Issues related to cpython engines [subsystem]

Comments

@CyrilWaechter
Copy link
Contributor

Describe the bug
There is an issue with CPython engine inside Revit only. It looks like it uses an old version of pathlib where exist_ok did not exist. This feature was apparently introduced in python 3.5.

To Reproduce
Steps to reproduce the behavior:

  1. Create a script containing following code:
#! python3
from pathlib import Path

Path("test").mkdir(parents=True, exist_ok=True)
  1. Execute this script
  2. See error:
CPython Traceback:
TypeError : mkdir() got an unexpected keyword argument 'exist_ok'
 File "<path_to_script_folder>\script.py", line 8, in <module>
Path("test").mkdir(parents=True, exist_ok=True)

pyRevitLabs.PythonNet
à Python.Runtime.Runtime.CheckExceptionOccurred()
 à Python.Runtime.PyScope.Exec(String code, IntPtr _globals, IntPtr _locals)
 à PyRevitLabs.PyRevit.Runtime.CPythonEngine.Execute(ScriptRuntime& runtime)

Expected behavior
This should work like when you run it in the python engine directly:

<path_to_pyRevit>\pyRevit\bin\engines\CPY385 (master -> origin)
λ python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
>>> from pathlib import Path
>>> Path("test").mkdir(parents=True, exist_ok=True)
>>>

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10
  • pyRevit Version: 4.8.8
@CyrilWaechter
Copy link
Contributor Author

I ran:

import pathlib

print(pathlib)

and got:

<module 'pathlib' from '<path_to_pyrevit>\\pyRevit\\site-packages\\pathlib.py'>

This explains why it does not use correct library as the engine ran separately:

<path_to_pyrevit>\pyRevit\bin\engines\CPY385 (master -> origin)
λ python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
>>> import pathlib
>>> pathlib
<module 'pathlib' from '<path_to_pyrevit>\\pyRevit\\bin\\engines\\CPY385\\python38.zip\\pathlib.pyc'>
>>>

@eirannejad
Copy link
Owner

so if you remove the pyRevit\site-packages\pathlib.py then it works? I need to separate these site-packages libraries for IronPython and Cpython

@eirannejad eirannejad added the Python 3 Issues related to cpython engines [subsystem] label Jun 24, 2021
@CyrilWaechter
Copy link
Contributor Author

CyrilWaechter commented Jun 25, 2021

so if you remove the pyRevit\site-packages\pathlib.py then it works? I need to separate these site-packages libraries for IronPython and Cpython

As extension’s lib folder stands before pyrevit sites-packages in sys.path I put pathlib.pyc from pyRevit\\bin\\engines\\CPY385\\python38.zip\\pathlib.pyc in extension’s lib folder but yes it works as it would probably with your suggestion. A solution could be to change sys.path order. I tried to found where all path are appended in pyRevit source code but did not figured all of it out.


import sys; import pprint; pprint.pprint(sys.path)

image


@eirannejad eirannejad changed the title [CPython] Issue with pathlib CPython Issue with pathlib Dec 30, 2021
@eirannejad eirannejad added the Heisenbug Bug that is very hard to find [class] label Dec 30, 2021
@jmcouffin jmcouffin added the Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to Heisenbug Bug that is very hard to find [class] Python 3 Issues related to cpython engines [subsystem]
Projects
None yet
Development

No branches or pull requests

3 participants