pyRevit icon indicating copy to clipboard operation
pyRevit copied to clipboard

[Bug]: get_config does not load latest from file

Open onomou opened this issue 4 months ago • 0 comments

✈ Pre-Flight checks

  • [X] I don't have SentinelOne antivirus installed (see above for the solution)
  • [X] I have searched in the issues (open and closed) but couldn't find a similar issue
  • [X] I have searched in the pyRevit Forum for similar issues
  • [X] I already followed the installation troubleshooting guide thoroughly
  • [X] I am using the latest pyRevit Version

🐞 Describe the bug

If get_config has already been called, and then the pyRevit_config.ini file is edited, get_config does not return the latest value from the file. This is true until the engine is reloaded (such as Ctrl + Shift + Alt.

⌨ Error/Debug Message

No error message. The old value is still returned from `get_config`.

♻️ To Reproduce

You can run this in pyRevit or RevitPythonShell.

from pyrevit import script
config = script.get_config('Demo Section')
config.first_var = 42
print('original value:', config.first_var)
script.save_config()

# edit pyRevit_config.ini ## Demo Section
# change first_var to something else
import configparser
cp = configparser.ConfigParser()
import os
config_file = os.path.join(os.getenv('APPDATA'), 'pyRevit', 'pyRevit_config.ini')
cp.read(config_file)
cp['Demo Section']['first_var'] = '12'
with open(config_file, 'w') as file:
    cp.write(file)

# this does not work
config = script.get_config('Demo Section')
print('still old value:', config.first_var) # prints 42

import sys
#del script.user_config
del sys.modules['pyrevit.userconfig']
config = script.get_config('Demo Section')
print('edited value:', config.first_var) # prints new value

⏲️ Expected behavior

The latest data from pyRevit_config.ini will be read and returned.

🖥️ Hardware and Software Setup (please complete the following information)

==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.8.16.24121+2117" | Path: "C:\Users\<redacted>\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "23.1.4" | Engine: IPY340PR (340) | Path: "C:\Users\<redacted>\AppData\Roaming\pyRevit-Master" 
master | Product: "2022.1.5" | Engine: IPY340PR (340) | Path: "C:\Users\<redacted>\AppData\Roaming\pyRevit-Master" 
master | Product: "2021.1.9" | Engine: IPY340PR (340) | Path: "C:\Users\<redacted>\AppData\Roaming\pyRevit-Master" 
==> Installed Extensions
==> Default Extension Search Path
C:\Users\<redacted>\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
==> Extension Sources - Default
https://github.com/pyrevitlabs/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
23.1.4 | Version: 23.1.40.56 | Build: 20240411_0945(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2023\"
2022.1.5 | Version: 22.1.50.17 | Build: 20230915_1530(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
2021.1.9 | Version: 21.1.90.15 | Build: 20230907_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2021\"
==> Running Revit Instances
PID: 51916 | 23.1.4 | Version: 23.1.40.56 | Build: 20240411_0945(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2023"
==> User Environment
Microsoft Windows 10 [Version 10.0.22631]
Executing User: <redacted>\<redacted>
Active User: <redacted>\<redacted>
Admin Access: No
%APPDATA%: "C:\Users\<redacted>\AppData\Roaming"
Latest Installed .Net Framework: 4.8
Installed .Net Target Packs: v4.0 v4.5 v4.5.1 v4.5.2 v4.6 v4.6.1 v4.7 v4.7.1 v4.7.2 v4.8 v4.X 
Installed .Net-Core Target Packs: v8.0.400 
pyRevit CLI v4.8.16.24121+2117.23a0b8cbc4babdeb29a0611e159d017bbe9cbad5

Additional context

A workaround is presented in the To Reproduce section. I posted about it here: Reload required on script update?

onomou avatar Oct 03 '24 16:10 onomou