-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
keep app id (project hash) the same even after re-init #2195
Conversation
reflex/utils/prerequisites.py
Outdated
@@ -278,20 +278,36 @@ def initialize_app_directory(app_name: str, template: constants.Templates.Kind): | |||
) | |||
|
|||
|
|||
def get_project_hash_if_exists(): |
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.
We can call this get_project_hash
and add a type annotation
def get_project_hash_if_exists() -> str | None:
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.
fixed
reflex/utils/prerequisites.py
Outdated
@@ -278,20 +278,36 @@ def initialize_app_directory(app_name: str, template: constants.Templates.Kind): | |||
) | |||
|
|||
|
|||
def get_project_hash_if_exists(): | |||
"""Check if the reflex.json file exists in .web folder and |
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.
nit: we can simplify the docstring "Get the project hash from the reflex.json file."
the rest of the comment can go in the place where we actually do the overriding
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.
changed
reflex/utils/prerequisites.py
Outdated
data = json.load(file) | ||
project_hash = data["project_hash"] | ||
return project_hash | ||
else: |
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.
Don't need the else
since the if
returns. Also generally may be cleaner to do the early return cases first:
if not os.path.exists(...):
return None
with open ...
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.
changed
reflex/utils/prerequisites.py
Outdated
def initialize_web_directory(): | ||
"""Initialize the web directory on reflex init.""" | ||
console.log("Initializing the web directory.") | ||
|
||
path_ops.cp(constants.Templates.Dirs.WEB_TEMPLATE, constants.Dirs.WEB) | ||
project_hash = get_project_hash_if_exists() |
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.
We can add the comment here about saving the project hash so its not overridden
reflex/utils/prerequisites.py
Outdated
@@ -315,11 +331,15 @@ def initialize_package_json(): | |||
file.write(code) | |||
|
|||
|
|||
def init_reflex_json(): | |||
def init_reflex_json(project_hash): |
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.
Add type annotations, and update docstrings
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.
updated
reflex/utils/prerequisites.py
Outdated
"""Get the project hash from the reflex.json file if the file exists. | ||
|
||
Returns: | ||
project_hash (int): The app hash. |
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.
nit: don't need the (int) in the docstring as we are using type annotations
console.debug(f"Setting project hash to {project_hash}.") | ||
def init_reflex_json(project_hash: int | None): | ||
"""Write the hash of the Reflex project to a REFLEX_JSON. | ||
Re-use the hash if one is already created, therefore do not |
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.
nit: add a blank line after the first line when expanding the docstring.
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.
fixed
reflex/utils/prerequisites.py
Outdated
. | ||
|
||
Args: | ||
project_hash (int): The app hash. |
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.
Don't need the annotation here also
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.
fixed
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
After these steps, you're ready to open a pull request.