cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
941 stars 103 forks source link

AttributeError in ctest-to: ‘dict’ object has no attribute ‘parse_db’ #344

Open hanexthink opened 1 month ago

hanexthink commented 1 month ago

I encountered an AttributeError while running the ctest-to command. The error message indicates that a dictionary object is being accessed for an attribute parse_db, which does not exist. Below are the details of the traceback:

Traceback (most recent call last): File "/Users/hossein.afshari/.pyenv/versions/vdsql/bin/ctest-to", line 8, in <module> sys.exit(main()) ^^^^^^ File "/Users/hossein.afshari/.pyenv/versions/vdsql/lib/python3.11/site-packages/cmakelang/ctest_to.py", line 253, in main ctx.start(args.directory) File "/Users/hossein.afshari/.pyenv/versions/vdsql/lib/python3.11/site-packages/cmakelang/ctest_to.py", line 216, in start self.parse_file(os.path.join(self.cwd, "CTestTestfile.cmake")) File "/Users/hossein.afshari/.pyenv/versions/vdsql/lib/python3.11/site-packages/cmakelang/ctest_to.py", line 206, in parse_file _ = parse.parse(tokens, self.get_db()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hossein.afshari/.pyenv/versions/vdsql/lib/python3.11/site-packages/cmakelang/parse/__init__.py", line 68, in parse return BodyNode.consume(ctx, tokens) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hossein.afshari/.pyenv/versions/vdsql/lib/python3.11/site-packages/cmakelang/parse/body_nodes.py", line 67, in consume subtree = StatementNode.consume(ctx, tokens) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hossein.afshari/.pyenv/versions/vdsql/lib/python3.11/site-packages/cmakelang/parse/statement_node.py", line 80, in consume parse_fun = ctx.parse_db.get(fnname, None) ^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'parse_db'

Steps to Reproduce

1.  Run the ctest-to command in the specified environment.

Environment

•   OS: macOS
•   Python Version: 3.11
•   cmakelang Version: cmakelang==0.6.13

Expected Behavior

The ctest-to command should parse the CTestTestfile.cmake file without raising an AttributeError.

Actual Behavior

The command raises an AttributeError indicating that a dict object is being accessed with an attribute parse_db, which does not exist.

Additional Information

It appears that there is an issue with the context or the way the parsing database is being accessed. This might be related to a recent change or an incompatibility with the specific Python version.

Request

Please investigate this issue and provide a fix or a workaround. Let me know if you need any further information or additional logs. Thank you