DeplanckeLab / scfair

an initiative to standardize single-cell genomics data and promote findable, accessible, interoperable, and reusable single-cell data.
0 stars 0 forks source link

autoload lib #12

Closed luxxi closed 3 weeks ago

luxxi commented 1 month ago

I stumbled upon an issue when trying to set up the project locally. The Getting Started refers to run rake api_updates which returns an error:

rake aborted!
NameError: uninitialized constant Tasks::ApisHelpers::AsapApi (NameError)

    @mod.const_get(@cname, false)
        ^^^^^^^^^^

When digging deeper, I found the issue is related to the solar reindex task sunspot:reindex. Before reindexing is performed, the library loads the Rails app https://github.com/sunspot/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/tasks.rb#L33 The same error occurs when trying to run Rails.application.eager_load! in the rails console.

After reviewing app configuration, I found this

  class Application < Rails::Application
    config.autoload_paths << Rails.root.join('lib')
    config.eager_load_paths << Rails.root.join('lib')

https://github.com/DeplanckeLab/scfair/blob/main/src/config/application.rb#L16-L17, which seems to be the root of the issue. Following the Rails documentation:

While assets and tasks share the lib directory with regular Ruby code, their contents are not meant to be reloaded or eager loaded. https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#config-autoload-lib-ignore

I suggest we remove /lib folder from autoload and eager load paths.

fab-dav commented 1 month ago

Yes, I agree about this. These 2 lines can cause problems and are not necessary. I checked other similar projects and they were not present. Thanks for pointing this issue and solving it!