Skip to content

Commit 5e88346

Browse files
committed
Install: Fixed getting package and bin directories.
1 parent a94d69d commit 5e88346

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

dp3/bin/config.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,41 @@ def config_nginx(app_name, server_hostname, www_root):
7272
www_root_dir.chmod(0o775)
7373

7474

75+
def get_python_directories() -> tuple[Path, Path]:
76+
"""
77+
Get the directory where the DP3 executable is located and where the DP3 library is installed.
78+
79+
There are two cases we need to consider:
80+
81+
- The package is installed in a normal way, be it in virtual environment,
82+
in `~/.local` or in `/usr/local`. The path will allways look something like
83+
`/path/to/python/lib/python3.X/{site|dist}-packages/dp3`.
84+
The path to the executable will be `/path/to/python/bin/dp3`.
85+
- The package is installed in editable mode, in which case the path of the
86+
package depends on the location of the repo. The path to the executable relates
87+
in no way to the path of the package, we cannot be sure.
88+
We therefore give it our best guess, which is the path of the python executable.
89+
This will be correct only in the case of a virtual environment, but it is the best
90+
we can do.
91+
"""
92+
package_path = Path(__file__).parent.parent.absolute()
93+
packages_path = package_path.parent
94+
lib_python_path = packages_path.parent
95+
96+
if "-packages" in packages_path.name and "python3" in lib_python_path.name:
97+
binary_path = package_path.parent.parent.parent.parent / "bin"
98+
else: # This is a development install.
99+
binary_path = Path(sys.executable).parent.absolute()
100+
return binary_path, package_path
101+
102+
75103
def config_supervisor(app_name, config_dir):
76104
"""
77105
Configure supervisor for process management.
78106
Replaces templates: DP3_EXE, DP3_APP, CONFIG_DIR, DP3_BIN, DP3_LIB
79107
"""
80108
# Get the current package location and other relative directories.
81-
package_dir = Path(__file__).parent.parent
82-
python_bin_dir = Path(sys.executable).parent.absolute()
83-
python_lib_dir = python_bin_dir.parent / "lib"
109+
python_bin_dir, package_dir = get_python_directories()
84110
dp3_executable_path = str(python_bin_dir / "dp3")
85111
abs_config_dir = Path(config_dir).absolute()
86112

@@ -101,7 +127,7 @@ def config_supervisor(app_name, config_dir):
101127
replace_template(supervisor_dir, "{{CONFIG_DIR}}", str(abs_config_dir))
102128
replace_template(supervisor_dir, "{{DP3_BIN}}", str(python_bin_dir))
103129
replace_template(supervisor_dir, "{{DP3_EXE}}", dp3_executable_path)
104-
replace_template(supervisor_dir, "{{DP3_LIB}}", str(python_lib_dir))
130+
replace_template(supervisor_dir, "{{DP3_PACKAGE_DIR}}", str(package_dir))
105131
replace_template(supervisor_dir, "{{WORKER_COUNT}}", str(worker_count))
106132

107133
# Set up the systemd service to start supervisor.

dp3/template/supervisor/supervisord.conf.d/api.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ command = {{DP3_BIN}}/gunicorn
77
--worker-class uvicorn.workers.UvicornWorker
88
--bind 127.0.0.1:8081
99

10-
directory = {{DP3_LIB}}/python3.9/site-packages/dp3/api
10+
directory = {{DP3_PACKAGE_DIR}}/api
1111
environment = APP_NAME="{{DP3_APP}}",CONF_DIR="{{CONFIG_DIR}}",ROOT_PATH='/api'
1212

1313
priority = 10

0 commit comments

Comments
 (0)