Skip to content
Merged
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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,41 @@ Install development dependencies and run the test suite:
python3 -m pip install -e ".[dev]"
python3 -m pytest
```

## TexSoup Validation

`pymini` has been validated against the upstream `TexSoup` test suite in package mode.
Current validation: raw source code `68.2%` smaller, compressed source code
(`.tar.gz`) `36.1%` smaller.
<!-- Raw bytes: 98,181 -> 31,212. Compressed bytes: 70,532 -> 45,054. -->

| Measurement | Original | Minified | Reduction | Reduction Rate |
| --- | ---: | ---: | ---: | ---: |
| Raw Python source (`*.py`) | `98,181` bytes | `31,212` bytes | `66,969` bytes | `68.2%` |
| `.tar.gz` of `TexSoup/` | `70,532` bytes | `45,054` bytes | `25,478` bytes | `36.1%` |

To reproduce that flow locally:

```bash
git clone https://github.com/alvinwan/TexSoup /tmp/texsoup
mkdir -p /tmp/texsoup-out/TexSoup
pymini package /tmp/texsoup/TexSoup -o /tmp/texsoup-out/TexSoup
cp -R /tmp/texsoup/tests /tmp/texsoup-tests
PYTHONPATH=/tmp/texsoup-out:/tmp/texsoup-tests python3 -m pytest /tmp/texsoup-tests/tests -o addopts=''
```

To compare raw package bytes before and after minification:

```bash
rg --files /tmp/texsoup/TexSoup -g '*.py' | xargs cat | wc -c
rg --files /tmp/texsoup-out/TexSoup -g '*.py' | xargs cat | wc -c
```

To compare compressed package snapshots:

```bash
tar -czf /tmp/texsoup-original-package.tar.gz -C /tmp/texsoup TexSoup
tar -czf /tmp/texsoup-minified-package.tar.gz -C /tmp/texsoup-out TexSoup
stat -f%z /tmp/texsoup-original-package.tar.gz
stat -f%z /tmp/texsoup-minified-package.tar.gz
```
10 changes: 10 additions & 0 deletions examples/pyminifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try:import demiurgic as a
except ImportError:print("Warning: You're not demiurgic. Actually, I think that's normal.")
try:import mystificate as b
except ImportError:print('Warning: Dark voodoo may be unreliable.')
ATLAS=False
class Foo(object):
def __init__(self,*args,**kwargs):0
def demiurgic_mystificator(self,dactyl):c=a.palpitation(dactyl);return b.dark_voodoo(c)
def test(self,whatever):print(whatever)
if __name__=='__main__':print('Forming...');d=Foo('epicaricacy','perseverate');d.test('Codswallop')
22 changes: 22 additions & 0 deletions examples/pyminify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def a(event,context):
l.info(event)
try:
b=hashlib.new('md5',(event['RequestId']+event['StackId']).encode()).hexdigest();c=event['ResourceProperties']
if event['RequestType']=='Create':
event['PhysicalResourceId']='None';event['PhysicalResourceId']=create_cert(c,b);add_tags(event['PhysicalResourceId'],c);validate(event['PhysicalResourceId'],c)
if wait_for_issuance(event['PhysicalResourceId'],context):event['Status']='SUCCESS';return send(event)
else:return reinvoke(event,context)
elif event['RequestType']=='Delete':
if event['PhysicalResourceId']!='None':acm.delete_certificate(CertificateArn=event['PhysicalResourceId'])
event['Status']='SUCCESS';return send(event)
elif event['RequestType']=='Update':
if replace_cert(event):
event['PhysicalResourceId']=create_cert(c,b);add_tags(event['PhysicalResourceId'],c);validate(event['PhysicalResourceId'],c)
if not wait_for_issuance(event['PhysicalResourceId'],context):return reinvoke(event,context)
else:
if 'Tags' in event['OldResourceProperties']:acm.remove_tags_from_certificate(CertificateArn=event['PhysicalResourceId'],Tags=event['OldResourceProperties']['Tags'])
add_tags(event['PhysicalResourceId'],c)
event['Status']='SUCCESS';return send(event)
else:raise RuntimeError('Unknown RequestType')
except Exception as d:l.exception('');event['Status']='FAILED';event['Reason']=str(d);return send(event)
handler=a
Loading
Loading