Skip to content

How can we share useful functions between demonstration notebooks when I want them to be self contained? #263

@DavidT3

Description

@DavidT3

Usually if I wanted to share functions between notebooks I'd make some common.py file and add it to the system path e.g. (ripped from one of my research notebook repos):

import pandas as pd
pd.set_option('display.max_columns', 500)
import numpy as np
from astropy.units import Quantity
from astropy.cosmology import LambdaCDM
import os

# This adds the directory above to the path, allowing me to import the common functions that I've written in
#  common.py - this just saves me repeating boring code and makes sure its all consistent
import sys
sys.path.insert(0, '..')
from common import xcs_cosmo, lx_norm, m_norm

import xga
from xga.relations.fit import scaling_relation_lira

However, I specifically diverged from how the Fornax notebooks work (and I think how IRSA does it) and don't use files to declare functions, instead they are defined in a collapsed section of the notebook.

Great, other than when we want multiple notebooks to have the same functions - then we have to maintain them in multiple places.

I don't have a good solution for this yet, other than post-processing the notebooks with a github action to replace any declarations of a commonly-named function when it changes in some centralized file where it is maintained?

Metadata

Metadata

Assignees

Labels

doc-infrastructureChanges or additions to the infrastructure to build and serve tutorials and documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions