Skip to content

Commit

Permalink
Try excluding pulsar inflate/deflate in Python < 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
vallis committed Sep 8, 2021
1 parent 07e1150 commit 8fd647b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ source = enterprise
omit =
enterprise/__init__*
enterprise/signals/__init__*
plugins =
coverage_conditional_plugin

[coverage_conditional_plugin]
rules =
"sys_version_info >= (3, 8)": py-gte-38
"sys_version_info < (3, 8)": py-lt-38
12 changes: 4 additions & 8 deletions enterprise/pulsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
import enterprise
from enterprise.signals import utils

try:
from enterprise.pulsar_inflate import PulsarInflater
except:
# pulsar.[deflate|inflate]() requires Python >= 3.8
pass
from enterprise.pulsar_inflate import PulsarInflater

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -553,23 +549,23 @@ def _get_sunssb(self, t2pulsar):
_todeflate = ["_designmatrix", "_planetssb", "_sunssb", "_flags"]
_deflated = "pristine"

def deflate(psr):
def deflate(psr): # pragma: py-lt-38
if psr._deflated == "pristine":
for attr in psr._todeflate:
if isinstance(getattr(psr, attr), np.ndarray):
setattr(psr, attr, PulsarInflater(getattr(psr, attr)))

psr._deflated = "deflated"

def inflate(psr):
def inflate(psr): # pragma: py-lt-38
if psr._deflated == "deflated":
for attr in psr._todeflate:
if isinstance(getattr(psr, attr), PulsarInflater):
setattr(psr, attr, getattr(psr, attr).inflate())

psr._deflated = "inflated"

def destroy(psr):
def destroy(psr): # pragma: py-lt-38
if psr._deflated == "deflated":
for attr in psr._todeflate:
if isinstance(getattr(psr, attr), PulsarInflater):
Expand Down
9 changes: 7 additions & 2 deletions enterprise/pulsar_inflate.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# deflate.py
# pulsar_inflate.py
"""Defines PulsarInflater class: instances copy a numpy array to shared memory,
and (after pickling) will reinflate to a numpy array that refers to the shared
data.
"""

from multiprocessing import shared_memory, resource_tracker
import numpy as np

try:
from multiprocessing import shared_memory, resource_tracker
except:
# shared_memory unavailable in Python < 3.8
pass


class memmap(np.ndarray):
def __del__(self):
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ PyYAML>=4.2b1
pytest>=4.0.0
sphinx-rtd-theme>=0.4.0
pytest-cov>=2.7.0
coverage-conditional-plugin>=0.4.0
jupyter>=1.0.0
build==0.3.1.post1

0 comments on commit 8fd647b

Please sign in to comment.