Skip to content

Commit 25c358a

Browse files
authored
Merge pull request #95 from open-atmos/slayoo-patch-3
enable Python 3.9 builds on Windows
2 parents ed55529 + 9123d82 commit 25c358a

File tree

6 files changed

+74
-33
lines changed

6 files changed

+74
-33
lines changed

.github/workflows/pdoc.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ jobs:
2626
pip install -e .
2727
# TODO: add -We
2828
python -m pdoc --html PyPartMC
29-
mkdir html/PyPartMC
30-
mv html/PyPartMC.html html/PyPartMC/index.html
3129
- name: Deploy
3230
if: ${{ github.ref == 'refs/heads/main' && matrix.platform == 'ubuntu-latest' }}
3331
uses: JamesIves/[email protected]

.github/workflows/tests+artifacts+pypi.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ jobs:
2020
matrix:
2121
platform: [ubuntu-latest, macos-11, macOS-12, windows-latest]
2222
python-version: ["3.7", "3.8", "3.9", "3.10"]
23-
exclude:
24-
- platform: windows-latest
25-
python-version: "3.8"
26-
- platform: windows-latest
27-
python-version: "3.9"
28-
- platform: windows-latest
29-
python-version: "3.10"
3023
runs-on: ${{ matrix.platform }}
3124
steps:
3225
- if: startsWith(matrix.platform, 'macos-')

CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
####################################################################################################
66

77
cmake_minimum_required(VERSION 3.4...3.18)
8-
project(PyPartMC LANGUAGES C CXX Fortran)
8+
project(_PyPartMC LANGUAGES C CXX Fortran)
99

1010
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1111

@@ -124,23 +124,23 @@ target_link_libraries(partmclib PRIVATE ${SUNDIALS_items})
124124
### PYBIND11 & PyPartMC ############################################################################
125125

126126
add_subdirectory(gitmodules/pybind11)
127-
pybind11_add_module(PyPartMC ${PyPartMC_sources})
128-
add_dependencies(PyPartMC partmclib)
129-
target_include_directories(PyPartMC PRIVATE
127+
pybind11_add_module(_PyPartMC ${PyPartMC_sources})
128+
add_dependencies(_PyPartMC partmclib)
129+
target_include_directories(_PyPartMC PRIVATE
130130
${CMAKE_SOURCE_DIR}/gitmodules/json/include
131131
${CMAKE_SOURCE_DIR}/gitmodules/pybind11_json/include
132132
${CMAKE_SOURCE_DIR}/gitmodules/span/include
133133
${CMAKE_SOURCE_DIR}/gitmodules/string_view-standalone/include
134134
)
135-
target_compile_definitions(PyPartMC PRIVATE VERSION_INFO=${VERSION_INFO})
136-
target_link_libraries(PyPartMC PRIVATE partmclib)
135+
target_compile_definitions(_PyPartMC PRIVATE VERSION_INFO=${VERSION_INFO})
136+
target_link_libraries(_PyPartMC PRIVATE partmclib)
137137
if (APPLE)
138-
target_link_options(PyPartMC PRIVATE -Wl,-no_compact_unwind -Wl,-keep_dwarf_unwind)
138+
target_link_options(_PyPartMC PRIVATE -Wl,-no_compact_unwind -Wl,-keep_dwarf_unwind)
139139
endif()
140140

141141
### pedantics ######################################################################################
142142

143-
foreach(target PyPartMC) # TODO: the same for partmclib
143+
foreach(target _PyPartMC) # TODO: the same for partmclib
144144
target_compile_options(${target} PRIVATE
145145
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
146146
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>

PyPartMC/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# pylint: disable=invalid-name,wrong-import-position
2+
import os
3+
from contextlib import contextmanager
4+
from pathlib import Path
5+
from collections import namedtuple
6+
7+
# https://github.com/diegoferigo/cmake-build-extension/blob/master/src/cmake_build_extension/__init__.py
8+
@contextmanager
9+
def __build_extension_env():
10+
cookies = []
11+
# https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
12+
if hasattr(os, "add_dll_directory"):
13+
for path in os.environ.get("PATH", "").split(os.pathsep):
14+
if path and Path(path).is_absolute() and Path(path).is_dir():
15+
cookies.append(os.add_dll_directory(path))
16+
try:
17+
yield
18+
finally:
19+
for cookie in cookies:
20+
cookie.close()
21+
22+
# TODO: 2 x loop over prefixes and units
23+
si = namedtuple("SI", (
24+
"m", "cm", "um",
25+
"kg", "g",
26+
"s",
27+
"K",
28+
"Pa", "hPa",
29+
"mol"
30+
))(
31+
m=1., cm=.01, um=1e-6,
32+
kg=1., g=1e-3,
33+
s=1.,
34+
K=1.,
35+
Pa=1., hPa=100.,
36+
mol=1.
37+
)
38+
""" TODO """
39+
40+
with __build_extension_env():
41+
from _PyPartMC import *
42+
from _PyPartMC import __all__
43+
import _PyPartMC

setup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import subprocess
1010
import sys
1111
from pathlib import Path
12-
from setuptools import Extension, setup
12+
from setuptools import Extension, setup, find_packages
1313
from setuptools.command.build_ext import build_ext
1414

1515
# Convert distutils Windows platform specifiers to CMake -A arguments
@@ -134,11 +134,17 @@ def build_extension(self, ext): # pylint: disable=too-many-branches
134134
description="Python interface to PartMC",
135135
long_description=(Path(__file__).parent / "README.md").read_text(),
136136
long_description_content_type="text/markdown",
137-
ext_modules=[CMakeExtension("PyPartMC")],
137+
packages=find_packages(include=["PyPartMC", "PyPartMC.*"]),
138+
ext_modules=[CMakeExtension("_PyPartMC")],
138139
cmdclass={"build_ext": CMakeBuild},
139140
zip_safe=False,
140141
python_requires=">=3.7",
141142
setup_requires=["setuptools_scm"],
142143
install_requires=['numpy'],
143144
license="GPL-3.0",
145+
project_urls={
146+
"Tracker": "https://github.com/open-atmos/PyPartMC/issues",
147+
"Documentation": "https://open-atmos.github.io/PyPartMC",
148+
"Source": "https://github.com/open-atmos/PyPartMC/",
149+
}
144150
)

src/pypartmc.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace py = pybind11;
2626

27-
PYBIND11_MODULE(PyPartMC, m) {
27+
PYBIND11_MODULE(_PyPartMC, m) {
2828
m.doc() = R"pbdoc(
2929
PyPartMC is a Python interface to PartMC.
3030
)pbdoc";
@@ -179,18 +179,19 @@ PYBIND11_MODULE(PyPartMC, m) {
179179
"Return the least power-of-2 that is at least equal to n."
180180
);
181181

182-
auto si = m.def_submodule("si", "SI units");
183-
// TODO: 2xloop over prefixes and units
184-
si.attr("m") = py::float_(1.);
185-
si.attr("s") = py::float_(1.);
186-
si.attr("K") = py::float_(1.);
187-
si.attr("Pa") = py::float_(1.);
188-
si.attr("hPa") = py::float_(100.);
189-
si.attr("mol") = py::float_(1.);
190-
si.attr("kg") = py::float_(1.);
191-
si.attr("g") = py::float_(1e-3);
192-
si.attr("cm") = py::float_(.01);
193-
si.attr("um") = py::float_(1e-6);
194-
195182
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
183+
184+
m.attr("__all__") = py::make_tuple(
185+
"__version__",
186+
"AeroData",
187+
"AeroState",
188+
"EnvState",
189+
"GasData",
190+
"GasState",
191+
"RunPartOpt",
192+
"Scenario",
193+
"condense_equilib_particles",
194+
"run_part",
195+
"pow2_above"
196+
);
196197
}

0 commit comments

Comments
 (0)