Skip to content

Commit 8c2ff0d

Browse files
authored
do not add requirementstxt if pyproject exists (#5185)
1 parent a28f0dc commit 8c2ff0d

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

reflex/constants/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
DefaultPorts,
4242
Expiration,
4343
GitIgnore,
44+
PyprojectToml,
4445
RequirementsTxt,
4546
)
4647
from .custom_components import CustomComponents
@@ -106,6 +107,7 @@
106107
"Page404",
107108
"PageNames",
108109
"Ping",
110+
"PyprojectToml",
109111
"Reflex",
110112
"RequirementsTxt",
111113
"RouteArgType",

reflex/constants/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ class GitIgnore(SimpleNamespace):
4949
}
5050

5151

52+
class PyprojectToml(SimpleNamespace):
53+
"""Pyproject.toml constants."""
54+
55+
# The pyproject.toml file.
56+
FILE = "pyproject.toml"
57+
58+
5259
class RequirementsTxt(SimpleNamespace):
5360
"""Requirements.txt constants."""
5461

reflex/reflex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ def _init(
8686
prerequisites.initialize_gitignore()
8787

8888
# Initialize the requirements.txt.
89-
wrote_to_requirements = prerequisites.initialize_requirements_txt()
89+
needs_user_manual_update = prerequisites.initialize_requirements_txt()
9090

9191
template_msg = f" using the {template} template" if template else ""
9292
# Finish initializing the app.
9393
console.success(
9494
f"Initialized {app_name}{template_msg}."
9595
+ (
9696
f" Make sure to add {constants.RequirementsTxt.DEFAULTS_STUB + constants.Reflex.VERSION} to your requirements.txt or pyproject.toml file."
97-
if not wrote_to_requirements
97+
if needs_user_manual_update
9898
else ""
9999
)
100100
)

reflex/utils/prerequisites.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,18 +840,24 @@ def initialize_gitignore(
840840

841841
def initialize_requirements_txt() -> bool:
842842
"""Initialize the requirements.txt file.
843-
If absent, generate one for the user.
843+
If absent and no pyproject.toml file exists, generate one for the user.
844844
If the requirements.txt does not have reflex as dependency,
845845
generate a requirement pinning current version and append to
846846
the requirements.txt file.
847847
848848
Returns:
849-
True if the requirements.txt file was created or updated, False otherwise.
849+
True if the user has to update the requirements.txt file.
850850
851851
Raises:
852852
Exit: If the requirements.txt file cannot be read or written to.
853853
"""
854854
requirements_file_path = Path(constants.RequirementsTxt.FILE)
855+
if (
856+
not requirements_file_path.exists()
857+
and Path(constants.PyprojectToml.FILE).exists()
858+
):
859+
return True
860+
855861
requirements_file_path.touch(exist_ok=True)
856862

857863
for encoding in [None, "utf-8"]:
@@ -864,12 +870,12 @@ def initialize_requirements_txt() -> bool:
864870
console.error(f"Failed to read {requirements_file_path}.")
865871
raise click.exceptions.Exit(1) from e
866872
else:
867-
return False
873+
return True
868874

869875
for line in content.splitlines():
870876
if re.match(r"^reflex[^a-zA-Z0-9]", line):
871877
console.debug(f"{requirements_file_path} already has reflex as dependency.")
872-
return True
878+
return False
873879

874880
console.debug(
875881
f"Appending {constants.RequirementsTxt.DEFAULTS_STUB} to {requirements_file_path}"
@@ -879,7 +885,7 @@ def initialize_requirements_txt() -> bool:
879885
"\n" + constants.RequirementsTxt.DEFAULTS_STUB + constants.Reflex.VERSION
880886
)
881887

882-
return True
888+
return False
883889

884890

885891
def initialize_app_directory(

0 commit comments

Comments
 (0)