Skip to content

Commit 4fea974

Browse files
committed
Merge branch 'main' into gas_improvements
Conflicts: tests/test_gas_state.py
2 parents 0447e64 + 159f630 commit 4fea974

35 files changed

+913
-498
lines changed

.github/workflows/pre-commit.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: pre-commit-hooks
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Set up Python 3.10
11+
uses: actions/setup-python@v1
12+
with:
13+
python-version: "3.10"
14+
- name: Linting
15+
run: |
16+
pip install pre-commit
17+
pre-commit clean
18+
pre-commit autoupdate
19+
pre-commit run --all-files

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,16 @@ jobs:
2424
fetch-depth: 0 # https://github.com/pypa/setuptools_scm/issues/480
2525
- run: pip install -r test-time-requirements.txt
2626
- run: DEBUG=0 VERBOSE=1 pip install --verbose -e .
27-
- run: pytest -v -s -We -p no:unraisableexception tests/test_todos_annotated.py
27+
- env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: pytest -v -s -We -p no:unraisableexception tests/test_todos_annotated.py
2830

2931
build:
3032
needs: [todos_annotated]
3133
strategy:
3234
matrix:
3335
platform: [ubuntu-latest, macos-12, windows-latest]
3436
python-version: ["3.7", "3.8", "3.9", "3.10"]
35-
exclude:
36-
- platform: macos-12
37-
python-version: "3.7"
38-
- platform: macos-12
39-
python-version: "3.8"
40-
- platform: macos-12
41-
python-version: "3.9"
4237
runs-on: ${{ matrix.platform }}
4338
steps:
4439
- if: startsWith(matrix.platform, 'macos-')
@@ -78,6 +73,7 @@ jobs:
7873
- run: pip install -r test-time-requirements.txt
7974

8075
- run: |
76+
unset CI
8177
python -m build 2>&1 | tee build.log
8278
exit `fgrep -i warning build.log | wc -l`
8379

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
shallow = true
55
[submodule "partmc"]
66
path = gitmodules/partmc
7-
url = https://github.com/compdyn/partmc
7+
url = https://github.com/slayoo/partmc
88
shallow = true
99
[submodule "pybind11_json"]
1010
path = gitmodules/pybind11_json

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
files: '.py'
2+
exclude: '.git'
3+
default_stages: [commit]
4+
5+
repos:
6+
- repo: https://github.com/psf/black
7+
rev: 22.6.0
8+
hooks:
9+
- id: black
10+
11+
- repo: https://github.com/timothycrosley/isort
12+
rev: 5.10.1
13+
hooks:
14+
- id: isort
15+
args: ["--profile", "black"]
16+
17+
- repo: https://github.com/pre-commit/pre-commit-hooks
18+
rev: v4.3.0
19+
hooks:
20+
- id: trailing-whitespace
21+
- id: end-of-file-fixer
22+
- id: debug-statements

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ add_definitions("-DSUNDIALS_INT64_T=1")
3636
### sources ########################################################################################
3737

3838
set(PyPartMC_sources
39-
pypartmc.cpp gimmicks.cpp fake_netcdf.cpp fake_mpi.cpp fake_spec_file.cpp
39+
pypartmc.cpp gimmicks.cpp fake_netcdf.cpp fake_spec_file.cpp sys.cpp
4040
run_part.F90 run_part_opt.F90 util.F90 aero_data.F90 aero_state.F90 env_state.F90 gas_data.F90
4141
gas_state.F90 scenario.F90 condense.F90 aero_particle.F90 bin_grid.F90
4242
camp_core.F90 photolysis.F90
@@ -136,7 +136,7 @@ set(partmclib_SOURCES condense_solver.c aero_state.F90 integer_varray.F90 intege
136136
photolysis.F90
137137
)
138138
add_prefix(gitmodules/partmc/src/ partmclib_SOURCES)
139-
list(APPEND partmclib_SOURCES src/fake_mpi.F90 src/fake_netcdf.F90 src/fake_spec_file.F90)
139+
list(APPEND partmclib_SOURCES src/fake_netcdf.F90 src/fake_spec_file.F90 src/sys.F90)
140140

141141
set(klu_SOURCES
142142
KLU/Source/klu_analyze.c
@@ -271,7 +271,6 @@ target_include_directories(camplib PRIVATE
271271

272272
add_library(partmclib STATIC ${partmclib_SOURCES})
273273
target_compile_definitions(partmclib PRIVATE PMC_USE_SUNDIALS="1")
274-
target_compile_definitions(partmclib PRIVATE PMC_USE_MPI="1")
275274
target_compile_definitions(partmclib PRIVATE PMC_USE_CAMP="1")
276275
add_dependencies(partmclib ${SUNDIALS_items})
277276
target_include_directories(partmclib PRIVATE
@@ -297,6 +296,9 @@ target_compile_definitions(_PyPartMC PRIVATE VERSION_INFO=${VERSION_INFO})
297296
target_link_libraries(_PyPartMC PRIVATE partmclib)
298297
if (APPLE)
299298
target_link_options(_PyPartMC PRIVATE -Wl,-no_compact_unwind -Wl,-keep_dwarf_unwind)
299+
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
300+
target_link_libraries(_PyPartMC PRIVATE -static gfortran -dynamic)
301+
endif()
300302
endif()
301303
if (WIN32)
302304
target_link_libraries(_PyPartMC PRIVATE -static gcc stdc++ winpthread quadmath -dynamic)

PyPartMC/__init__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# pylint: disable=invalid-name,wrong-import-position
22
import os
3+
from collections import namedtuple
34
from contextlib import contextmanager
45
from pathlib import Path
5-
from collections import namedtuple
6+
67

78
# https://github.com/diegoferigo/cmake-build-extension/blob/master/src/cmake_build_extension/__init__.py
89
@contextmanager
@@ -11,8 +12,8 @@ def __build_extension_env():
1112
# https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
1213
if hasattr(os, "add_dll_directory"):
1314
basepath = os.path.dirname(os.path.abspath(__file__))
14-
dllspath = os.path.join(basepath, '..')
15-
os.environ['PATH'] = dllspath + os.pathsep + os.environ['PATH']
15+
dllspath = os.path.join(basepath, "..")
16+
os.environ["PATH"] = dllspath + os.pathsep + os.environ["PATH"]
1617
for path in os.environ.get("PATH", "").split(os.pathsep):
1718
if path and Path(path).is_absolute() and Path(path).is_dir():
1819
cookies.append(os.add_dll_directory(path))
@@ -22,25 +23,24 @@ def __build_extension_env():
2223
for cookie in cookies:
2324
cookie.close()
2425

26+
2527
# TODO #113: 2 x loop over prefixes and units
26-
si = namedtuple("SI", (
27-
"m", "cm", "um", "nm",
28-
"kg", "g",
29-
"s",
30-
"K",
31-
"Pa", "hPa",
32-
"mol"
33-
))(
34-
m=1., cm=.01, um=1e-6, nm=1e-9,
35-
kg=1., g=1e-3,
36-
s=1.,
37-
K=1.,
38-
Pa=1., hPa=100.,
39-
mol=1.
28+
si = namedtuple("SI", ("m", "cm", "um", "nm", "kg", "g", "s", "K", "Pa", "hPa", "mol"))(
29+
m=1.0,
30+
cm=0.01,
31+
um=1e-6,
32+
nm=1e-9,
33+
kg=1.0,
34+
g=1e-3,
35+
s=1.0,
36+
K=1.0,
37+
Pa=1.0,
38+
hPa=100.0,
39+
mol=1.0,
4040
)
4141
""" TODO #113 """
4242

4343
with __build_extension_env():
44-
from _PyPartMC import *
45-
from _PyPartMC import __all__, __version__
4644
import _PyPartMC
45+
from _PyPartMC import *
46+
from _PyPartMC import __all__, __version__ # pylint: disable=no-name-in-module

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ warning: no files found matching 'gitmodules/...
9696
```
9797
Since git clone was done without recursive option, try: `git submodule update --init`
9898

99+
## Notes for developers
99100
#### How to debug
100101
```sh
101102
git clone --recursive git+https://github.com/open-atmos/PyPartMC.git
@@ -104,6 +105,8 @@ DEBUG=1 VERBOSE=1 pip --verbose install -e .
104105
gdb python
105106
(gdb) run -m pytest -s -vv -We -p no:unraisableexception tests
106107
```
108+
#### Pre-commit hooks
109+
PyPartMC codebase benefits from Pylint, Black and isort code analysis (which are all part of the CI workflows where we also use pre-commit hooks. The pre-commit hooks can be run locally, and then the resultant changes need to be staged before committing. To set up the hooks locally, install pre-commit via `pip install pre-commit` and set up the git hooks via `pre-commit install` (this needs to be done every time you clone the project). To run all pre-commit hooks, run `pre-commit run --all-files`. The `.pre-commit-config.yaml` file can be modified in case new hooks are to be added or existing ones need to be altered.
107110

108111
## Credits
109112

setup.py

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

1516
# Convert distutils Windows platform specifiers to CMake -A arguments
@@ -140,11 +141,11 @@ def build_extension(self, ext): # pylint: disable=too-many-branches
140141
zip_safe=False,
141142
python_requires=">=3.7",
142143
setup_requires=["setuptools_scm"],
143-
install_requires=['numpy'],
144+
install_requires=["numpy"],
144145
license="GPL-3.0",
145146
project_urls={
146147
"Tracker": "https://github.com/open-atmos/PyPartMC/issues",
147148
"Documentation": "https://open-atmos.github.io/PyPartMC",
148149
"Source": "https://github.com/open-atmos/PyPartMC/",
149-
}
150+
},
150151
)

src/aero_data.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ subroutine f_aero_data_ctor(ptr_c) bind(C)
1616
type(c_ptr), intent(out) :: ptr_c
1717

1818
allocate(ptr_f)
19+
call fractal_set_spherical(ptr_f%fractal)
1920
ptr_c = c_loc(ptr_f)
2021
end subroutine
2122

0 commit comments

Comments
 (0)