Skip to content

Commit

Permalink
Rename eol settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjanklein committed Oct 9, 2022
1 parent 169b6b8 commit a43a2d4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
20 changes: 8 additions & 12 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,15 @@ Configuration options are:
This is mostly useful to reduce CSP license count usage on older
systems. (CSP licenses are used as items are retrieved using a CSP
API.)
* **compatibility** ('vscode'|'export', default 'export') specifies how
to export trailing newlines. Setting this to 'export' exports the same
way that e.g. `$System.OBJ.ExportUDL()` does. The Visual Studio Code
ObjectScript extension exports one trailing newline less. (This could
be considered [a
bug](https://github.com/intersystems-community/vscode-objectscript/issues/850),
but it won't be fixed.) If compatibility with this plugin is
important, set this to 'vscode'.
* **augment_from** (filename) specifies an external toml file to merge
into the current one. It can be used to specify settings used in
multiple toml files once. The toml file must have the same structure
as the regular one, but does not have to be complete.
* **disable_eol_fix** (true|false, default false) allows disabling a fix
that saves the proper number of newlines when exporting CSP and
routine items. Before version 0.4.7, one final newline was stripped.
With this fix, exporting and re-importing does not change the file.
Disabling this fix could be useful to prevent many whitespace-only
changes in an existing repository.
* **disable_class_eol_fix** (true|false, default false) allows, like the
setting above, disabling a fix that ensures the proper number of
newlines when exporting classes. On versions 0.5 and below, one final
newline was stripped. With this fix, the export is compatible with
`$System.OBJ.Export()`. Disabling this fix could be useful to prevent
many whitespace-only changes in an existing repository.
12 changes: 9 additions & 3 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ def check(config:ns.Namespace):
ns.check_default(local, 'cookies', False)
ns.check_encoding(local, 'encoding', 'UTF-8')

# Backwards compatibility settings
ns.check_default(local, 'disable_eol_fix', False)
ns.check_default(local, 'disable_class_eol_fix', False)
# Output compatibility setting
ns.check_oneof(local, 'compatibility', ('vscode', 'export'), 'export')

# Warn about now unused settings
if 'disable_eol_fix' in local or 'disable_class_eol_fix' in local:
msg = "..._eol_fix settings are no longer supported. Use 'compatibility'" \
" setting instead. Value: false -> 'export', true -> 'vscode'."
raise ConfigurationError(msg)



# =====
Expand Down
4 changes: 2 additions & 2 deletions src/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def retrieve_item(config:ns.Namespace, item:dict):

# CSP/RTN text contents is missing a trailing newline; fix this unless
# the configuration says no.
nofix = config.Local.disable_eol_fix
nofix = config.Local.compatibility == 'vscode'
if not nofix and result['cat'] in ('CSP', 'RTN') and not result['enc']:
content.append('')

# The join below will also remove one line from class exports. Fix that
# unless turned off.
nofix = config.Local.disable_class_eol_fix
nofix = config.Local.compatibility == 'vscode'
if not nofix and result['cat'] == 'CLS' and not result['enc']:
content.append('')

Expand Down
16 changes: 4 additions & 12 deletions template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,9 @@ subdirs = true
# licence can be retained between runs.
cookies = false

# Output compatibility: either 'vscode' or 'export'. The former omits
# a trailing newline on export, that the latter includes.
compatibility = 'vscode'

# Augment/override settings in this file with the one specified here.
augment_from = ''


# ===== Backwards compatibility settings; should not normally
# ===== be changed.

# Disable fix that makes sure the last newline of routines is
# present.
disable_eol_fix = false

# Disable fix that makes sure the last newline of classes is
# present.
disable_class_eol_fix = false
29 changes: 23 additions & 6 deletions tests/test_export_newlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,30 @@ def test_class_newlines(tmp_path, server_toml, get_files):
compare_exports(tmp_path, get_files, cfg, name)

@pytest.mark.usefixtures("reload_modules")
def test_class_newlines_prev(tmp_path, server_toml, get_files):
""" Tests classes with backwards compatibility setting """
def test_class_newlines_vscode(tmp_path, server_toml, get_files):
""" Tests classes with VS Code compatibility setting """

name = 'Strix.Std.EAN.cls'

cfg = CFG.format(dir=tmp_path, name=name)
cfg = f"{cfg}\ndisable_class_eol_fix=true\n{server_toml}"
cfg = f"{cfg}\ncompatibility='vscode'\n{server_toml}"

compare_exports(tmp_path, get_files, cfg, name, True)

@pytest.mark.usefixtures("reload_modules")
def test_class_newlines_vscode_aug(tmp_path, server_toml, get_files):
""" Tests compatibility setting from augment config file """

name = 'Strix.Std.EAN.cls'

aug = "[Local]\ncompatibility='vscode'\n"
aug_name = tmp_path / 'aug.toml'
with open(aug_name, 'wt', encoding='UTF8') as f:
f.write(aug)

cfg = '\n'.join([CFG.format(dir=tmp_path, name=name),
f"augment_from='{aug_name}'",
server_toml ])

compare_exports(tmp_path, get_files, cfg, name, True)

Expand All @@ -86,13 +103,13 @@ def test_inc_newlines(tmp_path, server_toml, get_files):
compare_exports(tmp_path, get_files, cfg, name)

@pytest.mark.usefixtures("reload_modules")
def test_inc_newlines_prev(tmp_path, server_toml, get_files):
""" Tests include files with backwards compatibility setting """
def test_inc_newlines_vscode(tmp_path, server_toml, get_files):
""" Tests include files with VS Code compatibility setting """

name = 'Strix.inc'

cfg = CFG.format(dir=tmp_path, name=name)
cfg = f"{cfg}\ndisable_eol_fix=true\n{server_toml}"
cfg = f"{cfg}\ncompatibility='vscode'\n{server_toml}"

compare_exports(tmp_path, get_files, cfg, name, True)

Expand Down

0 comments on commit a43a2d4

Please sign in to comment.