@@ -11,6 +11,51 @@ class DEFAULT:
1111 pass
1212
1313
14+ # Representing constructors ===================================================
15+
16+ # Note that this is not a constructor, but a function to represent them.
17+ def board_deparse (board : BaseBoard ):
18+ """Return a representation of how a board could be reconstructed.
19+
20+ Note that this function does not try to represent the exact arguments used
21+ to construct a board, but key pieces (like the path to the board). You may
22+ need to specify environment variables with API keys to complete the connection.
23+
24+ Parameters
25+ ----------
26+ board:
27+ A pins board to be represented.
28+
29+ Examples
30+ --------
31+
32+ The example below deparses a board connected to RStudio Connect.
33+
34+ >>> board_deparse(board_rsconnect(server_url="http://example.com", api_key="xxx"))
35+ "board_rsconnect(server_url='http://example.com')"
36+
37+ Note that the deparsing an RStudio Connect board does not keep the api_key,
38+ which is sensitive information. In this case, you can set the CONNECT_API_KEY
39+ environment variable to connect.
40+
41+ Below is an example of representing a board connected to a local folder.
42+
43+ >>> board_deparse(board_folder("a/b/c"))
44+ "board_folder('a/b/c')"
45+ """
46+
47+ prot = board .fs .protocol
48+ if prot == "rsc" :
49+ url = board .fs .api .server_url
50+ return f"board_rsconnect(server_url={ repr (url )} )"
51+ elif prot == "file" :
52+ return f"board_folder({ repr (board .board )} )"
53+ else :
54+ raise NotImplementedError (
55+ "board deparsing currently not supported for protocol: {prot}"
56+ )
57+
58+
1459# Board constructors ==========================================================
1560# note that libraries not used by board classes above are imported within these
1661# functions. may be worth moving these funcs into their own module.
0 commit comments