Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export public API from Generators #633

Open
lazzarello opened this issue Mar 14, 2023 · 4 comments
Open

Export public API from Generators #633

lazzarello opened this issue Mar 14, 2023 · 4 comments

Comments

@lazzarello
Copy link

Describe the bug
Genie.Generator.microstack_app() throws a BoundsError and creates files

Error stacktrace
not indicated here, this is a new project and it began with only a Project/Manifest.toml and a README

julia> Genie.Generator.microstack_app()
ERROR: BoundsError: attempt to access 0-element Vector{SubString{String}} at index [0]
Stacktrace:
 [1] getindex
   @ ./array.jl:861 [inlined]
 [2] appmodule(path::String)
   @ Genie.FileTemplates ~/.julia/packages/Genie/IZLml/src/FileTemplates.jl:66
 [3] write_app_custom_files(path::String, app_path::String)
   @ Genie.Generator ~/.julia/packages/Genie/IZLml/src/Generator.jl:392
 [4] scaffold(app_name::String, app_path::String)
   @ Genie.Generator ~/.julia/packages/Genie/IZLml/src/Generator.jl:321
 [5] microstack_app(app_name::String, app_path::String)
   @ Genie.Generator ~/.julia/packages/Genie/IZLml/src/Generator.jl:339
 [6] microstack_app()
   @ Genie.Generator ~/.julia/packages/Genie/IZLml/src/Generator.jl:333
 [7] top-level scope
   @ REPL[6]:1

julia> Genie.Generator.microstack_app(".")
ERROR: ArgumentError: './bin' exists. `force=true` is required to remove './bin' before copying.
Stacktrace:
 [1] checkfor_mv_cp_cptree(src::String, dst::String, txt::String; force::Bool)
   @ Base.Filesystem ./file.jl:325
 [2] cp(src::String, dst::String; force::Bool, follow_symlinks::Bool)
   @ Base.Filesystem ./file.jl:364
 [3] cp
   @ ./file.jl:364 [inlined]
 [4] microstack_app(app_name::String, app_path::String)
   @ Genie.Generator ~/.julia/packages/Genie/IZLml/src/Generator.jl:336
 [5] microstack_app(app_name::String)
   @ Genie.Generator ~/.julia/packages/Genie/IZLml/src/Generator.jl:333
 [6] top-level scope
   @ REPL[7]:1

julia> readdir(".")
12-element Vector{String}:
 ".env.example"
 ".git"
 ".gitattributes"
 ".gitignore"
 "Manifest.toml"
 "Project.toml"
 "README.md"
 "bin"
 "config"
 "public"
 "routes.jl"
 "src"

To reproduce
See above. Julia 1.7.3 on Linux x86_64.

Expected behavior
There would not be an exception thrown because it appears the generator did what was expected. I'm new to Genie so I can't validate what it is supposed to do very well. There are a bunch of files there!

Additional context

(propagando.jl) pkg> st
      Status `~/src/propagando.jl/Project.toml`
  [c43c736e] Genie v5.15.0
  [eaed0597] JSpaceLibrary v0.16.1 `git@gitlab.internal.momentus.space:engineering/jspacelibrary.git#master`

julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_PKG_USE_CLI_GIT = true
@essenciary
Copy link
Member

Yup, just fixed it a few days ago, stumbled into it myself :) Need to tag a new version of Genie. I'll do it today.

@essenciary
Copy link
Member

@lazzarello this should be solved in v5.15.2 -- but beware that microstack_app won't do what you think it will do (it's meant to be an internal API). Please use newapp_webservice instead.

@lazzarello
Copy link
Author

@lazzarello this should be solved in v5.15.2 -- but beware that microstack_app won't do what you think it will do (it's meant to be an internal API). Please use newapp_webservice instead.

My reasoning went like this. I want to build an interface to do some astronomy calculations with input data from a different web service. The math is implemented in a Julia package internal to the corporation. The output is a small amount of JSON, so both sides don't expect too much data but it's high compute complexity. I don't need a database.

The word "microstack" stood out when browsing the generator interfaces. I'll try the newapp_webservice today. Thanks for your help. Only because I'm curious, what is the definition of "an internal API" in this context?

@essenciary
Copy link
Member

essenciary commented Mar 15, 2023

By internal API I mean private API. The microstack_app is used as a part of new app creation - used alone will potentially not create the right thing.

Regarding the topic of public/private scopes in Julia - I've been long supporting the idea of having these explicit. Unfortunately there is no traction.

So according to Julia, an API is public if:
a) is exported
b) is documented

Everybody agreed that b) is dumb, as private APIs also need to be documented.

That leaves a)
As a utility module, IMO it made more sense not to export functions from Generators as they'll just pollute the scope where they are used. But since it's the only way of marking public APIs, I should export them.

To conclude:

  • newapp_webservice is appropriate for your use case - but if even that is too much, you can use minimal.
  • I'll review and export the public API

@essenciary essenciary changed the title Genie.Generator.microstack_app() throws a BoundsError and creates files Export public API from Generators Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants