Skip to content

Commit 0b6ca7c

Browse files
authored
Merge branch 'main' into optimized_vmobject_points
2 parents 35d04d4 + 28bf4dd commit 0b6ca7c

File tree

300 files changed

+5237
-2943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+5237
-2943
lines changed

.flake8

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[flake8]
22
# Exclude the grpc generated code
3-
exclude = ./manim/grpc/gen/*
3+
exclude = ./manim/grpc/gen/*, __pycache__,.git,
4+
per-file-ignores = __init__.py:F401
45
max-complexity = 15
56
max-line-length = 88
67
statistics = True
@@ -9,7 +10,7 @@ rst-roles = attr,class,func,meth,mod,obj,ref,doc,exc
910
rst-directives = manim, SEEALSO, seealso
1011
docstring-convention=numpy
1112

12-
select = A,A00,B,B9,C4,C90,D,E,F,F,PT,RST,SIM,W
13+
select = A,A00,B,B9,C4,C90,D,E,F,F,PT,RST,SIM,W,F401
1314

1415
# General Compatibility
1516
extend-ignore = E203, W503, D202, D212, D213, D404
@@ -40,4 +41,4 @@ extend-ignore = E203, W503, D202, D212, D213, D404
4041

4142
# Plug-in: flake8-rst-docstrings
4243
RST201, RST203, RST210, RST212, RST213, RST215,
43-
RST301, RST303,
44+
RST301, RST303, RST499

.github/scripts/ci_build_cairo.py

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Logic is as follows:
2+
# 1. Download cairo source code: https://cairographics.org/releases/cairo-<version>.tar.xz
3+
# 2. Verify the downloaded file using the sha256sums file: https://cairographics.org/releases/cairo-<version>.tar.xz.sha256sum
4+
# 3. Extract the downloaded file.
5+
# 4. Create a virtual environment and install meson and ninja.
6+
# 5. Run meson build in the extracted directory. Also, set required prefix.
7+
# 6. Run meson compile -C build.
8+
# 7. Run meson install -C build.
9+
10+
import hashlib
11+
import logging
12+
import os
13+
import subprocess
14+
import sys
15+
import tarfile
16+
import tempfile
17+
import typing
18+
import urllib.request
19+
from contextlib import contextmanager
20+
from pathlib import Path
21+
from sys import stdout
22+
23+
CAIRO_VERSION = "1.18.0"
24+
CAIRO_URL = f"https://cairographics.org/releases/cairo-{CAIRO_VERSION}.tar.xz"
25+
CAIRO_SHA256_URL = f"{CAIRO_URL}.sha256sum"
26+
27+
VENV_NAME = "meson-venv"
28+
BUILD_DIR = "build"
29+
INSTALL_PREFIX = Path(__file__).parent.parent.parent / "third_party" / "cairo"
30+
31+
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
32+
logger = logging.getLogger(__name__)
33+
34+
35+
def is_ci():
36+
return os.getenv("CI", None) is not None
37+
38+
39+
def download_file(url, path):
40+
logger.info(f"Downloading {url} to {path}")
41+
block_size = 1024 * 1024
42+
with urllib.request.urlopen(url) as response, open(path, "wb") as file:
43+
while True:
44+
data = response.read(block_size)
45+
if not data:
46+
break
47+
file.write(data)
48+
49+
50+
def verify_sha256sum(path, sha256sum):
51+
with open(path, "rb") as file:
52+
file_hash = hashlib.sha256(file.read()).hexdigest()
53+
if file_hash != sha256sum:
54+
raise Exception("SHA256SUM does not match")
55+
56+
57+
def extract_tar_xz(path, directory):
58+
with tarfile.open(path) as file:
59+
file.extractall(directory)
60+
61+
62+
def run_command(command, cwd=None, env=None):
63+
process = subprocess.Popen(command, cwd=cwd, env=env)
64+
process.communicate()
65+
if process.returncode != 0:
66+
raise Exception("Command failed")
67+
68+
69+
@contextmanager
70+
def gha_group(title: str) -> typing.Generator:
71+
if not is_ci():
72+
yield
73+
return
74+
print(f"\n::group::{title}")
75+
stdout.flush()
76+
try:
77+
yield
78+
finally:
79+
print("::endgroup::")
80+
stdout.flush()
81+
82+
83+
def set_env_var_gha(name: str, value: str) -> None:
84+
if not is_ci():
85+
return
86+
env_file = os.getenv("GITHUB_ENV", None)
87+
if env_file is None:
88+
return
89+
with open(env_file, "a") as file:
90+
file.write(f"{name}={value}\n")
91+
stdout.flush()
92+
93+
94+
def get_ld_library_path(prefix: Path) -> str:
95+
# given a prefix, the ld library path can be found at
96+
# <prefix>/lib/* or sometimes just <prefix>/lib
97+
# this function returns the path to the ld library path
98+
99+
# first, check if the ld library path exists at <prefix>/lib/*
100+
ld_library_paths = list(prefix.glob("lib/*"))
101+
if len(ld_library_paths) == 1:
102+
return ld_library_paths[0].absolute().as_posix()
103+
104+
# if the ld library path does not exist at <prefix>/lib/*,
105+
# return <prefix>/lib
106+
ld_library_path = prefix / "lib"
107+
if ld_library_path.exists():
108+
return ld_library_path.absolute().as_posix()
109+
return ""
110+
111+
112+
def main():
113+
if sys.platform == "win32":
114+
logger.info("Skipping build on windows")
115+
return
116+
117+
with tempfile.TemporaryDirectory() as tmpdir:
118+
with gha_group("Downloading and Extracting Cairo"):
119+
logger.info(f"Downloading cairo version {CAIRO_VERSION}")
120+
download_file(CAIRO_URL, os.path.join(tmpdir, "cairo.tar.xz"))
121+
122+
logger.info("Downloading cairo sha256sum")
123+
download_file(CAIRO_SHA256_URL, os.path.join(tmpdir, "cairo.sha256sum"))
124+
125+
logger.info("Verifying cairo sha256sum")
126+
with open(os.path.join(tmpdir, "cairo.sha256sum")) as file:
127+
sha256sum = file.read().split()[0]
128+
verify_sha256sum(os.path.join(tmpdir, "cairo.tar.xz"), sha256sum)
129+
130+
logger.info("Extracting cairo")
131+
extract_tar_xz(os.path.join(tmpdir, "cairo.tar.xz"), tmpdir)
132+
133+
with gha_group("Installing meson and ninja"):
134+
logger.info("Creating virtual environment")
135+
run_command([sys.executable, "-m", "venv", os.path.join(tmpdir, VENV_NAME)])
136+
137+
logger.info("Installing meson and ninja")
138+
run_command(
139+
[
140+
os.path.join(tmpdir, VENV_NAME, "bin", "pip"),
141+
"install",
142+
"meson",
143+
"ninja",
144+
]
145+
)
146+
147+
env_vars = {
148+
# add the venv bin directory to PATH so that meson can find ninja
149+
"PATH": f"{os.path.join(tmpdir, VENV_NAME, 'bin')}{os.pathsep}{os.environ['PATH']}",
150+
}
151+
152+
with gha_group("Building and Installing Cairo"):
153+
logger.info("Running meson setup")
154+
run_command(
155+
[
156+
os.path.join(tmpdir, VENV_NAME, "bin", "meson"),
157+
"setup",
158+
BUILD_DIR,
159+
f"--prefix={INSTALL_PREFIX.absolute().as_posix()}",
160+
"--buildtype=release",
161+
"-Dtests=disabled",
162+
],
163+
cwd=os.path.join(tmpdir, f"cairo-{CAIRO_VERSION}"),
164+
env=env_vars,
165+
)
166+
167+
logger.info("Running meson compile")
168+
run_command(
169+
[
170+
os.path.join(tmpdir, VENV_NAME, "bin", "meson"),
171+
"compile",
172+
"-C",
173+
BUILD_DIR,
174+
],
175+
cwd=os.path.join(tmpdir, f"cairo-{CAIRO_VERSION}"),
176+
env=env_vars,
177+
)
178+
179+
logger.info("Running meson install")
180+
run_command(
181+
[
182+
os.path.join(tmpdir, VENV_NAME, "bin", "meson"),
183+
"install",
184+
"-C",
185+
BUILD_DIR,
186+
],
187+
cwd=os.path.join(tmpdir, f"cairo-{CAIRO_VERSION}"),
188+
env=env_vars,
189+
)
190+
191+
logger.info(f"Successfully built cairo and installed it to {INSTALL_PREFIX}")
192+
193+
194+
if __name__ == "__main__":
195+
if "--set-env-vars" in sys.argv:
196+
with gha_group("Setting environment variables"):
197+
# append the pkgconfig directory to PKG_CONFIG_PATH
198+
set_env_var_gha(
199+
"PKG_CONFIG_PATH",
200+
f"{Path(get_ld_library_path(INSTALL_PREFIX), 'pkgconfig').as_posix()}{os.pathsep}"
201+
f'{os.getenv("PKG_CONFIG_PATH", "")}',
202+
)
203+
set_env_var_gha(
204+
"LD_LIBRARY_PATH",
205+
f"{get_ld_library_path(INSTALL_PREFIX)}{os.pathsep}"
206+
f'{os.getenv("LD_LIBRARY_PATH", "")}',
207+
)
208+
sys.exit(0)
209+
main()

.github/workflows/cffconvert.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Check out a copy of the repository
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- name: Check whether the citation metadata from CITATION.cff is valid
1717
uses: citation-file-format/[email protected]

.github/workflows/ci.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-22.04, macos-latest, windows-latest]
25-
python: ["3.8", "3.9", "3.10", "3.11"]
25+
python: ["3.9", "3.10", "3.11", "3.12"]
2626

2727
steps:
2828
- name: Checkout the repository
29-
uses: actions/checkout@v3
29+
uses: actions/checkout@v4
3030

3131
- name: Install Poetry
3232
run: |
@@ -65,7 +65,7 @@ jobs:
6565

6666
- name: Install Texlive (Linux)
6767
if: runner.os == 'Linux'
68-
uses: teatimeguest/setup-texlive-action@v2
68+
uses: teatimeguest/setup-texlive-action@v3
6969
with:
7070
cache: true
7171
packages: scheme-basic fontspec inputenc fontenc tipa mathrsfs calligra xcolor standalone preview doublestroke ms everysel setspace rsfs relsize ragged2e fundus-calligra microtype wasysym physics dvisvgm jknapltx wasy cm-super babel-english gnu-freefont mathastext cbfonts-fd xetex
@@ -76,6 +76,22 @@ jobs:
7676
# start xvfb in background
7777
sudo /usr/bin/Xvfb $DISPLAY -screen 0 1280x1024x24 &
7878
79+
- name: Setup Cairo Cache
80+
uses: actions/cache@v3
81+
id: cache-cairo
82+
if: runner.os == 'Linux' || runner.os == 'macOS'
83+
with:
84+
path: ${{ github.workspace }}/third_party
85+
key: ${{ runner.os }}-dependencies-cairo-${{ hashFiles('.github/scripts/ci_build_cairo.py') }}
86+
87+
- name: Build and install Cairo (Linux and macOS)
88+
if: (runner.os == 'Linux' || runner.os == 'macOS') && steps.cache-cairo.outputs.cache-hit != 'true'
89+
run: python .github/scripts/ci_build_cairo.py
90+
91+
- name: Set env vars for Cairo (Linux and macOS)
92+
if: runner.os == 'Linux' || runner.os == 'macOS'
93+
run: python .github/scripts/ci_build_cairo.py --set-env-vars
94+
7995
- name: Setup macOS cache
8096
uses: actions/cache@v3
8197
id: cache-macos
@@ -103,10 +119,6 @@ jobs:
103119
export PATH="$oriPath"
104120
echo "Completed TinyTeX"
105121
106-
- name: Install cairo (MacOS)
107-
if: runner.os == 'macOS'
108-
run: brew install cairo
109-
110122
- name: Add macOS dependencies to PATH
111123
if: runner.os == 'macOS'
112124
shell: bash

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
steps:
2626
- name: Checkout
27-
uses: actions/checkout@v3
27+
uses: actions/checkout@v4
2828

2929
- name: Initialize CodeQL
3030
uses: github/codeql-action/init@v2

.github/workflows/publish-docker.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ jobs:
1313
if: github.event_name != 'release'
1414
steps:
1515
- name: Set up QEMU
16-
uses: docker/setup-qemu-action@v2
16+
uses: docker/setup-qemu-action@v3
1717

1818
- name: Set up Docker Buildx
19-
uses: docker/setup-buildx-action@v2
19+
uses: docker/setup-buildx-action@v3
2020

2121
- name: Login to DockerHub
22-
uses: docker/login-action@v2
22+
uses: docker/login-action@v3
2323
with:
2424
username: ${{ secrets.DOCKERHUB_USERNAME }}
2525
password: ${{ secrets.DOCKERHUB_TOKEN }}
2626

2727
- name: Build and push
28-
uses: docker/build-push-action@v4
28+
uses: docker/build-push-action@v5
2929
with:
3030
platforms: linux/arm64,linux/amd64
3131
push: true
@@ -38,13 +38,13 @@ jobs:
3838
if: github.event_name == 'release'
3939
steps:
4040
- name: Set up QEMU
41-
uses: docker/setup-qemu-action@v2
41+
uses: docker/setup-qemu-action@v3
4242

4343
- name: Set up Docker Buildx
44-
uses: docker/setup-buildx-action@v2
44+
uses: docker/setup-buildx-action@v3
4545

4646
- name: Login to DockerHub
47-
uses: docker/login-action@v2
47+
uses: docker/login-action@v3
4848
with:
4949
username: ${{ secrets.DOCKERHUB_USERNAME }}
5050
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -61,7 +61,7 @@ jobs:
6161
print(f"tag_name={ref_tag}", file=f)
6262
6363
- name: Build and push
64-
uses: docker/build-push-action@v4
64+
uses: docker/build-push-action@v5
6565
with:
6666
platforms: linux/arm64,linux/amd64
6767
push: true

.github/workflows/python-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
release:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212

13-
- name: Set up Python 3.8
13+
- name: Set up Python 3.11
1414
uses: actions/setup-python@v4
1515
with:
16-
python-version: 3.9
16+
python-version: 3.11
1717

1818
- name: Install dependencies
1919
run: python -m pip install --upgrade poetry

0 commit comments

Comments
 (0)