Skip to content

Commit a779f1e

Browse files
committed
Add type information
1 parent d4f9ada commit a779f1e

11 files changed

Lines changed: 283 additions & 14 deletions

File tree

.github/workflows/release.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
release:
1010
runs-on: ubuntu-latest
1111
container:
12-
image: danielflook/python-minifier-build:fedora30-2020-05-03
12+
image: danielflook/python-minifier-build:fedora34-2021-10-05
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v2
@@ -25,15 +25,13 @@ jobs:
2525
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
2626
run: |
2727
pip3 install --upgrade setuptools wheel twine
28-
python3 setup.py sdist bdist_wheel
28+
python3 setup.py sdist bdist_wheel --universal
2929
twine upload --non-interactive dist/*
3030
3131
- name: Build documentation
3232
run: |
33-
python3.8 -m ensurepip
34-
pip3.8 install --upgrade setuptools wheel twine
35-
pip3.8 install sphinx==2.0.1 sphinxcontrib-programoutput==0.14 sphinx_rtd_theme==0.4.3
36-
pip3.8 install dist/*.tar.gz
33+
pip3 install sphinx sphinxcontrib-programoutput sphinx_rtd_theme
34+
pip3 install dist/*.tar.gz
3735
sphinx-build docs/source /tmp/build
3836
3937
- name: Publish documentation
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
name: Test Release
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
7+
package:
8+
runs-on: ubuntu-latest
9+
container:
10+
image: danielflook/python-minifier-build:fedora34-2021-10-05
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set version statically
18+
run: |
19+
VERSION="$(python3 setup.py --version)"
20+
sed -i "s/setup_requires=.*/version='$VERSION',/; s/use_scm_version=.*//" setup.py
21+
22+
- name: Package
23+
run: |
24+
pip3 install --upgrade setuptools wheel twine
25+
python3 setup.py sdist bdist_wheel --universal
26+
27+
- uses: actions/upload-artifact@v3
28+
with:
29+
name: dist
30+
path: dist/
31+
if-no-files-found: error
32+
33+
test_docs:
34+
runs-on: ubuntu-latest
35+
needs: [package]
36+
container:
37+
image: danielflook/python-minifier-build:fedora34-2021-10-05
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v2
41+
42+
- uses: actions/download-artifact@v3
43+
with:
44+
name: dist
45+
path: dist/
46+
47+
- name: Build documentation
48+
run: |
49+
pip3 install sphinx sphinxcontrib-programoutput sphinx_rtd_theme
50+
pip3 install dist/*.tar.gz
51+
sphinx-build docs/source /tmp/build
52+
53+
test_package:
54+
runs-on: ubuntu-latest
55+
strategy:
56+
matrix:
57+
python: [2.7, 3.4, 3.5, 3.6, 3.7, 3.8]
58+
package_type: [.tar.gz, .whl]
59+
needs: [package]
60+
container:
61+
image: danielflook/python-minifier-build:fedora30-2020-05-03
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v2
65+
66+
- uses: actions/download-artifact@v3
67+
with:
68+
name: dist
69+
path: dist/
70+
71+
- name: Install package
72+
run: |
73+
if [[ "${{ matrix.python }}" == "2.7" || "${{ matrix.python }}" == "3.7" ]]; then
74+
echo "pip is already installed"
75+
elif [[ "${{ matrix.python }}" == "3.8" ]]; then
76+
curl https://bootstrap.pypa.io/get-pip.py | python${{ matrix.python }}
77+
else
78+
curl https://bootstrap.pypa.io/pip/${{ matrix.python }}/get-pip.py | python${{ matrix.python }}
79+
fi
80+
81+
pip${{ matrix.python }} install dist/*${{ matrix.package_type }}
82+
pyminify --version
83+
84+
- name: Test pyminify
85+
run: |
86+
set -x
87+
cat setup.py | pyminify -
88+
pyminify setup.py > /tmp/out.min.py
89+
pyminify setup.py --output /tmp/out.min.py2
90+
pyminify setup.py src test --in-place
91+
92+
test_package_3_3:
93+
runs-on: ubuntu-latest
94+
strategy:
95+
matrix:
96+
package_type: [.tar.gz, .whl]
97+
needs: [package]
98+
container:
99+
image: danielflook/python-minifier-build:fedora28-2020-05-03
100+
steps:
101+
- name: Checkout
102+
uses: actions/checkout@v2
103+
104+
- uses: actions/download-artifact@v3
105+
with:
106+
name: dist
107+
path: dist/
108+
109+
- name: Install package
110+
run: |
111+
curl https://bootstrap.pypa.io/pip/3.3/get-pip.py | python3.3
112+
pip3.3 install dist/*${{ matrix.package_type }}
113+
pyminify --version
114+
115+
- name: Test pyminify
116+
run: |
117+
set -x
118+
cat setup.py | pyminify -
119+
pyminify setup.py > /tmp/out.min.py
120+
pyminify setup.py --output /tmp/out.min.py2
121+
pyminify setup.py src test --in-place
122+
123+
test_package_3_9:
124+
runs-on: ubuntu-latest
125+
strategy:
126+
matrix:
127+
package_type: [.tar.gz, .whl]
128+
needs: [package]
129+
container:
130+
image: danielflook/python-minifier-build:fedora32-2020-10-11
131+
steps:
132+
- name: Checkout
133+
uses: actions/checkout@v2
134+
135+
- uses: actions/download-artifact@v3
136+
with:
137+
name: dist
138+
path: dist/
139+
140+
- name: Install package
141+
run: |
142+
pip3.9 install dist/*${{ matrix.package_type }}
143+
pyminify --version
144+
145+
- name: Test pyminify
146+
run: |
147+
set -x
148+
cat setup.py | pyminify -
149+
pyminify setup.py > /tmp/out.min.py
150+
pyminify setup.py --output /tmp/out.min.py2
151+
pyminify setup.py src test --in-place
152+
153+
test_package_3_10:
154+
runs-on: ubuntu-latest
155+
strategy:
156+
matrix:
157+
package_type: [.tar.gz, .whl]
158+
needs: [package]
159+
container:
160+
image: danielflook/python-minifier-build:fedora34-2021-10-05
161+
steps:
162+
- name: Checkout
163+
uses: actions/checkout@v2
164+
165+
- uses: actions/download-artifact@v3
166+
with:
167+
name: dist
168+
path: dist/
169+
170+
- name: Install package
171+
run: |
172+
pip3.10 install dist/*${{ matrix.package_type }}
173+
pyminify --version
174+
175+
- name: Test pyminify
176+
run: |
177+
set -x
178+
cat setup.py | pyminify -
179+
pyminify setup.py > /tmp/out.min.py
180+
pyminify setup.py --output /tmp/out.min.py2
181+
pyminify setup.py src test --in-place
182+
183+
- name: Test typing
184+
run: |
185+
pip3.10 install mypy
186+
mypy typing_test/test_typing.py
187+
188+
if mypy typing_test/test_badtyping.py; then
189+
echo "Bad types weren't detected"
190+
exit 1
191+
fi
192+
193+
stubtest python_minifier

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ wheels/
1010
*.egg-info/
1111
*.egg
1212
venv/
13+
venv*/
1314
docs/build/
1415
docs/source/transforms/*.min.py
1516
.cache/
1617
.pytest_cache/
17-
.circleci-config.yml
18+
.circleci-config.yml
19+
.coverage
20+
.mypy_cache/

MANIFEST.in

Lines changed: 0 additions & 3 deletions
This file was deleted.

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os.path
2+
23
from setuptools import setup, find_packages
34

45
readme_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md')
@@ -21,6 +22,7 @@
2122
use_scm_version=True,
2223
package_dir={'': 'src'},
2324
packages=find_packages('src'),
25+
package_data={"python_minifier": ["py.typed", "__init__.pyi"]},
2426
long_description=long_desc,
2527
long_description_content_type='text/markdown',
2628

@@ -48,7 +50,7 @@
4850
'Topic :: Software Development'
4951
],
5052

51-
entry_points = {
53+
entry_points={
5254
'console_scripts': ['pyminify=python_minifier.__main__:main']
5355
},
5456

src/python_minifier/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ def minify(
135135
minified = unparse(module)
136136

137137
if preserve_shebang is True:
138-
shebang_line = find_shebang(source)
138+
shebang_line = _find_shebang(source)
139139
if shebang_line is not None:
140140
return shebang_line + '\n' + minified
141141

142142
return minified
143143

144-
def find_shebang(source):
144+
def _find_shebang(source):
145145
"""
146146
Find a shebang line in source
147147
"""

src/python_minifier/__init__.pyi

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import ast
2+
from typing import List, Text, AnyStr, Optional, Any
3+
4+
5+
class UnstableMinification(RuntimeError):
6+
def __init__(self, exception: Any, source: Any, minified: Any): ...
7+
8+
def minify(
9+
source: AnyStr,
10+
filename: Optional[str] = ...,
11+
remove_annotations: bool = ...,
12+
remove_pass: bool = ...,
13+
remove_literal_statements: bool = ...,
14+
combine_imports: bool = ...,
15+
hoist_literals: bool = ...,
16+
rename_locals: bool = ...,
17+
preserve_locals: Optional[List[Text]] = ...,
18+
rename_globals: bool = ...,
19+
preserve_globals: Optional[List[Text]] = ...,
20+
remove_object_base: bool = ...,
21+
convert_posargs_to_args: bool = ...,
22+
preserve_shebang: bool = ...
23+
) -> Text: ...
24+
25+
def unparse(module: ast.Module) -> Text: ...
26+
27+
def awslambda(
28+
source: AnyStr,
29+
filename: Optional[Text] = ...,
30+
entrypoint: Optional[Text] = ...
31+
) -> Text: ...

src/python_minifier/py.typed

Whitespace-only changes.

src/python_minifier/rename/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,4 @@ def allow_rename_globals(module, rename_globals=False, preserve_globals=None):
190190
import builtins
191191
except ImportError:
192192
# noinspection PyCompatibility
193-
import __builtin__ as builtins
193+
import __builtin__ as builtins # type: ignore

typing_test/test_badtyping.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
This should fail type checking
3+
"""
4+
5+
from python_minifier import minify
6+
7+
def test_typing() -> None:
8+
9+
minify(456,
10+
remove_pass='yes please'
11+
)

0 commit comments

Comments
 (0)