Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MacHu-GWU committed Aug 29, 2022
1 parent 27b6000 commit b8df7f3
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 20 deletions.
70 changes: 70 additions & 0 deletions requirements-determinative.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
alabaster==0.7.12
atomicwrites==1.4.1
attrs==22.1.0
attrs-mate==1.0.2
autopep8==1.7.0
Babel==2.10.3
beautifulsoup4==4.11.1
bidict==0.22.0
bleach==5.0.1
cachetools==5.2.0
certifi==2022.6.15
charset-normalizer==2.1.1
commonmark==0.9.1
decorator==5.1.1
docfly==1.0.2
docutils==0.17.1
furo==2021.8.31
future==0.18.2
idna==3.3
imagesize==1.4.1
importlib-metadata==4.12.0
Jinja2==3.1.2
keyring==23.8.2
MarkupSafe==2.1.1
mpire==2.5.0
numpy==1.23.2
oauthlib==3.2.0
packaging==21.3
pandas-mate==0.0.3
pathlib-mate==1.0.3
pkginfo==1.8.3
polars==0.14.5
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.9.1
Pygments==2.13.0
pyparsing==3.0.9
pypinyin==0.47.1
python-dateutil==2.8.2
pytz==2022.2.1
readme-renderer==37.0
requests==2.28.1
requests-oauthlib==1.3.1
requests-toolbelt==0.9.1
rfc3986==2.0.0
rich==12.5.1
rsa==4.9
rstobj==0.0.7
sfm==0.0.16
six==1.16.0
snowballstemmer==2.2.0
soupsieve==2.3.2.post1
Sphinx==4.3.0
sphinx-copybutton==0.4.0
sphinx-jinja==1.1.1
sphinx-rtd-theme==0.4.3
sphinx_inline_tabs==2021.8.17b10
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
toml==0.10.2
tqdm==4.64.0
twine==4.0.1
typing_extensions==4.3.0
urllib3==1.26.12
webencodings==0.5.1
zipp==3.8.1
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
pathlib_mate # autopep8 your code
twine # make distribution archive
wheel # make pre-compiled distribution package
mpire # multi-process
58 changes: 38 additions & 20 deletions tools/compress-image/pngquant.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
:language: python
"""

import typing as T
import mpire
import subprocess
from pathlib import Path
Expand All @@ -38,26 +39,43 @@ def compress_image(in_path: Path, out_path):
])


def compress_many_image_in_dir(in_dir: Path, out_dir: Path):
pass


# in_dir = Path("/Users/sanhehu/Documents/GitHub/wotlkdoc-project/docs/source/_static/image/armor")

def compress_many_image_in_dir(
in_dir: Path,
out_dir: Path,
extensions: T.List[str] = None,
):
if extensions is None:
extensions = ["*.png"]
path_set: T.Set[Path] = set()
for ext in extensions:
for in_path in in_dir.glob(f"**/{ext}"):
path_set.add(in_path)
path_list = list(path_set)
path_list.sort()
args = list()
for in_path in path_list:
out_path = out_dir / in_path.relative_to(in_dir)
out_path.parent.mkdir(parents=True, exist_ok=True)
args.append(dict(
in_path=in_path,
out_path=out_path,
))

with mpire.WorkerPool() as pool:
pool.map(compress_image, args)


# Define before and after
dir_here: Path = Path(__file__).absolute().parent
dir_project_root: Path = dir_here.parent.parent

dir_example_before = dir_here / "before"
dir_example_after = dir_here / "after"
# dir_after.mkdir(parents=True, exist_ok=True)
#
# args = list()
# for in_path in dir_before.glob("**/*.png"):
# out_path = dir_after / in_path.name
# args.append(dict(
# in_path=in_path,
# out_path=out_path,
# ))
#
# with mpire.WorkerPool() as pool:
# results = pool.map(compress_image, args)
dir_example_before = dir_here / "example" / "before"
dir_example_after = dir_here / "example" / "after"

compress_many_image_in_dir(
dir_example_before,
dir_example_after,
extensions=[
"*.png",
],
)

0 comments on commit b8df7f3

Please sign in to comment.