Skip to content

Conversation

@osmith42
Copy link
Collaborator

@osmith42 osmith42 commented Oct 9, 2025

I've prepared a patchset for running PyHSS outside of the source tree. This is useful for the osmo-ttcn3-hacks test environment, where we already have test cases for HLR and HSS (that currently run against OsmoHLR and Open5GS, I'm working towards running them against PyHSS as well). Furthermore this can be used to make e.g. Debian packaging feasible, which would allow installing PyHSS system-wide like other packages.

Summary of changes:

  • Rework config loading to deduplicate code and to allow using a config from not only the top of the source tree, but also from /etc/pyhss/config.yaml, /usr/share/pyhss/config.yaml and a PYHSS_CONFIG environment variable.
  • When adding lib/ to sys.path, use the path relative to the current script instead of the current working directory.
  • Add a pyproject.toml for building python wheels.

Please see the individual commits for details.

The config is already getting parsed a few lines above, don't do it
twice.
The config is not used here, so remove code for loading it. Remove
commented out alternative logging initializing code while at it too.
Rename config to alembic_config, so we can use config as the pyhss
config (as it is used in most other files).
Move the config file loading to a new lib/pyhss_config.py file, instead
of having it duplicated in all files that load the config. This allows
replacing code like:

  import yaml

  try:
      with open("../config.yaml", 'r') as stream:
          config = (yaml.safe_load(stream))
  except:
      with open("config.yaml", 'r') as stream:
          config = (yaml.safe_load(stream))

with the following in all files:

  from pyhss_config import config

Replace code that loaded the config to self.config in various classes
with just using the global config variable. Adjust the few scripts that
had named it yaml_config instead of config to just config, so it is
consistent.

Let the new code not only load the config from the top dir of the git
repository, but also from a PYHSS_CONFIG env var, /etc/pyhss/config.yaml
and /usr/share/pyhss/config.yaml. This is useful for being able to still
load configs after installing PyHSS into a different location, for
example with pip or apt. It also allows running tests against PyHSS with
a config file in a separate directory (e.g. in osmo-ttcn3-hacks).
This script doesn't import anything from lib, so this is not needed.
To run services outside of the source tree, the lib path must be added
correctly to sys.path. Fix this by determining it relative to the
current script's path instead of assuming that it is in ../lib (relative
to the current work dir).
Add main() functions, so pyproject.toml can create launcher scripts for
the services.
Add a pyproject.toml file, so it becomes possible to build python whl
packages with:

$ python3 -m build

With this change, Linux distributions could package PyHSS similar to
other python projects, it should be possible to install it via pip (from
the git repo), and the whl can be used to directly install PyHSS into a
venv.
@osmith42 osmith42 force-pushed the osmith/rework-config-loading branch from 1e28305 to 4362227 Compare October 10, 2025 10:49
osmocom-gerrit pushed a commit to osmocom/osmo-dev that referenced this pull request Oct 13, 2025
Support cloning and building PyHSS and "interesting" dependencies (that
we might want to patch while hacking on PyHSS). Other dependencies such
as sqlalchemy get installed via pip into a venv that is currently shared
by all python projects that osmo-dev can build. We can change this later
on to use multiple venvs or change the dependencies that get built from
source, if needed.

Python projects get built with "python3 -m build" into a whl file, and
then installed into the venv with "pip install".

The above works with projects that have a pyproject.toml. PyHSS
currently doesn't have this yet, but this patchset adds one:
nickvsnetworking/pyhss#258

python-venv-requirements.txt in this patch is a combination of the
relevant dependencies from PyHSS and dependencies that get built from
source.

Related: OS#6862
Change-Id: If40c9e8ea07c9f6c7d379f6d5ff659e95165e4ae
Copy link
Collaborator

@Takuto88 Takuto88 left a comment

Choose a reason for hiding this comment

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

Let me preface this: I feel only responsible for the GSUP part, thus I will not overstep my boundaries here and will not merge this.

That being said: I looked at it because it came from @osmith42 too. I would very much like to see this land in master. The improvements on loading the config and be less path dependent is really substantial.

I have checked out his branch and it works for the GSUP part. The other daemons still launch successfully for me. I've checked that this retains compatibility too. If you have your config.yml inside the project root, it will still be picked up if you don't specify a PYHSS_CONFIG env variable or have the config in one of the new paths like /etc/pyhss/config.yml.

@nickvsnetworking What do you think? Is this something you'd like to upstream as well? When reviewing this, I recommend looking at the individual commits that really makes life easier.

osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
The config is already getting parsed a few lines above, don't do it
twice.

Upstreaming: nickvsnetworking#258
osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
The config is not used here, so remove code for loading it. Remove
commented out alternative logging initializing code while at it too.

Upstreaming: nickvsnetworking#258
osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
Rename config to alembic_config, so we can use config as the pyhss
config (as it is used in most other files).

Upstreaming: nickvsnetworking#258
osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
Move the config file loading to a new lib/pyhss_config.py file, instead
of having it duplicated in all files that load the config. This allows
replacing code like:

  import yaml

  try:
      with open("../config.yaml", 'r') as stream:
          config = (yaml.safe_load(stream))
  except:
      with open("config.yaml", 'r') as stream:
          config = (yaml.safe_load(stream))

with the following in all files:

  from pyhss_config import config

Replace code that loaded the config to self.config in various classes
with just using the global config variable. Adjust the few scripts that
had named it yaml_config instead of config to just config, so it is
consistent.

Let the new code not only load the config from the top dir of the git
repository, but also from a PYHSS_CONFIG env var, /etc/pyhss/config.yaml
and /usr/share/pyhss/config.yaml. This is useful for being able to still
load configs after installing PyHSS into a different location, for
example with pip or apt. It also allows running tests against PyHSS with
a config file in a separate directory (e.g. in osmo-ttcn3-hacks).

Upstreaming: nickvsnetworking#258
osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
This script doesn't import anything from lib, so this is not needed.

Upstreaming: nickvsnetworking#258
osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
To run services outside of the source tree, the lib path must be added
correctly to sys.path. Fix this by determining it relative to the
current script's path instead of assuming that it is in ../lib (relative
to the current work dir).

Upstreaming: nickvsnetworking#258
osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
Add main() functions, so pyproject.toml can create launcher scripts for
the services.

Upstreaming: nickvsnetworking#258
osmith42 added a commit to osmith42/pyhss that referenced this pull request Nov 10, 2025
Add a pyproject.toml file, so it becomes possible to build python whl
packages with:

$ python3 -m build

With this change, Linux distributions could package PyHSS similar to
other python projects, it should be possible to install it via pip (from
the git repo), and the whl can be used to directly install PyHSS into a
venv.

Upstreaming: nickvsnetworking#258
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants