antarctica / simple-action-pipeline

MIT License
1 stars 0 forks source link

jugrc file written out incorrectly in bash 5 #19

Open davidwilby opened 1 week ago

davidwilby commented 1 week ago

Running through the example usage I get the following error using bash 5.1.16

❯ pipeline execute .
INFO:pipeline:Target: /home/USER/simple-action-pipeline/example/
INFO:pipeline:Pipeline Status: built
Traceback (most recent call last):
  File "/home/USER/miniforge3/envs/sap/bin/jug", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/jug.py", line 248, in main
    options = parse(argv[1:])
              ^^^^^^^^^^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/options.py", line 249, in parse
    inifile = read_configuration_file(optionsfile, default_options=default_options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/options.py", line 137, in read_configuration_file
    config.read_file(fp)
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/configparser.py", line 705, in read_file
    self._read(f, source)
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/configparser.py", line 1064, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '/home/USER/.config/jugrc', line: 1
'$[main]\n'
INFO:pipeline:Executing pipeline simple-example.py ; MaxWorkers=2
Traceback (most recent call last):
  File "/home/USER/miniforge3/envs/sap/bin/jug", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/jug.py", line 248, in main
    options = parse(argv[1:])
              ^^^^^^^^^^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/options.py", line 249, in parse
    inifile = read_configuration_file(optionsfile, default_options=default_options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/options.py", line 137, in read_configuration_file
    config.read_file(fp)
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/configparser.py", line 705, in read_file
    self._read(f, source)
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/configparser.py", line 1064, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '/home/USER/.config/jugrc', line: 1
'$[main]\n'
Traceback (most recent call last):
  File "/home/USER/miniforge3/envs/sap/bin/jug", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/jug.py", line 248, in main
    options = parse(argv[1:])
              ^^^^^^^^^^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/options.py", line 249, in parse
    inifile = read_configuration_file(optionsfile, default_options=default_options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/site-packages/jug/options.py", line 137, in read_configuration_file
    config.read_file(fp)
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/configparser.py", line 705, in read_file
    self._read(f, source)
  File "/home/USER/miniforge3/envs/sap/lib/python3.12/configparser.py", line 1064, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '/home/USER/.config/jugrc', line: 1
'$[main]\n'

This is caused by usage of echo here:

https://github.com/antarctica/simple-action-pipeline/blob/0f8092ab18972c976d9ba1ac56df210c76538b63/src/sap/utils.py#L125

@bnubald suggested using printf instead of echo, or alternatively using python as suggested by @matscorse would be a more os-invariant alternative.

This is not a problem in bash 4.

bnubald commented 1 week ago

Out of interest, could you post the config it generated on your system vs expected?

e.g. expected:

$ cat ~/.config/jugrc 
[main]
jugdir=recent.%(jugfile)s
will_cite=True
davidwilby commented 1 week ago

My bad, I was in a rush and forgot to include it, it's the same but with a $ at the front:

$[main]
jugdir=recent.%(jugfile)s
will_cite=True