浏览代码

do not add requirementstxt if pyproject exists (#5185)

Khaleel Al-Adhami 2 周之前
父节点
当前提交
8c2ff0d97b
共有 4 个文件被更改,包括 22 次插入7 次删除
  1. 2 0
      reflex/constants/__init__.py
  2. 7 0
      reflex/constants/config.py
  3. 2 2
      reflex/reflex.py
  4. 11 5
      reflex/utils/prerequisites.py

+ 2 - 0
reflex/constants/__init__.py

@@ -41,6 +41,7 @@ from .config import (
     DefaultPorts,
     Expiration,
     GitIgnore,
+    PyprojectToml,
     RequirementsTxt,
 )
 from .custom_components import CustomComponents
@@ -106,6 +107,7 @@ __all__ = [
     "Page404",
     "PageNames",
     "Ping",
+    "PyprojectToml",
     "Reflex",
     "RequirementsTxt",
     "RouteArgType",

+ 7 - 0
reflex/constants/config.py

@@ -49,6 +49,13 @@ class GitIgnore(SimpleNamespace):
     }
 
 
+class PyprojectToml(SimpleNamespace):
+    """Pyproject.toml constants."""
+
+    # The pyproject.toml file.
+    FILE = "pyproject.toml"
+
+
 class RequirementsTxt(SimpleNamespace):
     """Requirements.txt constants."""
 

+ 2 - 2
reflex/reflex.py

@@ -86,7 +86,7 @@ def _init(
     prerequisites.initialize_gitignore()
 
     # Initialize the requirements.txt.
-    wrote_to_requirements = prerequisites.initialize_requirements_txt()
+    needs_user_manual_update = prerequisites.initialize_requirements_txt()
 
     template_msg = f" using the {template} template" if template else ""
     # Finish initializing the app.
@@ -94,7 +94,7 @@ def _init(
         f"Initialized {app_name}{template_msg}."
         + (
             f" Make sure to add {constants.RequirementsTxt.DEFAULTS_STUB + constants.Reflex.VERSION} to your requirements.txt or pyproject.toml file."
-            if not wrote_to_requirements
+            if needs_user_manual_update
             else ""
         )
     )

+ 11 - 5
reflex/utils/prerequisites.py

@@ -840,18 +840,24 @@ def initialize_gitignore(
 
 def initialize_requirements_txt() -> bool:
     """Initialize the requirements.txt file.
-    If absent, generate one for the user.
+    If absent and no pyproject.toml file exists, generate one for the user.
     If the requirements.txt does not have reflex as dependency,
     generate a requirement pinning current version and append to
     the requirements.txt file.
 
     Returns:
-        True if the requirements.txt file was created or updated, False otherwise.
+        True if the user has to update the requirements.txt file.
 
     Raises:
         Exit: If the requirements.txt file cannot be read or written to.
     """
     requirements_file_path = Path(constants.RequirementsTxt.FILE)
+    if (
+        not requirements_file_path.exists()
+        and Path(constants.PyprojectToml.FILE).exists()
+    ):
+        return True
+
     requirements_file_path.touch(exist_ok=True)
 
     for encoding in [None, "utf-8"]:
@@ -864,12 +870,12 @@ def initialize_requirements_txt() -> bool:
             console.error(f"Failed to read {requirements_file_path}.")
             raise click.exceptions.Exit(1) from e
     else:
-        return False
+        return True
 
     for line in content.splitlines():
         if re.match(r"^reflex[^a-zA-Z0-9]", line):
             console.debug(f"{requirements_file_path} already has reflex as dependency.")
-            return True
+            return False
 
     console.debug(
         f"Appending {constants.RequirementsTxt.DEFAULTS_STUB} to {requirements_file_path}"
@@ -879,7 +885,7 @@ def initialize_requirements_txt() -> bool:
             "\n" + constants.RequirementsTxt.DEFAULTS_STUB + constants.Reflex.VERSION
         )
 
-    return True
+    return False
 
 
 def initialize_app_directory(