Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: "3.13"
- run: pip install ruff && ruff check ./src
- run: pip install ruff && ruff check ./pkg ./src

job-semgrep:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -56,21 +56,18 @@ jobs:
- name: pip-install-test
run: |
sudo pip3 install -UI pip && sudo pip3 install -UI build setuptools wheel twine pyOpenSSL
cd src
sudo python3 -m build
pip3 install ./dist/*.tar.gz
aloha info
pip3 list | sort
cp ./README.md ./pkg/
cd pkg && sudo python3 -m build && pip3 install ./dist/*.tar.gz
pip3 list | grep aloha && aloha info

- name: pypi-publish
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_PASSWORD_TEST: ${{ secrets.TWINE_PASSWORD_TEST }}
run: |
env | sort -f && cd src && ls -alh
env | sort -f && cp ./README.md ./pkg/ && cd pkg && ls -alh
sudo python3 -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)"
sudo python3 -m build
ls -alh ./dist
sudo python3 -m build && ls -alh ./dist

if [ "${GITHUB_REPOSITORY}" = "LabNow-ai/aloha-python" ] && [ "${GITHUB_REF_NAME}" = "main" ] ; then
URL_REPOSITORY="https://upload.pypi.org/legacy/" ; P=${TWINE_PASSWORD} ;
Expand Down
179 changes: 0 additions & 179 deletions app/README.md

This file was deleted.

3 changes: 2 additions & 1 deletion doc/.readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build:
jobs:
pre_create_environment:
- echo "Command run at 'pre_create_environment' step"
- 'cp ./README.md ./pkg/'
pre_build:
- 'case "${READTHEDOCS_LANGUAGE}" in zh*) cp ./doc/mkdocs.zh.yml ./doc/mkdocs.yml ;; esac'
post_build:
Expand All @@ -23,6 +24,6 @@ python:
install:
- requirements: ./doc/requirements.txt
- method: pip
path: ./src
path: ./pkg
extra_requirements:
- all
File renamed without changes.
1 change: 1 addition & 0 deletions pkg/aloha/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.0"
File renamed without changes.
File renamed without changes.
84 changes: 84 additions & 0 deletions pkg/aloha/config/hocon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import os

from attrdict import AttrDict
from pyhocon import ConfigFactory
from pyhocon.config_parser import ConfigParser
from pyhocon.config_tree import ConfigTree, ConfigValues
from pyhocon.exceptions import ConfigSubstitutionException


# Monkeypatch ConfigParser._fixup_self_references to prevent "OrderedDict mutated during iteration"
# error on Python 3.13+ when resolving self-referential environment overrides.
@classmethod
def patched_fixup_self_references(cls, config, accept_unresolved=False):
if isinstance(config, ConfigTree) and config.root:
for key in list(config.keys()): # Use list to avoid mutation error during iteration
history = config.history.get(key)
if not history:
continue
previous_item = history[0]
for current_item in history[1:]:
for substitution in cls._find_substitutions(current_item):
prop_path = ConfigTree.parse_key(substitution.variable)
if len(prop_path) > 1 and config.get(substitution.variable, None) is not None:
continue
if prop_path[0] == key:
if isinstance(previous_item, ConfigValues) and not accept_unresolved:
raise ConfigSubstitutionException(
"Property {variable} cannot be substituted. Check for cycles.".format(
variable=substitution.variable
)
)
else:
value = previous_item if len(prop_path) == 1 else previous_item.get(".".join(prop_path[1:]))
_, _, current_item = cls._do_substitute(substitution, value)
previous_item = current_item

if len(history) == 1:
for substitution in cls._find_substitutions(previous_item):
prop_path = ConfigTree.parse_key(substitution.variable)
if len(prop_path) > 1 and config.get(substitution.variable, None) is not None:
continue
if prop_path[0] == key:
value = os.environ.get(key)
if value is not None:
cls._do_substitute(substitution, value)
continue
if substitution.optional:
cls._do_substitute(substitution, None)


# Fix: https://github.com/chimpler/pyhocon/pull/348 , the function and fix can be remove after this PR merged.
ConfigParser._fixup_self_references = patched_fixup_self_references


def load_config_from_hocon(config_file):
"""
Load configuration from a single HOCON file.

:param config_file: Path to the HOCON configuration file
:return: Configuration as an ordered dictionary
"""
config = ConfigFactory.parse_file(config_file).as_plain_ordered_dict()
return config


def load_config_from_hocon_files(config_files: list, base_dir: str):
"""
Load configuration from multiple HOCON files.

Combines multiple HOCON files using include directives and returns
the result as an AttrDict for attribute-style access.

:param config_files: List of HOCON configuration file names
:param base_dir: Base directory for resolving relative paths
:return: Configuration as an AttrDict object
"""
s = []
for config_file in config_files:
f = 'include required("%s")' % config_file
s.append(f)
f = "\n".join(s)

config = ConfigFactory.parse_string(content=f, basedir=base_dir).as_plain_ordered_dict()
return AttrDict(config)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading