Ray Chen commited on
Commit
2c54808
·
1 Parent(s): f88035d

new: --deployer to use different space in dev mode

Browse files

In dev mode, if deployer has his/her specified space config, it will deploy to which space instead of the default one.

.github/tools/config.py CHANGED
@@ -21,7 +21,7 @@ PRODUCTION_SPACE_CONFIG: Dict[ProductionSpace, Config] = {
21
  }
22
  }
23
 
24
- UserName = Literal["default"]
25
 
26
  DEV_SPACE_CONFIG: Dict[UserName, Config] = {
27
  "default": {
@@ -38,4 +38,18 @@ DEV_SPACE_CONFIG: Dict[UserName, Config] = {
38
  "pinned": False,
39
  },
40
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  }
 
21
  }
22
  }
23
 
24
+ UserName = Literal["default", "jhihruei"]
25
 
26
  DEV_SPACE_CONFIG: Dict[UserName, Config] = {
27
  "default": {
 
38
  "pinned": False,
39
  },
40
  },
41
+ "jhihruei": {
42
+ "space_name": "personal-dev",
43
+ "space_owner": "jy-raychen",
44
+ "space_readme": {
45
+ "title": "Personal Developing",
46
+ "emoji": "🏢",
47
+ "color_from": "yellow",
48
+ "color_to": "indigo",
49
+ "sdk": "gradio",
50
+ "sdk_version": "4.21.0",
51
+ "app_file": "app.py",
52
+ "pinned": False,
53
+ },
54
+ },
55
  }
.github/tools/deploy_to_space.py CHANGED
@@ -33,12 +33,23 @@ if __name__ == "__main__":
33
  parser.add_argument("--username", required=True)
34
  parser.add_argument("--user_token", required=True)
35
  parser.add_argument("--mode", required=True, choices=["prod", "dev"])
 
 
 
 
36
  args = parser.parse_args()
37
 
38
- if args.mode == "prod":
39
- space = Space(PRODUCTION_SPACE_CONFIG["production"])
40
- elif args.mode == "dev":
41
- space = Space(DEV_SPACE_CONFIG["default"])
 
 
 
 
 
 
 
42
 
43
  push_result = force_push_to_remote(
44
  space, args.username, args.user_token, args.branch_name
 
33
  parser.add_argument("--username", required=True)
34
  parser.add_argument("--user_token", required=True)
35
  parser.add_argument("--mode", required=True, choices=["prod", "dev"])
36
+ parser.add_argument(
37
+ "--deployer",
38
+ help="The actor in Github Actions, it used to choose space config in dev mode.",
39
+ )
40
  args = parser.parse_args()
41
 
42
+ try:
43
+ if args.mode == "prod":
44
+ space = Space(PRODUCTION_SPACE_CONFIG["production"])
45
+ elif args.mode == "dev":
46
+ space_config = DEV_SPACE_CONFIG.get(
47
+ args.deployer, DEV_SPACE_CONFIG["default"]
48
+ )
49
+ space = Space(space_config)
50
+ except Exception:
51
+ print("Error: The space is not set correctly!")
52
+ sys.exit(1)
53
 
54
  push_result = force_push_to_remote(
55
  space, args.username, args.user_token, args.branch_name
.github/tools/generate_readme.py CHANGED
@@ -27,12 +27,23 @@ if __name__ == "__main__":
27
  description="Generate Hugging Face space config file (i.e. README.md)."
28
  )
29
  parser.add_argument("--mode", required=True, choices=["prod", "dev"])
 
 
 
 
30
  args = parser.parse_args()
31
 
32
- if args.mode == "prod":
33
- space = Space(PRODUCTION_SPACE_CONFIG["production"])
34
- elif args.mode == "dev":
35
- space = Space(DEV_SPACE_CONFIG["default"])
 
 
 
 
 
 
 
36
 
37
  readme = readme_template(space.readme)
38
  print(readme)
 
27
  description="Generate Hugging Face space config file (i.e. README.md)."
28
  )
29
  parser.add_argument("--mode", required=True, choices=["prod", "dev"])
30
+ parser.add_argument(
31
+ "--deployer",
32
+ help="The actor in Github Actions, it used to choose space config in dev mode.",
33
+ )
34
  args = parser.parse_args()
35
 
36
+ try:
37
+ if args.mode == "prod":
38
+ space = Space(PRODUCTION_SPACE_CONFIG["production"])
39
+ elif args.mode == "dev":
40
+ space_config = DEV_SPACE_CONFIG.get(
41
+ args.deployer, DEV_SPACE_CONFIG["default"]
42
+ )
43
+ space = Space(space_config)
44
+ except Exception:
45
+ print("Error: The space is not set correctly!")
46
+ sys.exit(1)
47
 
48
  readme = readme_template(space.readme)
49
  print(readme)