-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate_release.py
More file actions
executable file
·102 lines (86 loc) · 3.54 KB
/
generate_release.py
File metadata and controls
executable file
·102 lines (86 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""
A script to package the project to be run by end users.
This strips down the project to the essentials, removing any unnecessary files
and folders, and zips the project for distribution.
The included files are:
- The simulator directory
- A generated VERSION file
- A readme.txt copied from the user readme
- A set of zone_X folders
- An example code file in zone_0
- A setup script to install the project into a virtual environment
"""
import logging
import os
import shutil
import subprocess
import sys
from pathlib import Path
from shutil import which
from tempfile import TemporaryDirectory
# Add the simulator directory to the path
sys.path.insert(0, str(Path(__file__).parents[1] / "simulator"))
from environment import NUM_ZONES
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
project_root = Path(__file__).parents[1]
try:
version = subprocess.check_output(
['git', 'describe', '--tags', '--always'],
cwd=str(project_root),
).decode().strip()
except subprocess.CalledProcessError:
logger.exception("Failed to get version from git")
exit(1)
(project_root / "dist").mkdir(exist_ok=True)
os.chdir(str(project_root / "dist"))
with TemporaryDirectory() as temp_dir_str:
temp_dir = Path(temp_dir_str)
logger.info("Copying simulator folder to temp directory")
shutil.copytree(project_root / "simulator", temp_dir / "simulator")
shutil.copy(project_root / "requirements.txt", temp_dir / "simulator/requirements.txt")
logger.info("Copying LICENSE to temp directory")
shutil.copy(project_root / "LICENSE", temp_dir / "LICENSE")
logger.info("Adding README to temp directory")
if which("pandoc"):
logger.info(" Converting markdown to HTML using pandoc")
subprocess.run(
[
"pandoc",
"--toc", # Add a table of contents
"--from", "gfm+definition_lists", # Use GitHub Flavored Markdown
"--shift-heading-level-by=-1", # Make the level 1 heading the title
"--self-contained", # Embed images in the HTML
"--metadata",
'pagetitle="title"',
str(project_root / "assets/user_readme.md"),
"--output",
str(temp_dir / "readme.html"),
],
cwd=str(project_root / "assets"),
check=True,
)
else:
logger.warning("Pandoc is not available, just copying markdown files")
shutil.copy(project_root / "assets/user_readme.md", temp_dir / "readme.md")
logger.info("Copying helper scripts to temp directory")
shutil.copy(project_root / "scripts/setup.py", temp_dir / "setup.py")
for script in project_root.glob("scripts/run_*.py"):
if "run_comp_" in str(script):
continue
shutil.copy(script, temp_dir)
script_dir = temp_dir / "scripts"
script_dir.mkdir()
logger.info("Copying example code to temp directory")
shutil.copytree(project_root / "example_robots", temp_dir / "example_robots")
logger.info("Creating zone folders")
for i in range(NUM_ZONES):
Path(temp_dir / f"zone_{i}").mkdir()
shutil.copy(project_root / "example_robots/basic_robot.py", temp_dir / "zone_0/robot.py")
logger.info("Creating VERSION file")
(temp_dir / "simulator/VERSION").write_text(version)
logger.info("Packaging project")
shutil.make_archive(f"sbot-simulator-{version}", "zip", temp_dir)
logger.info("Project packaged successfully")
logger.info(f"Output file: sbot-simulator-{version}.zip")