Skip to content

Commit

Permalink
Push ptf package to PyPI in CI (#184)
Browse files Browse the repository at this point in the history
We push every time the main branch is updated and every time a release
tag is created.

Signed-off-by: Antonin Bas <abas@vmware.com>
  • Loading branch information
antoninbas authored Jun 13, 2023
1 parent 9775e55 commit ff79b8c
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 66 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,30 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Dependencies
run: |
sudo apt-get install cmake libffi-dev python3-dev python3-pip ethtool
sudo pip3 install setuptools nose2 scapy
sudo apt-get install cmake libffi-dev ethtool python3-dev
# Install the latest pip version (not python3-pip) as older versions
# seem to have issues when installing from source.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py
sudo python3 -m pip install --upgrade setuptools nose2 scapy wheel
bash CI/travis/install-nanomsg.sh
bash CI/install-nanomsg.sh
sudo ldconfig
bash CI/travis/install-nnpy.sh
bash CI/install-nnpy.sh
- name: Install
run: |
sudo python setup.py install
sudo python3 -m pip install .
- name: Before_script
run: |
cd ptf_nn/; sudo ./veth_setup.sh; cd ..
- name: Script
run: |
python CI/travis/check-nnpy.py
./CI/travis/run_tests.sh
sudo python /usr/local/bin/nose2 utests.tests.test
python3 CI/check-nnpy.py
./CI/run_tests.sh
sudo python3 /usr/local/bin/nose2 utests.tests.test
40 changes: 40 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish releases to Pypi

on:
push:
branches:
- main
tags:
- v*

jobs:
publish-to-pypi:
name: Publish a Python distribution to PyPI
if: ${{ github.repository == 'p4lang/ptf' }}
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ profiles/*.pyc
dist
build
*.egg-info
.eggs
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions CI/install-nnpy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e
git clone https://github.com/nanomsg/nnpy.git
cd nnpy
sudo python3 -m pip install cffi
sudo python3 -m pip install --upgrade cffi
sudo python3 -m pip install .
cd ..
File renamed without changes.
8 changes: 0 additions & 8 deletions CI/travis/install-nnpy.sh

This file was deleted.

9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ on which to inject packets (along with the corresponding port number).

## Install PTF

PTF can be installed by running `sudo python setup.py install`. For more
information on the different options accepted by `setup.py` (e.g. installing in
a custom location), please refer to the [setuptools documentation]
(https://pythonhosted.org/setuptools/setuptools.html).

PTF can also be installed with `pip`:
PTF can be installed with `pip`:

```bash
# Install the latest version
Expand All @@ -112,6 +107,8 @@ pip install ptf
pip install ptf==0.9.1
```

You can also install a local copy of PTF with `pip install .`.

---

# Writing tests for your switch
Expand Down
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = [
"setuptools",
"setuptools_scm[toml]",
"setuptools_scm_git_archive",
"wheel",
]
build-backend = 'setuptools.build_meta'

[tool.setuptools_scm]
root = "./"
# use current tag and not next one
version_scheme = "post-release"
28 changes: 28 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[metadata]
name = ptf
description = The P4 Testing Framework
long_description = file: README.md
long_description_content_type = text/markdown; charset=UTF-8
url = https://github.com/p4lang/ptf
author = P4 Developers
author_email = p4-dev@lists.p4.org
license = Apache-2.0
license_files = LICENSE
classifiers =
License :: OSI Approved :: Apache Software License
Programming Language :: Python
Programming Language :: Python :: 3

[options]
package_dir=
=src
packages = find:
scripts = ptf, ptf_nn/ptf_nn_agent.py
platforms = any
python_requires = >=2.7, >=3
setup_requires =
setuptools_scm
install_requires = file: requirements.txt

[options.packages.find]
where = src
45 changes: 3 additions & 42 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
import os
from setuptools import setup
project_root = os.path.dirname(os.path.realpath(__file__))
import setuptools

with open(os.path.join(project_root, 'README.md')) as readme_file:
readme = readme_file.read()

with open("requirements.txt", "r") as req:
requirements = []
for l in req.readlines():
requirements.append(l.rstrip())

setup(
name='ptf',
version='0.9.3',
description='PTF is a Python based dataplane test framework.',
long_description=readme,
long_description_content_type="text/markdown",
author='Antonin Bas',
author_email='antonin@barefootnetworks.com',
url='https://github.com/p4lang/ptf',
packages=[
'ptf', 'ptf.platforms',
],
package_dir={'': 'src'},
scripts=[
'ptf',
'ptf_nn/ptf_nn_agent.py'
],
install_requires=requirements,
zip_safe=False,
license='Apache License',
keywords='ptf',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
]
)
if __name__ == "__main__":
setuptools.setup()

0 comments on commit ff79b8c

Please sign in to comment.