importing support files from parent directory

Hello,

First of all, I’ve searched and feel like this has been partially answered elsewhere, but I’m just trying to get a firm, final answer-- I apologize if this duplicates anything.

We’ve got three Bokeh apps, each of which is a fairly heavy dashboard for three different software products. The directory structure looks like this:

  • parent_project_dir

  • support_files

  • support_functions_i_want_to_use.py

  • dashboard_1_app

  • main.py

  • (etc)

  • dashboard_2_app

  • main.py

  • (etc)

  • dashboard_3_app

  • main.py

  • (etc)

So far I have not managed to have a dashboard able to import the support functions. (These functions were written before these apps were apps, when they were just static scripts, and we’ve since converted them to have more dynamic interactivity.) I can replicate the functions within a support file under each dashboard_n_app directory, but that seems unwieldy, especially when all three need the same thing-- copying and pasting (and triplicating maintenance effort in the future) just seems wrong.

Is it correct that this is not possible? Are there options?

Thanks,

Carolyn

Hi,

There's not really going to be any good way to do this if you run "bokeh serve" as a separate process. Think about if you had just run "python main.py" for instance. You would not be able to import random files higher up in the filesystem in that case either. Some ideas:

* explicitly munging sys.path to include the location of this module you need

* embedding the Bokeh server as library in a python script that you start that has visibility into this entire package/directory structure, see examples/howto/server_embed

* put this module in a package that is actually installed in your site-packages

···

On Mar 20, 2019, at 11:09 AM, [email protected] wrote:

Hello,

First of all, I've searched and feel like this has been partially answered elsewhere, but I'm just trying to get a firm, final answer-- I apologize if this duplicates anything.

We've got three Bokeh apps, each of which is a fairly heavy dashboard for three different software products. The directory structure looks like this:

- parent_project_dir
    - support_files
        - support_functions_i_want_to_use.py
    - dashboard_1_app
      - main.py
      - (etc)
    - dashboard_2_app
      - main.py
      - (etc)
    - dashboard_3_app
      - main.py
      - (etc)

So far I have not managed to have a dashboard able to import the support functions. (These functions were written before these apps were apps, when they were just static scripts, and we've since converted them to have more dynamic interactivity.) I can replicate the functions within a support file under each dashboard_n_app directory, but that seems unwieldy, especially when all three need the same thing-- copying and pasting (and triplicating maintenance effort in the future) just seems wrong.

Is it correct that this is not possible? Are there options?

Thanks,
Carolyn

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/fcd92a29-4ff6-4729-848f-cad08da7bc00%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.