Skip to content

Commit 4b04578

Browse files
committed
bugfix for distro workflow
1 parent 8205e8f commit 4b04578

File tree

4 files changed

+153
-43
lines changed

4 files changed

+153
-43
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ temp
3131
_build
3232
Pipfile.lock
3333

34+
build_tmp
35+
3436
# Created by https://www.gitignore.io/api/macos,python,visualstudiocode
3537

3638
### macOS ###

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
"pycapfile",
217217
"pyenv",
218218
"pypcap",
219+
"pyproject",
219220
"qsfn",
220221
"qsnn",
221222
"qsopt",

Makefile

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,41 @@ pipenv: update-pipenv
2525
# update: update-const update-date
2626
update: update-const
2727

28-
dist:
29-
mkdir -p dist sdist eggs wheels
30-
find dist -iname '*.egg' -exec mv {} eggs \;
31-
find dist -iname '*.whl' -exec mv {} wheels \;
32-
find dist -iname '*.tar.gz' -exec mv {} sdist \;
33-
rm -rf build dist *.egg-info
34-
pipenv run python setup.py sdist
35-
pypy3.7 setup.py bdist_egg bdist_wheel --python-tag='pp37'
36-
python3.7 setup.py bdist_egg bdist_wheel --python-tag='cp37'
37-
python3.8 setup.py bdist_egg bdist_wheel --python-tag='cp38'
38-
python3.9 setup.py bdist_egg bdist_wheel --python-tag='cp39'
39-
python3.10 setup.py bdist_egg bdist_wheel --python-tag='cp310'
40-
twine check dist/* || true
41-
twine upload dist/* -r pypi --skip-existing
42-
twine upload dist/* -r pypitest --skip-existing
28+
dist-update:
29+
~/.pyenv/versions/pypy3.7-*/bin/python3.7 -m pip install -U pip setuptools wheel
30+
~/.pyenv/versions/pypy3.8-*/bin/python3.8 -m pip install -U pip setuptools wheel
31+
~/.pyenv/versions/pypy3.9-*/bin/python3.9 -m pip install -U pip setuptools wheel
32+
~/.pyenv/versions/3.7.*/bin/python3.7 -m pip install -U pip setuptools wheel
33+
~/.pyenv/versions/3.8.*/bin/python3.8 -m pip install -U pip setuptools wheel
34+
python3.9 -m pip install -U pip setuptools wheel
35+
python3.10 -m pip install -U pip setuptools wheel
36+
python3.11 -m pip install -U pip setuptools wheel
37+
38+
dist-build:
39+
rm -rf build_tmp
40+
mkdir build_tmp
41+
cp -r pcapkit LICENSE MANIFEST.in pyproject.toml README.rst setup.cfg setup.py build_tmp
42+
cd build_tmp && mkdir -p dist sdist eggs wheels
43+
cd build_tmp && python3.11 setup.py bdist_egg bdist_wheel --python-tag='cp311'
44+
cd build_tmp && python3.10 setup.py bdist_egg bdist_wheel --python-tag='cp310'
45+
cd build_tmp && python3.9 setup.py bdist_egg bdist_wheel --python-tag='cp39'
46+
cd build_tmp && ~/.pyenv/versions/pypy3.9-*/bin/python3.9 setup.py bdist_egg bdist_wheel --python-tag='pp39'
47+
cd build_tmp && pipenv run walrus --no-archive pcapkit
48+
cd build_tmp && ~/.pyenv/versions/3.8.*/bin/python3.8 setup.py bdist_egg bdist_wheel --python-tag='cp38'
49+
cd build_tmp && ~/.pyenv/versions/pypy3.8-*/bin/python3.8 setup.py bdist_egg bdist_wheel --python-tag='pp38'
50+
cd build_tmp && ~/.pyenv/versions/3.7.*/bin/python3.7 setup.py bdist_egg bdist_wheel --python-tag='cp37'
51+
cd build_tmp && ~/.pyenv/versions/pypy3.7-*/bin/python3.7 setup.py bdist_egg bdist_wheel --python-tag='pp37'
52+
cd build_tmp && python3.11 setup.py sdist
53+
54+
dist-upload:
55+
twine check build_tmp/dist/*
56+
twine upload build_tmp/dist/* -r pypi --skip-existing
57+
# twine upload build_tmp/dist/* -r pypitest --skip-existing
58+
find build_tmp/dist -name "*.egg" -exec mv {} eggs \;
59+
find build_tmp/dist -name "*.whl" -exec mv {} wheels \;
60+
find build_tmp/dist -name "*.tar.gz" -exec mv {} sdist \;
61+
62+
dist: dist-update dist-build dist-upload
4363

4464
docs:
4565
PCAPKIT_SPHINX=1 pipenv run $(MAKE) -C doc/sphinx html
@@ -139,7 +159,7 @@ dist-pypi-old: dist-f2format
139159

140160
# upload PyPI distribution
141161
.ONESHELL:
142-
dist-upload:
162+
dist-upload-old:
143163
set -ex
144164
cd $(DIR)
145165
twine check dist/*

setup.py

Lines changed: 114 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,43 @@
165165
},
166166
setup_requires=[
167167
# version compatibility
168-
#'bpc-f2format; python_version < "3.6"',
169168
'f2format; python_version < "3.6"',
170-
#'bpc-walrus; python_version < "3.8"',
171-
'python-walrus==0.1.5rc1; python_version < "3.8"',
169+
'bpc-walrus; python_version < "3.8"',
172170
'pathlib2>=2.3.2; python_version == "3.4"',
173171
]
174172
)
175173

174+
175+
def refactor() -> 'None':
176+
"""Refactor code."""
177+
if version_info < (3, 6):
178+
try:
179+
subprocess.check_call( # nosec
180+
[sys.executable, '-m', 'f2format', '--no-archive', 'pcapkit']
181+
)
182+
except subprocess.CalledProcessError as error:
183+
print('Failed to perform assignment expression backport compiling.'
184+
'Please consider manually install `bpc-f2format` and try again.', file=sys.stderr)
185+
sys.exit(error.returncode)
186+
187+
if version_info < (3, 8):
188+
try:
189+
subprocess.check_call( # nosec
190+
[sys.executable, '-m', 'walrus', '--no-archive', 'pcapkit']
191+
)
192+
except subprocess.CalledProcessError as error:
193+
print('Failed to perform assignment expression backport compiling.'
194+
'Please consider manually install `bpc-walrus` and try again.', file=sys.stderr)
195+
sys.exit(error.returncode)
196+
197+
176198
try:
177199
from setuptools import setup
178-
from setuptools.command.build_py import build_py
200+
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
201+
from setuptools.command.build_py import build_py as _build_py
202+
from setuptools.command.develop import develop as _develop
203+
from setuptools.command.install import install as _install
204+
from setuptools.command.sdist import sdist as _sdist
179205

180206
version_info = sys.version_info[:2]
181207

@@ -191,38 +217,99 @@
191217
python_requires='>=3.6',
192218
zip_safe=True, # type: ignore
193219
))
220+
221+
222+
class bdist_egg(_bdist_egg):
223+
"""Add on-distribution backport code conversion."""
224+
225+
def run(self) -> 'None':
226+
"""Run command."""
227+
refactor()
228+
_bdist_egg.run(self)
229+
230+
231+
class develop(_develop):
232+
"""Add on-develop backport code conversion."""
233+
234+
def run(self) -> 'None':
235+
"""Run command."""
236+
refactor()
237+
_develop.run(self)
238+
239+
240+
cmdclass = {
241+
'bdist_egg': bdist_egg,
242+
'develop': develop,
243+
}
244+
194245
except ImportError:
195246
from distutils.core import setup # pylint: disable=deprecated-module
196-
from distutils.command.build_py import build_py # pylint: disable=deprecated-module
247+
from distutils.command.bdist import bdist as _bdist # pylint: disable=deprecated-module
248+
from distutils.command.build_py import build_py as _build_py # pylint: disable=deprecated-module
249+
from distutils.command.install import install as _install # pylint: disable=deprecated-module
250+
from distutils.command.sdist import sdist as _sdist # pylint: disable=deprecated-module
251+
252+
253+
class bdist(_bdist):
254+
"""Add on-distribution backport code conversion."""
255+
256+
def run(self) -> 'None':
257+
"""Run command."""
258+
refactor()
259+
_bdist.run(self)
260+
261+
262+
cmdclass = {
263+
'bdist': bdist,
264+
}
197265

198266

199-
class build(build_py):
267+
try:
268+
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
269+
270+
271+
class bdist_wheel(_bdist_wheel):
272+
"""Add on-wheel backport code conversion."""
273+
274+
def run(self) -> 'None':
275+
"""Run command."""
276+
refactor()
277+
_bdist_wheel.run(self)
278+
279+
280+
cmdclass['bdist_wheel'] = bdist_wheel
281+
except ImportError:
282+
pass
283+
284+
285+
class build_py(_build_py):
200286
"""Add on-build backport code conversion."""
201287

202288
def run(self) -> 'None':
203-
if version_info < (3, 6):
204-
try:
205-
subprocess.check_call( # nosec
206-
[sys.executable, '-m', 'f2format', '--no-archive', 'pcapkit']
207-
)
208-
except subprocess.CalledProcessError as error:
209-
print('Failed to perform assignment expression backport compiling.'
210-
'Please consider manually install `bpc-f2format` and try again.', file=sys.stderr)
211-
sys.exit(error.returncode)
212-
213-
if version_info < (3, 8):
214-
try:
215-
subprocess.check_call( # nosec
216-
[sys.executable, '-m', 'walrus', '--no-archive', 'pcapkit']
217-
)
218-
except subprocess.CalledProcessError as error:
219-
print('Failed to perform assignment expression backport compiling.'
220-
'Please consider manually install `bpc-walrus` and try again.', file=sys.stderr)
221-
sys.exit(error.returncode)
222-
build_py.run(self)
289+
refactor()
290+
_build_py.run(self)
291+
292+
293+
class install(_install):
294+
"""Add on-install backport code conversion."""
295+
296+
def run(self) -> 'None':
297+
refactor()
298+
_install.run(self)
299+
300+
301+
class sdist(_sdist):
302+
"""Add on-distribution backport code conversion."""
303+
304+
def run(self) -> 'None':
305+
refactor()
306+
_sdist.run(self)
223307

224308

225309
# set-up script for pip distribution
226310
setup(cmdclass={
227-
'build_py': build,
311+
'build_py': build_py,
312+
'install': install,
313+
'sdist': sdist,
314+
**cmdclass,
228315
}, **attrs)

0 commit comments

Comments
 (0)