Skip to content

Commit

Permalink
Cibuildwheel (#20)
Browse files Browse the repository at this point in the history
* Yum

 - This gets images using yum to install net-snmp

- but the build command fails.

* Update pyproject.toml

- attempt to get the linux wheels to work
- ATM only the macos wheels work.

* Docs

- updating docs with what is needed for a fresh ubuntu install.

* Docs And Cleanup

- cleaning up docs.
- cleaning up code.

* Update requirements.txt

- updating a bunch of packages

* No Perl

- attempting to build net-snmp with no perl.

* Update pyproject.toml

without perl not with perl.

* tool.cibuildwheel.linux

- okay this works now tool.cibuildwheel.linux

muslinux breaks now.

* Wheels

- all wheels build. Need to see if tests run on all as well ?? that might be trickier.
  • Loading branch information
carlkidcrypto authored Jan 30, 2024
1 parent 512fea5 commit bce1fcb
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto eol=lf
3 changes: 2 additions & 1 deletion .github/workflows/build_and_publish_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
- uses: actions/setup-python@v5

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.16.2
run: python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build_and_publish_to_test_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
- uses: actions/setup-python@v5

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.16.2
run: python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ docs/_build/
dev/
.vscode
*/*.log
*.log
*.log
wheelhouse/**
24 changes: 17 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ possible:
- **Wes Hardaker and the net-snmp-coders**: for their hard work and
dedication
- **fgimian and nnathan**: the original contributors to this codebase
- **Kent Coble**: who as the most recent maintainer. `Easy SNMP <https://github.com/easysnmp/easysnmp>`_
- **Kent Coble**: who was the most recent maintainer. `Easy SNMP <https://github.com/easysnmp/easysnmp>`_

Running Tests
-------------
Expand All @@ -142,11 +142,21 @@ them with the following on Linux:
git clone https://github.com/ezsnmp/ezsnmp.git;
cd ezsnmp;
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig;
cp tests/snmpd.conf /etc/snmp/snmpd.conf;
systemctl start snmpd;
rm -drf build/ ezsnmp.egg-info;
python3 setup.py build && python3 -m pip install -e . && gdb -ex run -ex bt -ex quit --args python3 -m pytest .;
sudo apt update && sudo apt upgrade -y;
sudo apt install -y snmpd libsnmp-dev libperl-dev snmp-mibs-downloader valgrind;
sudo apt install -y python3-pip python3-dev python3-setuptools gdb -y;
sudo systemctl stop snmpd;
sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig;
sudo cp tests/snmpd.conf /etc/snmp/snmpd.conf;
sudo download-mibs;
mkdir -p -m 0755 ~/.snmp;
echo 'mibs +ALL' > ~/.snmp/snmp.conf;
sudo systemctl start snmpd;
rm -drf build/ dist/ ezsnmp.egg-info;
python3 -m pip install -r requirements.txt;
python3 setup.py build && python3 -m pip install -e . && python3 -m pytest .;
# Bottom one for debug. Replace the top one with it if needed.
# python3 setup.py build && python3 -m pip install -e . && gdb -ex run -ex bt -ex quit --args python3 -m pytest .;
On MacOS
Expand All @@ -159,7 +169,7 @@ On MacOS
cp tests/snmpd.conf /etc/snmp/snmpd.conf;
launchctl unload /System/Library/LaunchDaemons/org.net-snmp.snmpd.plist;
launchctl load -w /System/Library/LaunchDaemons/org.net-snmp.snmpd.plist;
rm -drf build/ ezsnmp.egg-info;
rm -drf build/ dist/ ezsnmp.egg-info;
python3 setup.py build && python3 -m pip install -e . && python3 -m pytest .;
License
Expand Down
36 changes: 0 additions & 36 deletions ezsnmp/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@
*/

#include <Python.h>

/*
* Old versions of Python use CObject API instead of Capsules.
* Both are similar, so we just use a bit of preprocessor magic
* to provide backwards compatibility.
*/
#if ( \
(PY_VERSION_HEX < 0x02070000) || \
((PY_VERSION_HEX >= 0x03000000) && \
(PY_VERSION_HEX < 0x03010000)))

#define USE_DEPRECATED_COBJECT_API

#define PyCapsule_New(pointer, name, destructor) \
(PyCObject_FromVoidPtr(pointer, destructor))

#define PyCapsule_GetPointer(capsule, name) \
(PyCObject_AsVoidPtr(capsule))

#endif /* PY_VERSION_HEX */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/snmpv3_api.h>
Expand Down Expand Up @@ -1619,20 +1598,6 @@ void *get_session_handle_from_capsule(PyObject *session_capsule)
return PyCapsule_GetPointer(session_capsule, NULL);
}

#ifdef USE_DEPRECATED_COBJECT_API
/* The CObject API calls destructor with stored pointer */
void delete_session_capsule(void *session_ptr)
{
struct session_capsule_ctx *ctx = session_ptr;
if (ctx)
{
// clear_user_list(); // Too dangerous, may disrupt other valid sessions
__remove_user_from_cache((struct session_list *)ctx->handle);
snmp_sess_close(ctx->handle);
free(ctx);
}
}
#else
/* Automatically called when Python reclaims session_capsule object. */
void delete_session_capsule(PyObject *session_capsule)
{
Expand All @@ -1646,7 +1611,6 @@ void delete_session_capsule(PyObject *session_capsule)
free(ctx);
}
}
#endif /* USE_DEPRECATED_COBJECT_API */

PyObject *netsnmp_create_session(PyObject *self, PyObject *args)
{
Expand Down
28 changes: 25 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
[tool.cibuildwheel]
skip = "cp36-* cp37-*"
manylinux-x86_64-image = "manylinux2014"
skip = "cp27-* cp36-* cp37-* pp37-*"

[[tool.cibuildwheel.overrides]]
select = "*manylinux_2_24*"
before-all = """apt-get --assume-yes install wget unzip;
wget https://sourceforge.net/projects/net-snmp/files/net-snmp/5.9.4/net-snmp-5.9.4.zip/download ;
unzip download;
cd net-snmp-5.9.4;
./configure --with-defaults --disable-mibs --disable-manual --without-perl-modules --disable-embedded-perl;
make ;
make install ;"""

[[tool.cibuildwheel.overrides]]
select = "*musllinux*"
before-all = "apk add net-snmp-dev;"

[tool.cibuildwheel.linux]
before-all = "yum install net-snmp-devel || apk add snmpd libsnmp-dev libperl-dev || apt-get install snmpd libsnmp-dev libperl-dev"
before-all = """yum -y install wget;
wget https://sourceforge.net/projects/net-snmp/files/net-snmp/5.9.4/net-snmp-5.9.4.zip/download ;
unzip download;
cd net-snmp-5.9.4;
./configure --with-defaults --disable-mibs --disable-manual --without-perl-modules --disable-embedded-perl;
make ;
make install ;"""

[tool.cibuildwheel.macos]
before-all = """brew update;
Expand All @@ -11,4 +32,5 @@ before-all = """brew update;
echo 'export PATH="/usr/local/opt/net-snmp/bin:$PATH"' >> ~/.zshrc;
export PATH="/usr/local/opt/net-snmp/bin:$PATH";
echo 'export PATH="/usr/local/opt/net-snmp/sbin:$PATH"' >> ~/.zshrc;
export PATH="/usr/local/opt/net-snmp/sbin:$PATH";"""
export PATH="/usr/local/opt/net-snmp/sbin:$PATH";"""

Binary file modified requirements.txt
Binary file not shown.
19 changes: 1 addition & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
from pathlib import Path


def is_docker():
cgroup = Path("/proc/self/cgroup")
return (
Path("/.dockerenv").is_file()
or cgroup.is_file()
and "docker" in cgroup.read_text()
)


# Determine if a base directory has been provided with the --basedir option
basedir = None
in_tree = False
Expand Down Expand Up @@ -55,15 +46,7 @@ def is_docker():

# Otherwise, we use the system-installed SNMP libraries
else:
netsnmp_libs = None
if is_docker():
netsnmp_libs = check_output(
"docker run --privileged cmd.cat/net-snmp-config net-snmp-config --libs",
shell=True,
).decode()

else:
netsnmp_libs = check_output("net-snmp-config --libs", shell=True).decode()
netsnmp_libs = check_output("net-snmp-config --libs", shell=True).decode()

pass_next = False
# macOS-specific
Expand Down
5 changes: 3 additions & 2 deletions sphinx_docs_build/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ On RHEL / CentOS systems:
On Debian / Ubuntu systems:

.. code-block:: bash
sudo apt-get install libsnmp-dev snmp-mibs-downloader
sudo apt update && sudo apt upgrade -y;
sudo apt install -y libsnmp-dev libperl-dev snmp-mibs-downloader;
On macOS systems:

Expand Down

0 comments on commit bce1fcb

Please sign in to comment.