Skip to content

Commit f03c8f9

Browse files
authored
build universal pnnx wheel and pnnx entrypoint script (#5331)
1 parent f5b55c6 commit f03c8f9

File tree

6 files changed

+16
-56
lines changed

6 files changed

+16
-56
lines changed

.ci/pnnx.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ jobs:
132132
run: |
133133
export PYTHONUSERBASE=${{ci.workspace}}/torch-${{matrix.torch-version}}
134134
export PNNX_WHEEL_WITHOUT_BUILD=ON
135-
cd tools/pnnx
136-
cp build/src/pnnx python/pnnx/
135+
cd tools/pnnx/python
136+
cp ../build/src/pnnx pnnx/
137137
python3 setup.py install --user
138-
pytest python/tests/
138+
pytest tests

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ __pycache__
5454
*.pyd
5555
*.egg-info/
5656
python/setup.py
57-
tools/pnnx/python/setup.py
5857

5958
# Clangd
6059
.cache/
6160

6261
# Xmake
63-
.xmake/
62+
.xmake/

tools/pnnx/python/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ conda install pytorch
4242
```
4343
3. install
4444
```bash
45-
cd /pathto/ncnntools/pnnx
45+
cd /pathto/ncnntools/pnnx/python
4646
python setup.py install
4747
```
4848

@@ -61,8 +61,8 @@ python setup.py install
6161
6262
## Tests
6363
```bash
64-
cd /pathto/ncnn/tools/pnnx
65-
pytest python/tests/
64+
cd /pathto/ncnn/tools/pnnx/python
65+
pytest tests
6666
```
6767
6868
## Usage

tools/pnnx/python/pnnx/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
# specific language governing permissions and limitations under the License.
1414

1515
import os
16+
import sys
1617
import platform
18+
import subprocess
19+
1720
EXEC_DIR_PATH = os.path.dirname(os.path.abspath(__file__))
1821
if platform.system() == 'Linux' or platform.system() == "Darwin":
1922
EXEC_PATH = EXEC_DIR_PATH + "/pnnx"
@@ -31,3 +34,5 @@
3134
except:
3235
pass
3336

37+
def pnnx():
38+
raise SystemExit(subprocess.call([EXEC_PATH] + sys.argv[1:], close_fds=False))

tools/pnnx/setup.py tools/pnnx/python/setup.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ def build_extension(self, ext):
156156
],
157157
license="BSD-3",
158158
python_requires=">=3.7",
159-
packages=find_packages("python"),
159+
packages=find_packages(),
160160
package_data={"pnnx": ["pnnx", "pnnx.exe"]},
161-
package_dir={"": "python"},
161+
package_dir={"": "."},
162162
install_requires=requirements,
163-
ext_modules=[CMakeExtension("pnnx")],
163+
ext_modules=None if PNNX_WHEEL_WITHOUT_BUILD == 'ON' else [CMakeExtension("pnnx", "..")],
164164
cmdclass={"build_ext": CMakeBuild},
165+
entry_points={"console_scripts": ["pnnx=pnnx:pnnx"]},
165166
)

tools/pnnx/python/setup.py.i

-45
This file was deleted.

0 commit comments

Comments
 (0)