Skip to content

Unify INI values#3704

Draft
hansu wants to merge 24 commits into
LinuxCNC:masterfrom
hansu:unify-ini-values
Draft

Unify INI values#3704
hansu wants to merge 24 commits into
LinuxCNC:masterfrom
hansu:unify-ini-values

Conversation

@hansu

@hansu hansu commented Jan 17, 2026

Copy link
Copy Markdown
Member

Fixes #3238 and #2335.

To be done

@hansu hansu added the 2.10-candidate would be nice to have fixed in 2.10 label Jan 17, 2026
@zz912

zz912 commented Jan 17, 2026

Copy link
Copy Markdown
Contributor
* [ ]  Adapt [Gmoccapy - change spindle => spindle_0 in *.ini files #3488](https://github.com/LinuxCNC/linuxcnc/pull/3488)

Feel free remake (or close) #3488 how you need. Git is not my friend, so I cant help you.

#3488 also does:

  • INI file from PNCconf is more verbose in build_INI.py
  • correct MACHINE in 7_axis.ini
  • correct MACHINE in 6_axis.ini

@andypugh

andypugh commented Feb 4, 2026

Copy link
Copy Markdown
Collaborator

update_ini is designed to be scriptable, (-d and -f flags) and I think I had a meta-script that ran it on all the sample configs.
I probably can't find it any more, but I could have a look.

@hansu hansu force-pushed the unify-ini-values branch 2 times, most recently from ef0fb47 to 9cc5bac Compare February 4, 2026 14:20
@hansu

hansu commented Feb 4, 2026

Copy link
Copy Markdown
Member Author

update_ini is designed to be scriptable, (-d and -f flags) and I think I had a meta-script that ran it on all the sample configs. I probably can't find it any more, but I could have a look.

Yes that would be helpful. I only used tested with the -d option so far.
The renaming stuff is done so far, only some parts which moves or copy some values are missing.
And a bit refactoring maybe.
Also a little bug where it generates two [KINS] sections...

@andypugh

andypugh commented Feb 4, 2026

Copy link
Copy Markdown
Collaborator

Yes that would be helpful.

Sorry, I looked and it's nowhere obvious. It might be sat in a git stash somewhere, but I think it's probably been lost.

I doubt it was anything special, I am not much of a scripting wizard.

@hansu

hansu commented Feb 9, 2026

Copy link
Copy Markdown
Member Author

I copied now

  • [TRAJ]DEFAULT_LINEAR_VELOCITY -> [DISPLAY]DEFAULT_LINEAR_VELOCITY
  • [TRAJ]MIN_LINEAR_VELOCITY -> [DISPLAY]MIN_LINEAR_VELOCITY

The values are/will not be not used in TRAJ any more. Do you think we should delete them from TRAJ or keep them as a precaution ?

@c-morley

c-morley commented Feb 9, 2026

Copy link
Copy Markdown
Collaborator

Ate you sure they ate not used in the trajectory planner?
Iirc they are used in non trivial machines.

@hansu

hansu commented Feb 9, 2026

Copy link
Copy Markdown
Member Author

Ate you sure they ate not used in the trajectory planner? Iirc they are used in non trivial machines.

DEFAULT_LINEAR_VELOCITY I overlooked, but MIN_LINEAR_VELOCITY is couldn't find in the trajectory planner.

@c-morley

c-morley commented Feb 9, 2026

Copy link
Copy Markdown
Collaborator

Ahh yes DEFAULT is what I was recalling.

@hansu

hansu commented Feb 11, 2026

Copy link
Copy Markdown
Member Author

I think the script is ready for the first review.

@andypugh How do we handle the message boxes if upgrading from <1.0 to 1.2?
Is it too irritating when there are multiple LinuxCNC versions in the list like this?

grafik

@hansu hansu requested a review from andypugh February 11, 2026 18:25
@zz912

zz912 commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Hi Hans, when do you expect to finish this PR? I'm currently converting the spindle control from PWM to hm2_modbus. So I could test if there are any bugs when changing SPINDLE => SPINDLE_0.

@hansu hansu marked this pull request as ready for review February 22, 2026 13:44
@hansu

hansu commented Feb 22, 2026

Copy link
Copy Markdown
Member Author

It's more or less ready from my side. This is waiting for a review and then all the INI files needs to be converted by the update_ini script and committed.
But this will be done just before 2.10 is being released I guess.

@zz912

zz912 commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

I asked the wrong question.
When do you expect to merge this PR to master?
I'm currently working on hm2_modbus communication.
If it were merged in a few days. I'd wait for that.

I'm just asking. I don't want to do it twice.

@hansu

hansu commented Feb 22, 2026

Copy link
Copy Markdown
Member Author

I think it will take some weeks

@zz912

zz912 commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Ok, thanks for information.

@andypugh

Copy link
Copy Markdown
Collaborator

I think that the very long message box is fine. We really want users to be aware that a lot has changed, and to think before pressing the buttons.

@BsAtHome

BsAtHome commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

How does the update script handle #INCLUDE syntax?

The include handling is expanded by the linuxcnc script and you don't really see the whole truth when running. Well, until now, because the new INI parser does the include internally and does not rely on external merging.

But still, the update script should be aware of #INCLUDE directives and act accordingly. Maybe there needs to be an additional interface in the new INI parser to extract filename/linenr information from python (already possible in C++).

@BsAtHome

Copy link
Copy Markdown
Contributor

The update_ini program also needs to update quoted strings (see #3946 and #3947).

The new ini-parser in python allows you to recall the exact file and line of any variable by using linuxcnc.ini.lineof(section, variable [,num]) (returns a tuple). This allows you to read the old ini-file as text, converted into an array of lines, and then change any line accordingly. The reason to use this feature is because #INCLUDE statements skew the program's view of the content, but the original source of variables can still be recovered by using lineof().
A small problem is line continuation, which are not recoverable from the parsed value (was merged into one value). However, I don't think that lines with continuations are lines that generally need change. But, it is possible to look at the previous line in the source text and see if that had a continuation and act accordingly (lineof returns the last line of the continued value).

@hansu hansu force-pushed the unify-ini-values branch from 50c6463 to dc704c6 Compare April 18, 2026 18:33
@hansu hansu force-pushed the unify-ini-values branch from dc704c6 to 7e24a91 Compare June 10, 2026 21:54
Comment thread src/emc/ini/update_ini.py Outdated
Comment on lines 83 to 85
# We want to work with the base INI file here, not the expanded version if #include is used
filename = re.sub(r'\.expanded', '', filename)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The "expanded" version is no longer generated. If you find an expanded inifile, then it can be removed. The Tcl code has been fixed to use the new inifile parser.

Comment thread src/emc/ini/update_ini.py
Comment on lines +89 to +91
included_files.append(filename)
pattern = re.compile(r"^#INCLUDE[ \t]+(\S+)")
with open(filename, "r", encoding="utf-8") as f:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The include match is not entirely correct, although it should normally not matter I guess. The parser uses ^#INCLUDE[ \t]\s*(.*)\s*, which captures anything after the statement and strips leading/trailing whitespace.

However, what may be wrong is that opening the included file uses a specific path methodology with the following cases:

  • path/file, if $current_include_filename has a '/' in it:
    • --> $(dirname "$current_include_filename")/path/file
    • else --> use open(path/file)
  • ~/path/file --> $HOME/path/file
  • /path/file --> absolute

You need to devise your own running view through the tree of files while tracking through the sections and variables. Includes can happen anywhere, cannot recurse (beware of loops), but may be included multiple times. You must process each file in sequence as the parser would read the files and convert in sequence. You also need tracking already converted files to not double convert and assure that a converted file will be valid when read again in another place (perfectly legal situation).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You also need tracking already converted files to not double convert and assure that a converted file will be valid when read again in another place (perfectly legal situation).

Double conversion should be no problem - if a file is already converted then there is simply nothing to convert.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The include match is not entirely correct, although it should normally not matter I guess. The parser uses ^#INCLUDE[ \t]\s*(.*)\s*, which captures anything after the statement and strips leading/trailing whitespace.

But this would include spaces in the filename:

grafik

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, it can include spaces. That is how the original also worked. The behaviour was taken from that work.

Comment thread src/emc/ini/update_ini.py

for current_file in included_files:
print(f'===> Updating "{current_file}"...')
if version == "$Revision$" or version < "1.0":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think it would be a good idea to handle included files separately because there is no guarantee there is anything in them you can understand without the context of where you are in the ini-file sequence.

As mentioned above you must read through and convert the files in order to be able to track where you are.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If you don't want to merge all the includes together, you have to handle them separately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, yes, you need to handle them one-by-one. However, you must do so as-if you are handling one file and treat everything as one stream while tracking the actual origin.

Example: include variables from a file:

[Tag]
#INCLUDE otherfile.inc

[OtherTag]
#INCLUDE otherfile.inc

and otherfile.inc contains:

# Note: a nested include is perfectly fine
#INCLUDE common.inc
ValidInTag=blabla
# Changing the following tag will become invalid after change but is necessary for [Tag]
BecomesInvalidInOtherTag=nono

Although the error scenario may be rare, the way these includes are made is not. The above include sequence is f.ex. seen in axes and joints that share most parameters. If a converted include file is re-read and would require changes, then you have to flag an error in auto-conversion and say it has to be done manually.

It would also be perfectly legal for an include file to end with a new section header. Returning one level up would then add variables to the section the include file ended with. This would be really borderline sane, but there is nothing that prevents it and the parser happily accepts it. Such scenario will automatically work when you treat the whole ini-file as a text-stream.

The "easy" way out for all the possible problems is to drop auto-conversion of INI-files that contain includes. However, that would make it harder for users. But when you do convert them, then you must support the whole structure and deal with the complexity of how the parser sees and reads the INI-file data when read.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah that's a bit tricky. But I don't think it's worth the work to handle this case.

But feel free to join this game...

@BsAtHome

Copy link
Copy Markdown
Contributor

It is good that you run the update/test after the ini-file is tested for validity:

# Test whether we have a valid INI-file that can be parsed without error.
# Running inivalue without section/variable filter should return the value of
# the first variable in the first section of the file. If that fails, there is
# a parse error in the file or it is empty.
inivalue "$INIFILE" > /dev/null || { echo "E: The INI-file contains errors that need to be fixed."; exit 1; }

It guarantees you already know that the file conforms to the formal standard. The content is then of only concern.

@BsAtHome

Copy link
Copy Markdown
Contributor

Alright then... have a look at this: process_ini.py

It takes an ini file and processes it as one stream white tracking includes and converting recursively. Two functions are provided to handle conversion (handleSection and handleVariable)

The only limitation is that it assumes that you do not re-read an include file that has sections in it. This case would already produce a warning in the new ini-parser (same section name gets its variables merged), so it is probably safe to assume this will not happen.

@hansu

hansu commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

But how should that fit in the current update_ini script?

@BsAtHome

Copy link
Copy Markdown
Contributor

But how should that fit in the current update_ini script?

With care? ;-)

But seriously, it needs some more work, yes. This was just to show that making a full stream editor for the ini-file is not that difficult. Will make some "suggestion" when I'm done hacking the script.

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

Labels

2.10-candidate would be nice to have fixed in 2.10

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify INI file settings in DISPLAY section

5 participants