-
Notifications
You must be signed in to change notification settings - Fork 80
Allow running outside of source tree #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Allow running outside of source tree #258
Conversation
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.
1e28305 to
4362227
Compare
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
Takuto88
left a comment
There was a problem hiding this 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.
The config is already getting parsed a few lines above, don't do it twice. Upstreaming: nickvsnetworking#258
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
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
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
This script doesn't import anything from lib, so this is not needed. Upstreaming: nickvsnetworking#258
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
Add main() functions, so pyproject.toml can create launcher scripts for the services. Upstreaming: nickvsnetworking#258
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
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:
/etc/pyhss/config.yaml,/usr/share/pyhss/config.yamland aPYHSS_CONFIGenvironment variable.lib/tosys.path, use the path relative to the current script instead of the current working directory.Please see the individual commits for details.