Skip to content

Commit 283a2e7

Browse files
committed
Release v2.2.4: auto-generate config.h in setup.py
- Generate config.h at build time instead of requiring CMake pre-run Fixes 'pip install pynec' / 'pip install necpp' from sdist on Linux - Bump version 2.2.3 -> 2.2.4 in pyproject.toml + setup.py fallback - Clean up docs: remove Python 2 references, outdated NEWS, stale install instructions, and fix necpp README Python 3 syntax
1 parent 2bfc2f4 commit 283a2e7

9 files changed

Lines changed: 107 additions & 61 deletions

File tree

‎PyNEC/CHANGES.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<!-- Copyright (c) 2008-2026 Tim Molteno (tim@elec.ac.nz) -->
2-
### Version 1.8.0:
2+
### Version 2.2.4:
3+
4+
* Fix #XX: Auto-generate config.h in setup.py so pip install from sdist works
5+
- setup.py now writes necpp_src/build/config.h with version from pyproject.toml
6+
- No longer requires CMake to be run before pip install from source
7+
- Applied to both PyNEC/setup.py and necpp/setup.py
8+
9+
### Version 2.2.3:
310

411
* Update necpp_src submodule to v2.1.1 — major engine upgrade
512
- Eigen 3.4.0 replaces LAPACK (bundled in src/eigen3/, no external dependency)

‎PyNEC/INSTALL.md‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<!-- Copyright (c) 2008-2026 Tim Molteno (tim@elec.ac.nz) -->
2-
## Building from Source
2+
# PyNEC: Building from Source
33

4-
apt install swig
5-
git submodule init
6-
git submodule update --remote
7-
cd PyNEC
4+
git clone --recursive https://github.com/tmolteno/python-necpp.git
5+
cd python-necpp/PyNEC
86
./build.sh
97
uv pip install dist/*.whl
108

11-
## Testing
9+
## Test
1210

1311
uv pip install pytest
1412
python -m pytest tests/ -v
1513

16-
## Uploading the package to pypi
14+
## Upload
1715

1816
uv build
1917
uv publish

‎PyNEC/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- Copyright (c) 2008-2026 Tim Molteno (tim@elec.ac.nz) -->
22
# Python NEC2++ Module
33

4-
This module wraps the C++ API for antenna simulation of nec2++. It is easier to work with, and more powerful than the C-style API wrapper. Works with Python 2.7 and 3+.
4+
This module wraps the C++ API for antenna simulation of nec2++. It is easier to work with, and more powerful than the C-style API wrapper. Requires Python 3.9+.
55

66

77
## Usage
@@ -77,7 +77,7 @@ Then do following:
7777

7878
## Install from PyPI
7979

80-
$ sudo pip install pynec
80+
$ pip install PyNEC
8181

8282
*Note: 'sudo' is not required in windows.*
8383

‎PyNEC/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "PyNEC"
8-
version = "2.2.3"
8+
version = "2.2.4"
99
description = "Python Antenna Simulation Module (nec2++) object-oriented interface"
1010
readme = "README.md"
1111
license = "GPL-3.0-only"

‎PyNEC/setup.py‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,48 @@
1010
Author Tim Molteno. tim@molteno.net
1111
"""
1212

13+
import datetime
1314
import os
1415
from glob import glob
1516

1617
from setuptools import Extension, setup
1718

19+
# ---------------------------------------------------------------------------
20+
# Generate config.h (normally done by CMake, but needed for pip installs and
21+
# PEP 517 isolated builds where CMake is not available).
22+
# ---------------------------------------------------------------------------
23+
BUILD_DIR = "necpp_src/build"
24+
os.makedirs(BUILD_DIR, exist_ok=True)
25+
26+
# Try to read the version from pyproject.toml; fall back to a known default.
27+
_version = "2.2.4"
28+
try:
29+
import tomllib # Python 3.11+
30+
except ImportError:
31+
try:
32+
import tomli as tomllib
33+
except ImportError:
34+
pass
35+
else:
36+
with open("pyproject.toml", "rb") as _f:
37+
_version = tomllib.load(_f)["project"]["version"]
38+
else:
39+
with open("pyproject.toml", "rb") as _f:
40+
_version = tomllib.load(_f)["project"]["version"]
41+
42+
_build_date = datetime.date.today().strftime("%Y-%m-%d")
43+
44+
_config_h = os.path.join(BUILD_DIR, "config.h")
45+
with open(_config_h, "w") as _f:
46+
_f.write(f"""#ifndef CONFIG_H
47+
#define CONFIG_H
48+
49+
#define NECPP_VERSION "{_version}"
50+
#define NECPP_BUILD_DATE "{_build_date}"
51+
52+
#endif /* CONFIG_H */
53+
""")
54+
1855
# numpy is declared in pyproject.toml build-system.requires for PEP 517 isolated builds.
1956
# Guard against the case where setup.py is evaluated for metadata before build deps are installed.
2057
try:
@@ -37,7 +74,7 @@
3774
)
3875
nec_sources.extend(glob("PyNEC_wrap.cxx"))
3976

40-
# config.h is generated by CMake into necpp_src/build/ (run build.sh first).
77+
# config.h is auto-generated above from pyproject.toml metadata.
4178
#
4279
if np is not None:
4380
include_dirs = [np.get_include(), "necpp_src/src", "necpp_src/", "necpp_src/build/", "necpp_src/src/eigen"]

‎necpp/INSTALL.md‎

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,22 @@
11
<!-- Copyright (c) 2008-2026 Tim Molteno (tim@elec.ac.nz) -->
2-
# python-necpp
3-
PyPI module for nec2++
2+
# necpp: Building from Source
43

5-
This module allows you to do antenna simulations in Python using the nec2++ antenna
6-
simulation package. This is a wrapper using SWIG of the C interface, so the syntax
7-
is quite simple. Have a look at the file test.py, for an example of how this
8-
library can be used. Other examples are in the 'examples' directory.
4+
This is the C-style SWIG wrapper for the nec2++ antenna simulation library.
5+
The C++ code is compiled as part of the Python extension — no separate library
6+
installation is required.
97

108
### Author
119

1210
Tim Molteno. tim@physics.otago.ac.nz
1311

14-
## Instructions
15-
16-
To use this python module, you must have the necpp library installed on your system. This can
17-
be installed in the main part of the necpp code distribution.
18-
19-
### NEC2++ source distribution
20-
21-
This is included as a git submodule
22-
23-
git clone https://github.com/tmolteno/python-necpp.git
24-
git submodule init
25-
git submodule update --remote
26-
27-
To update the submodule to the latest necpp
28-
29-
git submodule update --remote
30-
31-
### Converting from MarkDown
32-
33-
apt install pandoc swig
34-
35-
pandoc --to=rst README.md > README.txt
36-
37-
### Testing
38-
39-
Build and install the module:
12+
## Build from Source
4013

14+
git clone --recursive https://github.com/tmolteno/python-necpp.git
15+
cd python-necpp/necpp
4116
./build.sh
4217
uv pip install dist/*.whl
4318

44-
Run the tests:
19+
## Testing
4520

4621
uv pip install pytest
4722
python -m pytest tests/ -v
48-
49-
### Uploading to PyPI.
50-
51-
uv build
52-
uv publish

‎necpp/README.md‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ library can be used.
1010

1111
Tim Molteno. tim@physics.otago.ac.nz
1212

13-
## NEWS
13+
## News
1414

15-
* Version 1.7.3 Includes Python3 support. Also some bug fixes and updating nec++ to the
16-
latest version.
17-
* Version 1.7.0.3 includes nec_medium_parameters(). You could simulate an antenna in seawater!
18-
* Version 1.7.0 includes support for getting elements of radiation patterns. At the moment
19-
this is just through the function nec_get_gain().
15+
* Version 2.2.x Latest releases including Eigen-based matrix solver and
16+
modern Python packaging (pyproject.toml, uv support).
2017

2118

2219
## Install
@@ -45,7 +42,7 @@ over a perfect ground.
4542

4643
def handle_nec(result):
4744
if (result != 0):
48-
print necpp.nec_error_message()
45+
print(necpp.nec_error_message())
4946

5047
def impedance(frequency, z0, height):
5148
@@ -64,9 +61,9 @@ over a perfect ground.
6461
necpp.nec_delete(nec)
6562
return z
6663

67-
if (__name__ == 'main'):
64+
if __name__ == "__main__":
6865
z = impedance(frequency = 34.5, z0 = 0.5, height = 4.0)
69-
print "Impedance \t(%6.1f,%+6.1fI) Ohms" % (z.real, z.imag)
66+
print("Impedance \t(%6.1f,%+6.1fI) Ohms" % (z.real, z.imag))
7067

7168
## More Information
7269

‎necpp/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "necpp"
8-
version = "2.2.3"
8+
version = "2.2.4"
99
description = "Python Antenna Simulation Module (nec2++) C-style interface"
1010
readme = "README.md"
1111
license = "GPL-3.0-only"

‎necpp/setup.py‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,48 @@
88
All package metadata is in pyproject.toml.
99
"""
1010

11+
import datetime
1112
import os
1213
from glob import glob
1314

1415
from setuptools import Extension, setup
1516

17+
# ---------------------------------------------------------------------------
18+
# Generate config.h (normally done by CMake, but needed for pip installs and
19+
# PEP 517 isolated builds where CMake is not available).
20+
# ---------------------------------------------------------------------------
21+
BUILD_DIR = "necpp_src/build"
22+
os.makedirs(BUILD_DIR, exist_ok=True)
23+
24+
# Try to read the version from pyproject.toml; fall back to a known default.
25+
_version = "2.2.4"
26+
try:
27+
import tomllib # Python 3.11+
28+
except ImportError:
29+
try:
30+
import tomli as tomllib
31+
except ImportError:
32+
pass
33+
else:
34+
with open("pyproject.toml", "rb") as _f:
35+
_version = tomllib.load(_f)["project"]["version"]
36+
else:
37+
with open("pyproject.toml", "rb") as _f:
38+
_version = tomllib.load(_f)["project"]["version"]
39+
40+
_build_date = datetime.date.today().strftime("%Y-%m-%d")
41+
42+
_config_h = os.path.join(BUILD_DIR, "config.h")
43+
with open(_config_h, "w") as _f:
44+
_f.write(f"""#ifndef CONFIG_H
45+
#define CONFIG_H
46+
47+
#define NECPP_VERSION "{_version}"
48+
#define NECPP_BUILD_DATE "{_build_date}"
49+
50+
#endif /* CONFIG_H */
51+
""")
52+
1653
nec_sources = []
1754
nec_sources.extend(
1855
[
@@ -27,7 +64,7 @@
2764
)
2865
nec_sources.extend(glob("necpp_wrap.c"))
2966

30-
# config.h is generated by CMake into necpp_src/build/ (run build.sh first).
67+
# config.h is auto-generated above from pyproject.toml metadata.
3168
#
3269
necpp_module = Extension(
3370
"_necpp",

0 commit comments

Comments
 (0)