File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 80
80
produce_bootstrap_output ,
81
81
parse_client_response ,
82
82
)
83
- from .shiny_express import is_express_app
83
+ from .shiny_express import escape_to_var_name , is_express_app
84
84
85
85
server_store = ServerStore ()
86
86
future_enabled = False
@@ -1424,8 +1424,7 @@ def deploy_app(
1424
1424
)
1425
1425
1426
1426
if is_express_app (entrypoint + ".py" , directory ):
1427
- env_vars ["SHINY_EXPRESS_APP_FILE" ] = entrypoint + ".py"
1428
- entrypoint = "shiny.express.app"
1427
+ entrypoint = "shiny.express.app:" + escape_to_var_name (entrypoint + ".py" )
1429
1428
1430
1429
extra_args = dict (
1431
1430
directory = directory ,
Original file line number Diff line number Diff line change 5
5
6
6
import ast
7
7
from pathlib import Path
8
+ import re
8
9
9
10
__all__ = ("is_express_app" ,)
10
11
@@ -72,3 +73,27 @@ def visit_Module(self, node: ast.Module):
72
73
# Don't recurse into any nodes, so the we'll only ever look at top-level nodes.
73
74
def generic_visit (self , node : ast .AST ):
74
75
pass
76
+
77
+
78
+ def escape_to_var_name (x : str ) -> str :
79
+ """
80
+ Given a string, escape it to a valid Python variable name which contains
81
+ [a-zA-Z0-9_]. All other characters will be escaped to _<hex>_. Also, if the first
82
+ character is a digit, it will be escaped to _<hex>_, because Python variable names
83
+ can't begin with a digit.
84
+ """
85
+ encoded = ""
86
+ is_first = True
87
+
88
+ for char in x :
89
+ if is_first and re .match ("[0-9]" , char ):
90
+ encoded += f"_{ ord (char ):x} _"
91
+ elif re .match ("[a-zA-Z0-9]" , char ):
92
+ encoded += char
93
+ else :
94
+ encoded += f"_{ ord (char ):x} _"
95
+
96
+ if is_first :
97
+ is_first = False
98
+
99
+ return encoded
You can’t perform that action at this time.
0 commit comments