Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package into single file with stickytape #70

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ build/
*.pyo
*.egg
*.egg-info
single_file/single_file_icecream.py
single_file/icecream_pypy.py
24 changes: 24 additions & 0 deletions single_file/compare_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Utility to see which version files differ.
"""

from collections import defaultdict
from glob import glob
from pathlib import Path

result = defaultdict(list)

for filename in glob("icecream_*.py"):
group = result[hash(Path(filename).read_text())]
group.append(filename.replace("icecream_", "").replace(".py", ""))
group.sort()

for group in sorted(result.values()):
print(group)

"""
The result is that the files fall into these groups:
['py27', 'pypy27']
['py35', 'pypy35']
['py36', 'py37', 'py38', 'py39', 'pypy36']
"""
90 changes: 90 additions & 0 deletions single_file/icecream_py27.py

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions single_file/icecream_py35.py

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions single_file/icecream_py36.py

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions single_file/icecream_py37.py

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions single_file/icecream_py38.py

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions single_file/icecream_py39.py

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions single_file/icecream_pypy27.py

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions single_file/icecream_pypy35.py

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions single_file/icecream_pypy36.py

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions single_file/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -eux

OUTPUT_FILE=icecream_${TOX_ENV_NAME}.py

stickytape stickytape_entry.py \
--add-python-path .. \
--add-python-module pygments.formatters.terminal256 \
--add-python-module pygments.lexers.python \
--add-python-module icecream.__version__ \
--add-python-path $(python site_packages_path.py) \
--output-file $OUTPUT_FILE

ls -lh $OUTPUT_FILE
cp $OUTPUT_FILE single_file_icecream.py

python test_single_file_icecream.py
9 changes: 9 additions & 0 deletions single_file/site_packages_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import executing

path = executing.__file__.rstrip("c")
suffix = "/executing/__init__.py"
assert path.endswith(suffix), path
path = path[:-len(suffix)]

if __name__ == '__main__':
print(path)
6 changes: 6 additions & 0 deletions single_file/stickytape_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# After this module is imported and exits, stickytape deletes
# the temporary directory containing the files
# Necessary modules need to be imported before then
# asttokens is only imported dynamically by executing
import asttokens
from icecream import *
10 changes: 10 additions & 0 deletions single_file/test_single_file_icecream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sys
import site_packages_path
sys.path.remove(site_packages_path.path)
del sys.modules["executing"]
del sys.modules["executing.executing"]

# Copied from a version specific file in package.sh
from single_file_icecream import ic

ic(ic(1+2))
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[tox]
envlist = py27, py35, py36, py37, pypy, pypy3
envlist = py27, py35, py36, py37, py38, py39, pypy, pypy35, pypy36

[testenv]
allowlist_externals=/bin/bash
deps =
nose
commands =
nosetests --exe []
; bash -c 'cd single_file; ./package.sh'