Skip to content

Commit

Permalink
Fix up webpack recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 7, 2024
1 parent 61487b3 commit d1c7a60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/_static/test-py.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
let q = `${i}`.padStart(4, '0');
const pyodide = await pyodideReadyPromise;
const answer = await pyodide.runPythonAsync(`
from src import p${q}
from euler.python.src import p${q}
p${q}.main()
`);
if (answer === null || answer === undefined) {
Expand Down
19 changes: 16 additions & 3 deletions python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ clean:
rm -r ./{*,*/*}{.pyc,__pycache__,.mypy_cache} || echo

webpack:
mkdir -p ../docs/_static/dist
wget https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js -O ../docs/_static/dist/pyodide.js
tar --exclude=__pycache__ -czvf ../docs/_static/dist/python.tar.gz src
# Create temporary directory for the archive content
mkdir -p ../docs/_static/dist/tmp
cp -r ../* ../docs/_static/dist/tmp

# Add __init__.py files to the temporary directory
echo "# init file" > ../docs/_static/dist/tmp/__init__.py
echo "# init file" > ../docs/_static/dist/tmp/python/__init__.py

# Exclude unwanted directories and create tarball
cd ../docs/_static/dist/tmp && \
tar --exclude='__pycache__' --exclude='*/__pycache__' \
--exclude='!_data' --exclude='!python' \
-czvf ../python.tar.gz .

# Clean up temporary directory
rm -rf ../docs/_static/dist/tmp
4 changes: 2 additions & 2 deletions python/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

for i in range(1, 10000):
try:
name = f'p{i:04}' # noqa
name = f'p{i:0>4}' # noqa
module = import_module(f'.{name}', __name__)
setattr(modules[__name__], name, module)
__all__.append(name)
Expand All @@ -24,4 +24,4 @@ def run_problems() -> None: # pragma: no cover
start = perf_counter()
answer = p()
stop = perf_counter()
print(f'The answer to problem {i:04} is {answer!r} (found in {(stop - start) * 1000:,}ms)') # noqa
print(f'The answer to problem {i:0>4} is {answer!r} (found in {(stop - start) * 1000:,}ms)') # noqa

0 comments on commit d1c7a60

Please sign in to comment.