# Creating a module that chooses different files

**URL:** <https://discourse.julialang.org/t/creating-a-module-that-chooses-different-files/129152>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 19, 2025, 4:41pm UTC](https://discourse.julialang.org/t/creating-a-module-that-chooses-different-files/129152 "2025-05-19T16:41:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [May 19, 2025, 4:41pm UTC](https://discourse.julialang.org/t/creating-a-module-that-chooses-different-files/129152/1 "2025-05-19T16:41:53Z")

</div>

Hi all.  
I have written a module to process some data. Depending on the computer where it is running I would like to use different files for the plotting. If we are using a normal computer with a screen I would like to use “vizGL.jl” that runs with GLMakie. In the case he computer is headless I want to call “vizCairo.jl”.

I tried this:

```julia

 module DASVader
 
 include("headless2.jl")
 
 if has_graphical_display() == true
     include("vizGL.jl")
     @info "Working on graphical mode"
 else
     include("vizCairo.jl")
     @info "Working on headless mode"
 end
 
 include("tandf.jl")
 include("wmatrix.jl")
 include("filemanagement.jl")
 include("xandw.jl")
 include("detectiontools.jl")
 include("Findpeaks.jl")
 include("myspectogram.jl")
 include("myspectra.jl")
 include("datasrc.jl")
 include("interface.jl")
 
 end

```

But it does not work :(.

headless2.jl is like this:

```julia

function env_has_display()
    if Sys.islinux()
        return !isempty(get(ENV, "DISPLAY", "")) || !isempty(get(ENV, "WAYLAND_DISPLAY", ""))
    elseif Sys.iswindows() || Sys.isapple()
        return true # Assume GUI unless proven otherwise
    else
        return false
    end
end

function glmakie_screen_available()
    try
        @eval using GLMakie # Delay loading to avoid errors
        s = GLMakie.Screen()
        close(s)
        return true
    catch
        return false
    end
end

function has_graphical_display()
    env_has_display() && glmakie_screen_available()
end

export has_graphical_display, glmakie_screen_available, env_has_display

```

Any idea?

---

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [May 19, 2025, 8:23pm UTC](https://discourse.julialang.org/t/creating-a-module-that-chooses-different-files/129152/2 "2025-05-19T20:23:14Z")

</div>

You could try adding `@static`:

```julia
@static if has_graphical_display() == true
     include("vizGL.jl")
     @info "Working on graphical mode"
 else
     include("vizCairo.jl")
     @info "Working on headless mode"
 end

```

This means that the if statement will be run at parse time, effectively just leaving the branch that you want. E.g.

```julia
julia> @macroexpand @static if Sys.isapple() ; include("macOS.jl") ; else include("everythingelse.jl") ; end
quote
    #= REPL[4]:1 =#
    include("macOS.jl")
end

```

But any result will be cached (if this is in a package) and will not change for that machine even if an environment variable changes. (Which may or may not be what you want.)

---

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [May 20, 2025, 12:14pm UTC](https://discourse.julialang.org/t/creating-a-module-that-chooses-different-files/129152/3 "2025-05-20T12:14:39Z")

</div>

HI @dawbarton .

I just noticed that my problem is much bigger thatn this. In the Project file, I cannot have GLMakie as a dependency while working on the server :(. I am rather lost here
