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

keep app id (project hash) the same even after re-init #2195

Merged
merged 4 commits into from
Nov 20, 2023

Conversation

tgberkeley
Copy link
Collaborator

@tgberkeley tgberkeley commented Nov 17, 2023

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

After these steps, you're ready to open a pull request.

a. Give a descriptive title to your PR.

b. Describe your changes.

c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such).

@tgberkeley tgberkeley requested a review from picklelo November 17, 2023 23:41
@@ -278,20 +278,36 @@ def initialize_app_directory(app_name: str, template: constants.Templates.Kind):
)


def get_project_hash_if_exists():
Copy link
Contributor

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:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -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
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

data = json.load(file)
project_hash = data["project_hash"]
return project_hash
else:
Copy link
Contributor

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 ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

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()
Copy link
Contributor

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

@@ -315,11 +331,15 @@ def initialize_package_json():
file.write(code)


def init_reflex_json():
def init_reflex_json(project_hash):
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

"""Get the project hash from the reflex.json file if the file exists.

Returns:
project_hash (int): The app hash.
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

.

Args:
project_hash (int): The app hash.
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@picklelo picklelo merged commit 5198dae into main Nov 20, 2023
45 checks passed
@masenf masenf deleted the tracking-retention branch December 6, 2023 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants