-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[components] [RFC] Overhaul DgConfig, replace is_{workspace,project,component_lib}
with type
field
#28002
base: master
Are you sure you want to change the base?
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
is_{workspace,project,component_lib}
with type
field
def _get_literal_values(type_: Any) -> tuple[object, ...]: | ||
val = type_ | ||
while get_origin(val) is not Literal: | ||
val = get_origin(type_) | ||
return get_args(val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a bug in the _get_literal_values()
function where the while
loop uses get_origin(type_)
instead of get_origin(val)
. This creates an infinite loop since type_
never changes. The line should be:
val = get_origin(val)
This will properly traverse the type hierarchy until reaching the Literal
type.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
|
||
|
||
def _raise_missing_required_key_error(key: str, type_str: str) -> Never: | ||
raise DgValidationError(f"`Missing required value for `{key}`. Expected {type_str}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a misplaced backtick in the error message string. The current message:
f"`Missing required value for `{key}`. Expected {type_str}."
Should be:
f"Missing required value for `{key}`. Expected {type_str}."
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
if not isinstance(section, dict): | ||
raise DgValidationError("`tool.dg.project` must be a table.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message in this function incorrectly references tool.dg.project
when validating a library section. Since this is the _validate_file_config_library_section
function, the error message should reference tool.dg.library
instead.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
def default(cls) -> Self: | ||
return cls(DgGlobalConfig.default()) | ||
|
||
# Note that this funciton takes an argument called `container_workspace_file_config` instead of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo in comment: funciton
should be function
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this eliminate the case where a project is also a component library?
Since writing this my thinking has evolved on "library". See my thoughts here: TLDR I'd like to change this PR to eliminate the "library" type, there should just be "workspace" and "project". |
Summary & Motivation
Overhaul the
dg
config system. This is essential for a stable foundation going forward.Status quo
The config system reads config from three sources and merges them all together.
Even though the kinds of options you can set in these different locations differ (for example, you can't set
is_workspace
from the CLI), they are currently all treated as having the same type. This:The implicit complexity will become a problem as we scale.
This PR
type
argument specifying the "directory type" instead of setting booleans (is_workspace
,is_project
,is_component_library
). There are only three types:"workspace"
"project"
"library"
tool.dg.project
: this is required whentool.dg.type = "project"
. At a minimum you must specify the root package name of your project (comes automatically in scaffolding).package_name
components_package_name
(defaults to<package_name>.components
)components_lib_package_name
(defaults to<package_name>.lib
)tool.dg.library
: this is required whentool.dg.type = "library"
. At a minimum you must specify the root package name of your library (comes automatically in scaffolding).package_name
components_lib_package_name
tool.dg.workspace
does not exist, because there are no settings yet specific to the workspace.tool.dg.global
takes global settings, the same stuff you pass on the command line,verbose
etc.global
: always definedproject
only defined in a project contextlibrary
only defined in a library contextExample workspace config:
Example project config:
Example library config:
Planning on an additional upstack PR that breaks up
DgContext
with constituentWorkspace
,Project
, andLibrary
objects, which is easy with the new sectioned config.How I Tested These Changes
Added unit tests.