Skip to content

Commit

Permalink
ontologia-multi-writing-system (#7): cor.hxltm.215.yml name can be us…
Browse files Browse the repository at this point in the history
…ed instead of cor.hxltm.yml (not yet default); improved tests to search files not installed with package
  • Loading branch information
fititnt committed Nov 15, 2021
1 parent 57207a1 commit e1310ba
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 70 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- TODO
<!-- ## [v0.8.9-rc.2] - 2020-11-12 -->
- `cor.hxltm.215.yml` can be use instead of `cor.hxltm.yml` (refs #7)

### Changed
- Environment variable `HXLM_CONFIG_BASE` renamed to `HXLTM_DORMUM`
- Environment variable `HXLTM_TESTUM_BASIM_DEFALLO` renamed to `HXLTM_TESTUM`

## [v0.8.9-rc.2] - 2020-11-14

Expand Down
72 changes: 38 additions & 34 deletions bin/hxltmcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# COMPANY: EticaAI
# LICENSE: Public Domain dedication OR Zero-Clause BSD
# SPDX-License-Identifier: Unlicense OR 0BSD
# VERSION: v0.8.8
# VERSION: v0.9.0-rc.1
# CREATED: 2021-06-27 19:50 UTC v0.5, de github.com/EticaAI
# /HXL-Data-Science-file-formats/blob/main/bin/hxl2example
# REVISION: 2021-06-27 21:16 UTC v0.6 de hxl2tab
Expand All @@ -64,6 +64,7 @@
# 2021-10-15 17:08 UTC v0.8.7 MVP of --objectivum-formulam
# 2021-10-15 17:08 UTC v0.8.8 --objectivum-formulam, allow
# save result to file (was working for stdout)
# -------------------- v0.9.0 To be released
# ==============================================================================
"""hxltmcli.py: Humanitarian Exchange Language Trānslātiōnem Memoriam CLI
Expand Down Expand Up @@ -247,7 +248,7 @@
from liquid.context import Context as LiquidContext
# from liquid.token import TOKEN_EXPRESSION as LIQUID_TOKEN_EXPRESSION

__VERSION__ = "v0.8.8"
__VERSION__ = "v0.9.0-rc.1"

# _[eng-Latn]
# Note: If you are doing a fork and making it public, please customize
Expand Down Expand Up @@ -296,31 +297,22 @@

_HOME = str(Path.home())

# TODO: clean up redundancy from hxlm/core/schema/urn/util.py
HXLM_CONFIG_BASE = os.getenv(
'HXLM_CONFIG_BASE', _HOME + '/.config/hxlm')
# ~/.config/hxlm/cor.hxltm.yml
# cor.hxltm.215.ext:
# 1. HXLTM_RUNNING_DIR ; defallo .
# 2. HXLTM_DORMUM ; defallo ~/.config/hxlm/cor.hxltm.215.ext
# 3. HXLTM_SYSTEMA_DIR ; defallo hxltmcli.py dir

# _[eng-Latn]
# This can be customized with enviroment variable HXLM_CONFIG_BASE
#
# Since hpd-toolchain is not a hard requeriment, we first try to load
# hdp-toolchain lib, but if hxltmcli is a standalone script with
# only libhxl, yaml, etc installed, we tolerate it
# Environment variables HXLTM_DORMUM (for default search place for
# configurations) HXLTM_TESTUM (for default place to search for test
# files) can be manually configured.
# [eng-Latn]_
try:
from hxlm.core.constant import (
HXLM_ROOT,
HDATUM_EXEMPLUM
)
HXLTM_SCRIPT_DIR = HXLM_ROOT + '/core/bin'
HXLTM_TESTUM_BASIM_DEFALLO = str(HDATUM_EXEMPLUM).replace('file://', '')
except ImportError:
HXLTM_SCRIPT_DIR = str(Path(__file__).parent.resolve())
HXLTM_TESTUM_BASIM_DEFALLO = str(Path(
# HXLTM_SCRIPT_DIR + '/../../../testum/hxltm').resolve())
HXLTM_SCRIPT_DIR + '/../../../testum').resolve())
HXLTM_DORMUM = os.getenv('HXLTM_DORMUM', _HOME + '/.config/hxltm')
HXLTM_TESTUM = os.getenv(
'HXLTM_TESTUM', HXLTM_DORMUM + '/testum')
# TODO: make HXLTM_TESTUM instalable as python package

HXLTM_SYSTEMA_DIR = str(Path(__file__).parent.resolve())
HXLTM_RUNNING_DIR = str(Path().resolve())


Expand Down Expand Up @@ -5967,7 +5959,7 @@ def testum_praefixum(archivum: str = None) -> str:
_[eng-Latn]
Note: this will try check if the enviroment variable
HXLTM_TESTUM_BASIM and only fallback to assume the entire
HXLTM_TESTUM and only fallback to assume the entire
hdp-toolchain installation (or a fork from
EticaAI/HXL-Data-Science-file-formats) on local disk.
Expand All @@ -5989,9 +5981,9 @@ def testum_praefixum(archivum: str = None) -> str:

# if HDATUM_EXEMPLUM:
# hxltmtestum = str(Path(
# HXLTM_SCRIPT_DIR + '/../../../testum/hxltm').resolve())
# HXLTM_SYSTEMA_DIR + '/../../../testum/hxltm').resolve())

praefixum = os.getenv('HXLTM_TESTUM_BASIM', HXLTM_TESTUM_BASIM_DEFALLO)
praefixum = os.getenv('HXLTM_TESTUM', HXLTM_TESTUM)

if archivum:
return praefixum + '/' + archivum
Expand All @@ -6014,8 +6006,8 @@ def datum(
if not os.path.isfile(exemplum_archivum):
raise RuntimeError(
'HXLTMTestumAuxilium non-datum [{}]. '
'Requīsītum: dēfīnītiōnem HXLTM_TESTUM_BASIM. Exemplum:'
'> HXLTM_TESTUM_BASIM="/home/marcus/testum/" '
'Requīsītum: dēfīnītiōnem HXLTM_TESTUM. Exemplum:'
'> HXLTM_TESTUM="/home/marcus/testum/" '
'python3 -m doctest hxltmcli-de-marcus.py'
' <'.format(exemplum_archivum))

Expand Down Expand Up @@ -6749,8 +6741,8 @@ def load_hxltm_options(custom_file_option=None, is_debug=False):
# pylint: disable=using-constant-test
if is_debug:
print('load_hxltm_options')
print('HXLM_CONFIG_BASE', HXLM_CONFIG_BASE)
print('HXLTM_SCRIPT_DIR', HXLTM_SCRIPT_DIR)
print('HXLTM_DORMUM', HXLTM_DORMUM)
print('HXLTM_SYSTEMA_DIR', HXLTM_SYSTEMA_DIR)
print('HXLTM_RUNNING_DIR', HXLTM_RUNNING_DIR)

if custom_file_option is not None:
Expand All @@ -6764,13 +6756,25 @@ def load_hxltm_options(custom_file_option=None, is_debug=False):
return HXLTMUtil._load_hxltm_options_file(
HXLTM_RUNNING_DIR + '/cor.hxltm.yml', is_debug)

if Path(HXLM_CONFIG_BASE + '/cor.hxltm.yml').exists():
if Path(HXLTM_RUNNING_DIR + '/cor.hxltm.215.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLTM_RUNNING_DIR + '/cor.hxltm.215.yml', is_debug)

if Path(HXLTM_DORMUM + '/cor.hxltm.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLTM_DORMUM + '/cor.hxltm.yml', is_debug)

if Path(HXLTM_DORMUM + '/cor.hxltm.215.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLTM_DORMUM + '/cor.hxltm.215.yml', is_debug)

if Path(HXLTM_SYSTEMA_DIR + '/cor.hxltm.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLM_CONFIG_BASE + '/cor.hxltm.yml', is_debug)
HXLTM_SYSTEMA_DIR + '/cor.hxltm.yml', is_debug)

if Path(HXLTM_SCRIPT_DIR + '/cor.hxltm.yml').exists():
if Path(HXLTM_SYSTEMA_DIR + '/cor.hxltm.215.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLTM_SCRIPT_DIR + '/cor.hxltm.yml', is_debug)
HXLTM_SYSTEMA_DIR + '/cor.hxltm.215.yml', is_debug)
# print('oioioi')

raise RuntimeError(
Expand Down
73 changes: 40 additions & 33 deletions bin/hxltmdexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
# COMPANY: EticaAI
# LICENSE: Public Domain dedication OR Zero-Clause BSD
# SPDX-License-Identifier: Unlicense OR 0BSD
# VERSION: v0.7.0
# VERSION: v0.9.0-rc.1
# CREATED: 2021-07-24 00:04 UTC v0.1.0 de hxl2example
# REVISION: 2021-07-24 17:49 UTC v0.2.0 hxltmdexml at least read XML
# 2021-07-25 23:28 UTC v0.5.0 XLIFF 1.2 and XLIFF 2.1 (MVP)
# 2021-07-28 22:01 UTC v0.7.0 TBX-IATE (MVP), TMX (MVP)
# 2021-11-06 21:19 UTC v0.8.0 Fix cli importing; more stable
# -------------------- v0.9.0 To be released
# ==============================================================================
"""hxltmdexml.py: Humanitarian Exchange Language Trānslātiōnem Memoriam de XML
Expand Down Expand Up @@ -189,7 +190,7 @@
# pip3 install langcodes
# import langcodes

__VERSION__ = "v0.7.1"
__VERSION__ = "v0.9.0-rc.1"

# _[eng-Latn]
# Note: If you are doing a fork and making it public, please customize
Expand Down Expand Up @@ -274,30 +275,24 @@

_HOME = str(Path.home())

# TODO: clean up redundancy from hxlm/core/schema/urn/util.py
HXLM_CONFIG_BASE = os.getenv(
'HXLM_CONFIG_BASE', _HOME + '/.config/hxlm')
# ~/.config/hxlm/cor.hxltm.yml
# cor.hxltm.215.ext:
# 1. HXLTM_RUNNING_DIR ; defallo .
# 2. HXLTM_DORMUM ; defallo ~/.config/hxlm/cor.hxltm.215.ext
# 3. HXLTM_SYSTEMA_DIR ; defallo hxltmcli.py dir

# _[eng-Latn]
# This can be customized with enviroment variable HXLM_CONFIG_BASE
#
# Since hpd-toolchain is not a hard requeriment, we first try to load
# hdp-toolchain lib, but if hxltmcli is a standalone script with
# only libhxl, yaml, etc installed, we tolerate it
# Environment variables HXLTM_DORMUM (for default search place for
# configurations) HXLTM_TESTUM (for default place to search for test
# files) can be manually configured.
# [eng-Latn]_
try:
from hxlm.core.constant import (
HXLM_ROOT,
HDATUM_EXEMPLUM
)
HXLTM_SCRIPT_DIR = HXLM_ROOT + '/core/bin'
HXLTM_TESTUM_BASIM_DEFALLO = str(HDATUM_EXEMPLUM).replace('file://', '')
except ImportError:
HXLTM_SCRIPT_DIR = str(Path(__file__).parent.resolve())
HXLTM_TESTUM_BASIM_DEFALLO = str(Path(
HXLTM_SCRIPT_DIR + '/../../../testum/hxltm').resolve())
HXLTM_DORMUM = os.getenv('HXLTM_DORMUM', _HOME + '/.config/hxltm')
HXLTM_TESTUM = os.getenv(
'HXLTM_TESTUM', HXLTM_DORMUM + '/testum')
# TODO: make HXLTM_TESTUM instalable as python package

# systēma

HXLTM_SYSTEMA_DIR = str(Path(__file__).parent.resolve())
HXLTM_RUNNING_DIR = str(Path().resolve())

# De Python Constants
Expand Down Expand Up @@ -2904,8 +2899,8 @@ def load_hxltm_options(custom_file_option=None, is_debug=False):
# pylint: disable=using-constant-test
if is_debug:
print('load_hxltm_options')
print('HXLM_CONFIG_BASE', HXLM_CONFIG_BASE)
print('HXLTM_SCRIPT_DIR', HXLTM_SCRIPT_DIR)
print('HXLTM_DORMUM', HXLTM_DORMUM)
print('HXLTM_SYSTEMA_DIR', HXLTM_SYSTEMA_DIR)
print('HXLTM_RUNNING_DIR', HXLTM_RUNNING_DIR)

if custom_file_option is not None:
Expand All @@ -2919,13 +2914,25 @@ def load_hxltm_options(custom_file_option=None, is_debug=False):
return HXLTMUtil._load_hxltm_options_file(
HXLTM_RUNNING_DIR + '/cor.hxltm.yml', is_debug)

if Path(HXLM_CONFIG_BASE + '/cor.hxltm.yml').exists():
if Path(HXLTM_RUNNING_DIR + '/cor.hxltm.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLTM_RUNNING_DIR + '/cor.hxltm.215.yml', is_debug)

if Path(HXLTM_DORMUM + '/cor.hxltm.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLTM_DORMUM + '/cor.hxltm.yml', is_debug)

if Path(HXLTM_DORMUM + '/cor.hxltm.215.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLTM_DORMUM + '/cor.hxltm.215.yml', is_debug)

if Path(HXLTM_SYSTEMA_DIR + '/cor.hxltm.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLM_CONFIG_BASE + '/cor.hxltm.yml', is_debug)
HXLTM_SYSTEMA_DIR + '/cor.hxltm.yml', is_debug)

if Path(HXLTM_SCRIPT_DIR + '/cor.hxltm.yml').exists():
if Path(HXLTM_SYSTEMA_DIR + '/cor.hxltm.215.yml').exists():
return HXLTMUtil._load_hxltm_options_file(
HXLTM_SCRIPT_DIR + '/cor.hxltm.yml', is_debug)
HXLTM_SYSTEMA_DIR + '/cor.hxltm.215.yml', is_debug)
# print('oioioi')

raise RuntimeError(
Expand Down Expand Up @@ -3030,7 +3037,7 @@ def testum_praefixum(archivum: str = None) -> str:
_[eng-Latn]
Note: this will try check if the enviroment variable
HXLTM_TESTUM_BASIM and only fallback to assume the entire
HXLTM_TESTUM and only fallback to assume the entire
hdp-toolchain installation (or a fork from
EticaAI/HXL-Data-Science-file-formats) on local disk.
Expand All @@ -3052,9 +3059,9 @@ def testum_praefixum(archivum: str = None) -> str:

# if HDATUM_EXEMPLUM:
# hxltmtestum = str(Path(
# HXLTM_SCRIPT_DIR + '/../../../testum/hxltm').resolve())
# HXLTM_SYSTEMA_DIR + '/../../../testum/hxltm').resolve())

praefixum = os.getenv('HXLTM_TESTUM_BASIM', HXLTM_TESTUM_BASIM_DEFALLO)
praefixum = os.getenv('HXLTM_TESTUM', HXLTM_TESTUM)

if archivum:
return praefixum + '/' + archivum
Expand All @@ -3077,8 +3084,8 @@ def datum(
if not os.path.isfile(exemplum_archivum):
raise RuntimeError(
'HXLTMTestumAuxilium non-datum [{}]. '
'Requīsītum: dēfīnītiōnem HXLTM_TESTUM_BASIM. Exemplum:'
'> HXLTM_TESTUM_BASIM="/home/marcus/testum/" '
'Requīsītum: dēfīnītiōnem HXLTM_TESTUM. Exemplum:'
'> HXLTM_TESTUM="/home/marcus/testum/" '
'python3 -m doctest hxltmcli-de-marcus.py'
' <'.format(exemplum_archivum))

Expand Down
13 changes: 12 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# To run even if flake8 is not enabled by default
# tox -e flake8
# To run doctests (not integrated yet with tox)
# pytest -vv bin/ --doctest-modules
# HXLTM_TESTUM=./testum pytest -vv src/hxltm/bin/ --doctest-module

### To run with travis ........................................................
# @see .travis.yml
Expand Down Expand Up @@ -59,6 +59,9 @@ deps =
pyyaml
langcodes

setenv =
HXLTM_TESTUM = ./testum

commands =
# pytest -vv bin/ --doctest-modules
pytest -vv src/hxltm/bin/ --doctest-modules
Expand All @@ -75,6 +78,9 @@ deps =
langcodes
python-liquid

setenv =
HXLTM_TESTUM = ./testum

commands =
pytest
# pylint
Expand All @@ -92,6 +98,8 @@ deps =
pyyaml
langcodes

setenv =
HXLTM_TESTUM = ./testum

[testenv:flake8]
deps =
Expand All @@ -100,6 +108,9 @@ deps =
libhxl
pyyaml

setenv =
HXLTM_TESTUM = ./testum

commands =
# pytest -vv bin/ --doctest-modules
pytest -vv src/hxltm/bin/ --doctest-modules
Expand Down

0 comments on commit e1310ba

Please sign in to comment.