Currently, the directory Library/ is treated as a hard-coded special case by the lean project-create and lean library add commands. Given that projects list the names and paths of their library dependencies and that libraries also have config.json files, it seems that dropping the hard-coded value in favor of more explicit settings/flags would be cleaner and allow users more flexibility for code organization.
This assumes that the runtime doesn't treat Library/paths as special, which I have not checked.
Current status:
is_lean_library() checks whether the argument to library add starts with "Library/" to determine its return value, and this is what the library add command uses to determine whether to add a local library or to install from pypi/nuget.
The docs say to use project-create to create a new library. [project_create] looks at whether the path to the project contains "Library/" and if so, uses the library template and puts it in Library.py (instead of main.py with the usual algo contents)
https://github.com/QuantConnect/lean-cli/blob/master/lean/commands/create_project.py#L428-L434
https://github.com/QuantConnect/lean-cli/blob/master/lean/commands/create_project.py#L455-L457
Proposed changes:
- introduce an argument to
project-create, --library to indicate that the project is intended to be a library
- when
"Library/" is in the path according to current logic, but --library is not set to true, emit warning log message
is_library_project = is-library-arg OR current logic
- modify
project-create so that it also sets is-library in config.json when creating a library
- modify
is_lean_library() in to use the field in the config rather than the path
Optional / nice-to-have changes:
- introduce
library-create command, analogous to project-create, but for creating libraries
- factor out common logic between the two commands
- add a deprecation warning log message to project-create in the library-creation path
- introduce an argument to the
library add to explicitly indicate whether the library is local or to be installed from pypi/nuget
Currently, the directory
Library/is treated as a hard-coded special case by thelean project-createandlean library addcommands. Given that projects list the names and paths of their library dependencies and that libraries also haveconfig.jsonfiles, it seems that dropping the hard-coded value in favor of more explicit settings/flags would be cleaner and allow users more flexibility for code organization.This assumes that the runtime doesn't treat
Library/paths as special, which I have not checked.Current status:
is_lean_library()checks whether the argument to library add starts with"Library/"to determine its return value, and this is what thelibrary addcommand uses to determine whether to add a local library or to install from pypi/nuget.The docs say to use
project-createto create a new library. [project_create] looks at whether the path to the project contains"Library/"and if so, uses the library template and puts it inLibrary.py(instead ofmain.pywith the usual algo contents)https://github.com/QuantConnect/lean-cli/blob/master/lean/commands/create_project.py#L428-L434
https://github.com/QuantConnect/lean-cli/blob/master/lean/commands/create_project.py#L455-L457
Proposed changes:
project-create,--libraryto indicate that the project is intended to be a library"Library/"is in the path according to current logic, but--libraryis not set to true, emit warning log messageis_library_project = is-library-arg OR current logicproject-createso that it also setsis-libraryinconfig.jsonwhen creating a libraryis_lean_library()in to use the field in the config rather than the pathOptional / nice-to-have changes:
library-createcommand, analogous toproject-create, but for creating librarieslibrary addto explicitly indicate whether the library is local or to be installed from pypi/nuget