# Export works but not when \`\] add\` package

**URL:** https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030
**Category:** New to Julia
**Tags:** question, package, debugging, github
**Created:** [July 14, 2024, 1:45pm UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030 "2024-07-14T13:45:53Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)
#### Post date: [July 14, 2024, 1:45pm UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/1 "2024-07-14T13:45:53Z")

</div>

I am on this one for too long and can’t fix it yet 🥲 😆  
A MWE is not productible unfortunately

file `RingStarProblems.jl` contains:

```julia
module RingStarProblems
    if "JULIA_REGISTRYCI_AUTOMERGE" in keys(ENV) && ENV["JULIA_REGISTRYCI_AUTOMERGE"]

    else
          ### Some code
          ### Some usings
          using Gurobi 
         ...
          ### Some includes
          include("options.jl")
          ...

          export Both
   end
end

```

The following works, that’s great! (i.e., git clone then activating the package and launching it)

```julia
➜ tmp git clone git@github.com:jkhamphousone/RingStarProblems.jl.git
Cloning into 'RingStarProblems.jl'...
remote: Enumerating objects: 3410, done.
[...] # Some git clone infos
➜ tmp cd RingStarProblems.jl 
➜ RingStarProblems.jl git:(main) julia -t auto -q 
julia> import Pkg ; Pkg.activate(".") ; using Revise ; import RingStarProblems as RSP
  Activating project at `~/Desktop/tmp/RingStarProblems.jl`
Precompiling RingStarProblems
        Info Given RingStarProblems was explicitly requested, output will be shown live 
[ Info: Loading Revise, Aqua
[ Info: Loading JuMP
[ Info: Loading Gurobi
[...] # Some outputs

julia> pars = RSP.SolverParameters(
               solve_mod = RSP.Both(), # ILP, B&BC or Both
               sp_solve = RSP.Poly(),
               writeresults = RSP.WHTML(), # output results locally, html or no output ""
               o_i = 0, # opening costs
               s_ij = RSP.Euclidian(), # star costs
               r_ij = RSP.Euclidian(), # ring costs
               backup_factor = 0.01, # backup_factor c'=0.01c and d'=0.01c
               do_plot = false, # plot_results (to debug)
               two_opt = 0, # use two_opt heuristic (not functional yet)
               tildeV = 100, # uncertain nodes set
               timelimit = 120, # Gurobi TL
               log_level = 1, # console output log_level
               redirect_stdio = false, # redirecting_stdio to output file
               F = 183, # total failing time F, see PhD manuscript
               use_blossom = false, # use blossom inequalities (not functional yet)
               alphas = [3], # See [Labbé et al., 2004](ttps://doi.org/10.1002/net.10114)
               nthreads = 4, # Number of threads used in GUROBI, set 0 for maximum number of available threads
               ucstrat = 4 # user cut strategy
              )
RingStarProblems.SolverParameters
  solve_mod: RingStarProblems.Options.SolveMod.Both RingStarProblems.Options.SolveMod.Both()
  sp_solve: RingStarProblems.Options.SPSolve.Poly RingStarProblems.Options.SPSolve.Poly()
  tildeV: Int64 100
  alphas: Array{Int64}((1,)) [3]
  F: Float64 183.0
  warm_start: Array{Int64}((0,)) Int64[]
  inst_trans: Int64 2
  ucstrat: Int64 4
  ucstrat_limit: Int64 2000
  uctolerance: Float64 0.01
  timelimit: Int64 120
  nthreads: Int64 4
  writeresults: RingStarProblems.Options.WResults.WHTML RingStarProblems.Options.WResults.WHTML()
  nrand: Int64 0
  o_i: Int64 0
  s_ij: RingStarProblems.Options.Costs.Euclidian RingStarProblems.Options.Costs.Euclidian()
  r_ij: RingStarProblems.Options.Costs.Euclidian RingStarProblems.Options.Costs.Euclidian()
  backup_factor: Float64 0.01
  nb_runrand: Tuple{Int64, Int64}
  two_opt: Int64 0
  do_plot: Bool false
  log_level: Int64 1
  lp_relaxation: Bool false
  assert: Bool true
  write_log: Bool false
  post_procedure: Bool true
  F_interval: Tuple{Float64, Float64}
  redirect_stdio: Bool false
  use_blossom: Bool false
  gFreuse_lazycons: Bool true

julia>

```

While the following doesn’t: (i.e., ] add the package then lauching it)

```julia
(@v1.10) pkg> add RingStarProblems
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.10/Project.toml`
  No Changes to `~/.julia/environments/v1.10/Manifest.toml`
Precompiling project...
  1 dependency successfully precompiled in 8 seconds. 231 already precompiled.
  1 dependency had output during precompilation:
┌ RingStarProblems
│ [ Info: Loading Revise
│ [ Info: Loading JuMP
│ [ Info: Loading Gurobi
...

julia> import RingStarProblems as RSP

julia> pars = RSP.SolverParameters(
               solve_mod = RSP.Both(), # ILP, B&BC or Both
               sp_solve = RSP.Poly(),
               writeresults = RSP.WHTML(), # output results locally, html or no output ""
               o_i = 0, # opening costs
               s_ij = RSP.Euclidian(), # star costs
               r_ij = RSP.Euclidian(), # ring costs
               backup_factor = 0.01, # backup_factor c'=0.01c and d'=0.01c
               do_plot = false, # plot_results (to debug)
               two_opt = 0, # use two_opt heuristic (not functional yet)
               tildeV = 100, # uncertain nodes set
               timelimit = 120, # Gurobi TL
               log_level = 1, # console output log_level
               redirect_stdio = false, # redirecting_stdio to output file
               F = 183, # total failing time F, see PhD manuscript
               use_blossom = false, # use blossom inequalities (not functional yet)
               alphas = [3], # See [Labbé et al., 2004](ttps://doi.org/10.1002/net.10114)
               nthreads = 4, # Number of threads used in GUROBI, set 0 for maximum number of available threads
               ucstrat = 4 # user cut strategy
              )
ERROR: UndefVarError: `Both` not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:31
 [2] top-level scope
   @ REPL[3]:1

julia>

```

I am lost on this one. I don’t get why it works with `git clone` and activating the project but not with `] add` while the code did not change.  
Could someone help if you please ? 😃

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [July 14, 2024, 3:35pm UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/2 "2024-07-14T15:35:54Z")

</div>

The code that was registered is here: [GitHub - jkhamphousone/RingStarProblems.jl at c14a9c89357d388e2976b07857574c2c55f199f8](https://github.com/jkhamphousone/RingStarProblems.jl/tree/c14a9c89357d388e2976b07857574c2c55f199f8) (v0.1.0). Since you’ve made changes since then, you will get those by adding the URL (which gives the latest in-development version), but not adding by name (which gives the latest registered version).

---

<div class="post-metadata">

### Author: ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)
#### Post date: [July 14, 2024, 4:14pm UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/3 "2024-07-14T16:14:14Z")

</div>

@ericphanson Thanks!!! You are my today rescuer hahaha! Can continue the developments now 😃

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 15, 2024, 6:09am UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/4 "2024-07-15T06:09:41Z")

</div>

Out of curiosity, what is the rationale behind this conditional statement inside your main module? That’s rather unusual and it makes me think there might be a better solution for whatever it is you want to do

---

<div class="post-metadata">

### Author: ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)
#### Post date: [July 15, 2024, 6:52am UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/5 "2024-07-15T06:52:01Z")

</div>

Dear Guillaume, thank you so much for your input that might improve my code!

I am testing if the environment variable `"JULIA_REGISTRYCI_AUTOMERGE"` exists and is true because when I was registering the version 0.1.0 of my package (the first one), there was at some point an error thrown by [AutoMerge bot](https://github.com/JuliaRegistries/General/pull/110600). I believe this is because I am using Gurobi.jl which is a proprietary software.

From the README:  
" My package fails to load because it needs proprietary software/additional setup to work, what can I do?

Before merging a pull request, AutoMerge will check that your package can be installed and loaded. It is OK for your package to not be fully functional, but making it at least load successfully would streamline registration, as it does not require manual intervention from the registry maintainers. This would also let other packages depend on it, and use its functionalities only when the proprietary software is available in the system, as done for example by the [`CUDA.jl`](https://github.com/JuliaGPU/CUDA.jl) package. If you are not able or willing to make your package always loadable without the proprietary dependency (which is the preferred solution), you can check if the environment variable `JULIA_REGISTRYCI_AUTOMERGE` is equal to `true` and make your package loadable during AutoMerge at least, so that it can be registered without manual intervention. Examples of packages with proprietary software that use the environment variable check include [`Gurobi.jl`](https://github.com/jump-dev/Gurobi.jl) and [`CPLEX.jl`](https://github.com/jump-dev/CPLEX.jl)."

Note that in `RingStarProblems.jl`, as suggested in an issue, we should probably work on depending on MathOptInterface instead of relying on JuMP and specific solvers.

On a side small note I should replace:

```julia
    if "JULIA_REGISTRYCI_AUTOMERGE" in keys(ENV) && ENV["JULIA_REGISTRYCI_AUTOMERGE"]

    else
          ### Some code
          ### Some usings
          using Gurobi 
         ...
          ### Some includes
          include("options.jl")
          ...

          export Both
   end

```

With:

```julia
    if !("JULIA_REGISTRYCI_AUTOMERGE" in keys(ENV) && ENV["JULIA_REGISTRYCI_AUTOMERGE"]) # TODO: try to see if removing it works on next registration
          ### Some code
          ### Some usings
          using Gurobi 
         ...
          ### Some includes
          include("options.jl")
          ...
          export Both
      
   end

```

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 15, 2024, 7:39am UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/6 "2024-07-15T07:39:07Z")

</div>

So you’re cheating the automerge bot by registering what is essentially an empty package? That doesn’t seem like a good solution.  
I would recommend making the solver parametric in your code (which is very easy with JuMP), and picking HiGHS.jl as the default. Users can then switch to Gurobi if they are able to get a license, and that way GitHub CI will be happy too.

---

<div class="post-metadata">

### Author: ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)
#### Post date: [July 15, 2024, 7:48am UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/7 "2024-07-15T07:48:57Z")

</div>

Thank you for this good idea @gdalle 😃 I [opened an issue](https://github.com/jkhamphousone/RingStarProblems.jl/issues/11) on my repository and will try to code what you suggested!

---

<div class="post-metadata">

### Author: ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)
#### Post date: [July 15, 2024, 8:00am UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/8 "2024-07-15T08:00:06Z")

</div>

@gdalle  
However, I think it will not be possible to use HiGHS.jl because [my solver uses callbacks for the Branch and Benders cut method.](https://jump.dev/JuMP.jl/stable/manual/callbacks/):

> ## [Available solvers](https://jump.dev/JuMP.jl/stable/manual/callbacks/#Available-solvers)
> 
> Solver-independent callback support is limited to a few solvers. This includes [CPLEX](https://github.com/jump-dev/CPLEX.jl), [GLPK](https://github.com/jump-dev/GLPK.jl), [Gurobi](https://github.com/jump-dev/Gurobi.jl), [Xpress](https://github.com/jump-dev/Xpress.jl), and [SCIP](https://github.com/scipopt/SCIP.jl).

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 15, 2024, 8:04am UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/9 "2024-07-15T08:04:43Z")

</div>

Then pick another open source solver like SCIP.jl?

---

<div class="post-metadata">

### Author: ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)
#### Post date: [July 16, 2024, 6:11pm UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/10 "2024-07-16T18:11:08Z")

</div>

@gdalle, thank you so much for suggesting the open-source SCIP.jl! [Turns out, I can’t use it too](https://discourse.julialang.org/t/lazy-constraints-are-not-supported-by-scip-jl-while-jump-doesnt-mention-it/117110/2) 😅 I’ll have a look at GLPK soon 😃

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [July 17, 2024, 1:16am UTC](https://discourse.julialang.org/t/export-works-but-not-when-add-package/117030/11 "2024-07-17T01:16:46Z")

</div>

GLPK is open-source and supports callbacks.

See [Benders decomposition · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/algorithms/benders_decomposition/#Callback-method)
