Hey all,
I’ve recently started digging into Julia and am trying to implement some of my Python projects in Julia in order to get used to the language (these are mainly data science related projects). There is a lot I like out of the box but am currently struggling to structure a Project I’m working on.
This is how I usually structure my Python projects (which shares similarity to Julia’s Package structure):
…/ProjectName/
├── src/
│ ├── definitions.py (contains constants)
│ ├── train.py
│ ├── lib/
│ │ ├── dataset.py
│ │ ├── helpers.py
│ ├── models/
│ │ ├── modela.py
│ │ ├── modelb.py
├── data/…
├── results/…
├── tests/…
├── poetry.lock
├── pyproject.toml
├── README
How I work through this process:
I first define constants in definitions.py, usually absolute paths to the contents of the data/, results/ folders etc.
This file exports a Dict:
# from src/definitions.py
PATH = {"data1" : "somePath", ...}
I can then import this variable in dataset.py by:
# from src/lib/dataset.py
from src.definitions import PATH
print(PATH)
I can run this file to check its output by running:
$ poetry shell # activates virtual env
(myEnv) $ python -m src.lib.dataset # -m meaning run from module perspective
PATH("A": "somePath")
Say I have the exact same setup for a Julia project, I am then facing two issues doing the same:
- How do I enter the correct Pkg environment from bash? If I execute
$ julia src/lib/dataset.jl
It will run that file from my global julia installation, and not from my environment.
Others suggested opening Julia in the bash, setting the environment with activate .
and then using include(“src/lib/dataset.jl”) to “run” the file. I really don’t like this, is there a more straightforward method to do this?
- How can I import from top-level files from within sub-directories?
An obvious way is to just run
# from src/lib/dataset.jl
include("../definitions.jl")
print(PATH)
But it makes sense that a lot of files import from this file, so I would not like to use include.
I have since been messing with making all the files in my directory modules and attempting to import those modules from sub-dirs but to no avail. Also that seems like a lot of boilerplate to just import some variables…
A true package of course defines a MyPackage.jl, and exposes all it’s contents by include and exports. But I don’t really see that being very intuitive for data science projects.
I want to run something like:
# from src/lib/dataset.jl
import definitions: PATH # or src.definitions: PATH
Anyone who has any suggestions for tackling this?