Skip to content

Fix: Create config directory before writing#2757

Merged
jmcouffin merged 3 commits intopyrevitlabs:developfrom
jmcouffin:fix-config-file-creation
Aug 18, 2025
Merged

Fix: Create config directory before writing#2757
jmcouffin merged 3 commits intopyrevitlabs:developfrom
jmcouffin:fix-config-file-creation

Conversation

@jmcouffin
Copy link
Copy Markdown
Contributor

Ensures the destination directory exists before writing the config file.

When setting up the user config file from a template, the code did not ensure that the destination directory existed before attempting to write the file. This would cause an error if the directory did not exist, which is the case for a new user.

This change adds a call to CommonUtils.EnsurePath to create the directory if it does not exist.

Trying to fix #2595

Ensures the destination directory exists before writing the config file.

When setting up the user config file from a template, the code did not
ensure that the destination directory existed before attempting to write
the file. This would cause an error if the directory did not exist,
which is the case for a new user.

This change adds a call to `CommonUtils.EnsurePath` to create the
directory if it does not exist.
@jmcouffin jmcouffin requested a review from Copilot August 18, 2025 15:33
@jmcouffin jmcouffin added Installer Issues related to the pyRevit installer [subsystem] Command Line Utility (CLI) Issues related to pyRevit CLI tool [subsystem] labels Aug 18, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where pyRevit would fail to create a user configuration file for new users because the destination directory might not exist. The fix ensures the configuration directory is created before attempting to write the config file.

Key Changes

  • Added a directory creation check before writing the configuration file
  • Prevents errors when setting up config files for new users who don't have the config directory yet

Copy link
Copy Markdown
Contributor

@devloai devloai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary:

This PR fixes a bug where pyRevit fails to create user config files for new users. The issue occurs when the destination directory doesn't exist in %AppData%\pyRevit\. The fix adds a single line to ensure the directory exists before writing the config file.

Review Summary:

The fix is well-targeted and correctly addresses the reported issue #2595. The solution uses the existing CommonUtils.EnsurePath method, which is the appropriate utility for ensuring directory existence before file operations. The change is minimal, defensive, and follows established patterns in the codebase. No critical issues were identified.

Follow-up suggestions:

  • @devloai consider creating a unit test to verify config file creation works correctly when the destination directory doesn't exist

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jmcouffin jmcouffin merged commit aaccfbe into pyrevitlabs:develop Aug 18, 2025
@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25230+1701-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25232+0824-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25232+0848-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25232+0859-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25232+1126-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25232+1352-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25233+0639-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25233+1431-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25233+1438-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25237+0821-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25237+0841-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25237+1124-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25237+1535-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25237+1604-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25238+0615-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25240+1356-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25240+1743-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25243+1636-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25243+1639-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25268+1757-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1336-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1431-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1436-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1822-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25271+1719-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2003-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2012-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2017-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2149-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 1, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25274+1734-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 4, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25277+1425-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 4, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25277+1427-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 6, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25279+2157-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25280+0218-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25280+1054-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25280+1057-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 9, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25282+1656-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25283+0140-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25286+1022-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25287+0905-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25287+1000-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25288+0613-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25293+0755-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25293+0828-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25293+1113-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25293+1234-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25295+0707-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25296+0824-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25302+0949-wip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Command Line Utility (CLI) Issues related to pyRevit CLI tool [subsystem] Installer Issues related to the pyRevit installer [subsystem]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Errors in all versions of Revit except 2025

2 participants