Import code from parent directory
abullity
PROOP

2 years ago

I have 2 railway services:
api
task_queue

Both are written in Python and are the replications of my monorepo structure - 2 directories in a single repository.
taskqueue uses some code which is defined in api (which is also in api directory, so I can't just move the code there), the way I do that in taskqueue is by injecting root path in sys.path, that way I can import the code from api. Works well on my local but doesn't work in Railway - I get ModuleNotFoundError during the deployment stage.

I have root paths defined for both services to /api and /task_queue, respectively.

How can I use the code defined in /api inside of /task_queue?
Any help would be appreciated

4 Replies

2 years ago

How can I use the code defined in /api inside of /task_queue?
you can not use code outside of the set root directory, you would have to remove the root directory settings


2 years ago

n/a


abullity
PROOP

2 years ago

Thanks @Brody, that makes sense.
I've removed the root path and as a result Python is not detected as a provider (as expected).

I've added providers explicitly in railway.json file.
I've also added custom build command since requirements.txt is going to be nested in the child directory.

This is how my railway.json looks like:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"buildCommand": "pip install -r jobqueue/requirements.txt", "nixpacksPlan": { "providers": ["python"] } }, "deploy": { "startCommand": "celery -A jobqueue.worker.app worker --loglevel=INFO",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 3
}
}

However build still fails due to:
0.291 /bin/bash: line 1: pip: command not found

Could you help me out with this one as well? should I move this to nixpacks.toml file? if so which field would be required there to be added?


2 years ago

I think this would best be done with a Dockerfile, please look into that


Loading...