Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-25877: Change pybind11 to use a single importable module #26

Merged
merged 7 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 32 additions & 27 deletions python/lsst/sphgeom/SConscript
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
from lsst.sconsUtils import scripts
scripts.BasicSConscript.pybind11([
'angle',
'angleInterval',
'box',
'box3d',
'chunker',
'circle',
'convexPolygon',
'curve',
'ellipse',
'htmPixelization',
'interval1d',
'lonLat',
'matrix3d',
'mq3cPixelization',
'normalizedAngle',
'normalizedAngleInterval',
'orientation',
'pixelization',
'q3cPixelization',
'rangeSet',
'region',
'relationship',
'unitVector3d',
'utils',
'vector3d',
], addUnderscore=False)

scripts.BasicSConscript.pybind11(
nameList=['sphgeom'],
extraSrc={'sphgeom': [
'angle.cc',
'angleInterval.cc',
'box.cc',
'box3d.cc',
'chunker.cc',
'circle.cc',
'convexPolygon.cc',
'curve.cc',
'ellipse.cc',
'htmPixelization.cc',
'interval1d.cc',
'lonLat.cc',
'matrix3d.cc',
'mq3cPixelization.cc',
'normalizedAngle.cc',
'normalizedAngleInterval.cc',
'orientation.cc',
'pixelization.cc',
'q3cPixelization.cc',
'rangeSet.cc',
'region.cc',
'relationship.cc',
'unitVector3d.cc',
'utils.cc',
'vector3d.cc',
]},
addUnderscore=False
)
timj marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 1 addition & 25 deletions python/lsst/sphgeom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,6 @@
"""lsst.sphgeom
"""

from .region import *
from .pixelization import *
from .angle import *
from .angleInterval import *
from .box import *
from .box3d import *
from .chunker import *
from .circle import *
from .convexPolygon import *
from .curve import *
from .ellipse import *
from .htmPixelization import *
from .interval1d import *
from .lonLat import *
from .matrix3d import *
from .mq3cPixelization import *
from .normalizedAngle import *
from .normalizedAngleInterval import *
from .orientation import *
from .q3cPixelization import *
from .rangeSet import *
from .relationship import *
from .unitVector3d import *
from .utils import *
from .vector3d import *
from .sphgeom import *
from .version import *
from ._yaml import *
9 changes: 4 additions & 5 deletions python/lsst/sphgeom/angle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
#include "pybind11/pybind11.h"

#include "sphgeom.h"

#include "lsst/sphgeom/Angle.h"
#include "lsst/sphgeom/NormalizedAngle.h"

Expand All @@ -29,11 +31,9 @@ using namespace pybind11::literals;

namespace lsst {
namespace sphgeom {
namespace {

PYBIND11_MODULE(angle, mod) {
py::class_<Angle> cls(mod, "Angle");

template <>
void defineClass(py::class_<Angle> &cls) {
cls.def_static("nan", &Angle::nan);
cls.def_static("fromDegrees", &Angle::fromDegrees);
cls.def_static("fromRadians", &Angle::fromRadians);
Expand Down Expand Up @@ -92,6 +92,5 @@ PYBIND11_MODULE(angle, mod) {
});
}

} // <anonymous>
} // sphgeom
} // lsst
14 changes: 4 additions & 10 deletions python/lsst/sphgeom/angleInterval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
*/
#include "pybind11/pybind11.h"

#include <memory>
#include <stdexcept>
#include "sphgeom.h"

#include "lsst/sphgeom/AngleInterval.h"
#include "lsst/sphgeom/python/interval.h"
Expand All @@ -32,14 +31,10 @@ using namespace pybind11::literals;

namespace lsst {
namespace sphgeom {
namespace {

PYBIND11_MODULE(angleInterval, mod) {
py::module::import("lsst.sphgeom.angle");

py::class_<AngleInterval, std::shared_ptr<AngleInterval>> cls(
mod, "AngleInterval");

template <>
void defineClass(
py::class_<AngleInterval, std::shared_ptr<AngleInterval>> &cls) {
python::defineInterval<decltype(cls), AngleInterval, Angle>(cls);

cls.def_static("fromDegrees", &AngleInterval::fromDegrees, "x"_a, "y"_a);
Expand All @@ -62,6 +57,5 @@ PYBIND11_MODULE(angleInterval, mod) {
});
}

} // <anonymous>
} // sphgeom
} // lsst
13 changes: 5 additions & 8 deletions python/lsst/sphgeom/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "pybind11/pybind11.h"

#include <memory>
#include "sphgeom.h"

#include "lsst/sphgeom/AngleInterval.h"
#include "lsst/sphgeom/Box.h"
Expand All @@ -42,20 +42,18 @@ using namespace pybind11::literals;

namespace lsst {
namespace sphgeom {
namespace {

namespace {
std::unique_ptr<Box> decode(py::bytes bytes) {
uint8_t const *buffer = reinterpret_cast<uint8_t const *>(
PYBIND11_BYTES_AS_STRING(bytes.ptr()));
size_t n = static_cast<size_t>(PYBIND11_BYTES_SIZE(bytes.ptr()));
return Box::decode(buffer, n);
}
}

PYBIND11_MODULE(box, mod) {
py::module::import("lsst.sphgeom.region");

py::class_<Box, std::unique_ptr<Box>, Region> cls(mod, "Box");

template <>
void defineClass(py::class_<Box, std::unique_ptr<Box>, Region> &cls) {
cls.attr("TYPE_CODE") = py::int_(Box::TYPE_CODE);

cls.def_static("fromDegrees", &Box::fromDegrees, "lon1"_a, "lat1"_a,
Expand Down Expand Up @@ -167,6 +165,5 @@ PYBIND11_MODULE(box, mod) {
[](py::bytes bytes) { return decode(bytes).release(); }));
}

} // <anonymous>
} // sphgeom
} // lsst
12 changes: 3 additions & 9 deletions python/lsst/sphgeom/box3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "pybind11/pybind11.h"

#include <memory>
#include "sphgeom.h"

#include "lsst/sphgeom/Box3d.h"
#include "lsst/sphgeom/python/relationship.h"
Expand All @@ -32,14 +32,9 @@ using namespace pybind11::literals;

namespace lsst {
namespace sphgeom {
namespace {

PYBIND11_MODULE(box3d, mod) {
py::module::import("lsst.sphgeom.interval1d");
py::module::import("lsst.sphgeom.vector3d");

py::class_<Box3d, std::shared_ptr<Box3d>> cls(mod, "Box3d");

template <>
void defineClass(py::class_<Box3d, std::shared_ptr<Box3d>> &cls) {
cls.def_static("empty", &Box3d::empty);
cls.def_static("full", &Box3d::full);
cls.def_static("aroundUnitSphere", &Box3d::aroundUnitSphere);
Expand Down Expand Up @@ -163,6 +158,5 @@ PYBIND11_MODULE(box3d, mod) {
});
}

} // <anonymous>
} // sphgeom
} // lsst
16 changes: 7 additions & 9 deletions python/lsst/sphgeom/chunker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include <memory>
#include "sphgeom.h"

#include "lsst/sphgeom/Chunker.h"

Expand All @@ -31,17 +31,16 @@ using namespace pybind11::literals;

namespace lsst {
namespace sphgeom {
namespace {

py::str toString(Chunker const & self) {
namespace {
py::str toString(Chunker const &self) {
return py::str("Chunker({!s}, {!s})")
.format(self.getNumStripes(), self.getNumSubStripesPerStripe());
}
}


PYBIND11_MODULE(chunker, mod) {
py::class_<Chunker, std::shared_ptr<Chunker>> cls(mod, "Chunker");

template <>
void defineClass(py::class_<Chunker, std::shared_ptr<Chunker>> &cls) {
cls.def(py::init<int32_t, int32_t>(), "numStripes"_a,
"numSubStripesPerStripe"_a);

Expand All @@ -57,7 +56,7 @@ PYBIND11_MODULE(chunker, mod) {
cls.def("getSubChunksIntersecting",
[](Chunker const &self, Region const &region) {
py::list results;
for (auto const & sc: self.getSubChunksIntersecting(region)) {
for (auto const &sc : self.getSubChunksIntersecting(region)) {
results.append(py::make_tuple(sc.chunkId, sc.subChunkIds));
}
return results;
Expand All @@ -76,6 +75,5 @@ PYBIND11_MODULE(chunker, mod) {
});
}

} // <anonymous>
} // sphgeom
} // lsst
13 changes: 5 additions & 8 deletions python/lsst/sphgeom/circle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "pybind11/pybind11.h"

#include <memory>
#include "sphgeom.h"

#include "lsst/sphgeom/Box.h"
#include "lsst/sphgeom/Circle.h"
Expand All @@ -38,20 +38,18 @@ using namespace pybind11::literals;

namespace lsst {
namespace sphgeom {
namespace {

namespace {
std::unique_ptr<Circle> decode(py::bytes bytes) {
uint8_t const *buffer = reinterpret_cast<uint8_t const *>(
PYBIND11_BYTES_AS_STRING(bytes.ptr()));
size_t n = static_cast<size_t>(PYBIND11_BYTES_SIZE(bytes.ptr()));
return Circle::decode(buffer, n);
}
}

PYBIND11_MODULE(circle, mod) {
py::module::import("lsst.sphgeom.region");

py::class_<Circle, std::unique_ptr<Circle>, Region> cls(mod, "Circle");

template <>
void defineClass(py::class_<Circle, std::unique_ptr<Circle>, Region> &cls) {
cls.attr("TYPE_CODE") = py::int_(Circle::TYPE_CODE);

cls.def_static("empty", &Circle::empty);
Expand Down Expand Up @@ -149,6 +147,5 @@ PYBIND11_MODULE(circle, mod) {
[](py::bytes bytes) { return decode(bytes).release(); }));
}

} // <anonymous>
} // sphgeom
} // lsst
16 changes: 6 additions & 10 deletions python/lsst/sphgeom/convexPolygon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include <memory>
#include "sphgeom.h"

#include "lsst/sphgeom/Box.h"
#include "lsst/sphgeom/Box3d.h"
#include "lsst/sphgeom/Circle.h"
#include "lsst/sphgeom/ConvexPolygon.h"
#include "lsst/sphgeom/Ellipse.h"
#include "lsst/sphgeom/Region.h"
#include "lsst/sphgeom/UnitVector3d.h"

#include "lsst/sphgeom/python/relationship.h"
Expand All @@ -40,21 +39,19 @@ using namespace pybind11::literals;

namespace lsst {
namespace sphgeom {
namespace {

namespace {
std::unique_ptr<ConvexPolygon> decode(py::bytes bytes) {
uint8_t const *buffer = reinterpret_cast<uint8_t const *>(
PYBIND11_BYTES_AS_STRING(bytes.ptr()));
size_t n = static_cast<size_t>(PYBIND11_BYTES_SIZE(bytes.ptr()));
return ConvexPolygon::decode(buffer, n);
}
}

PYBIND11_MODULE(convexPolygon, mod) {
py::module::import("lsst.sphgeom.region");

py::class_<ConvexPolygon, std::unique_ptr<ConvexPolygon>, Region> cls(
mod, "ConvexPolygon");

template <>
void defineClass(py::class_<ConvexPolygon, std::unique_ptr<ConvexPolygon>,
Region> &cls) {
cls.attr("TYPE_CODE") = py::int_(ConvexPolygon::TYPE_CODE);

cls.def_static("convexHull", &ConvexPolygon::convexHull, "points"_a);
Expand Down Expand Up @@ -90,6 +87,5 @@ PYBIND11_MODULE(convexPolygon, mod) {
[](py::bytes bytes) { return decode(bytes).release(); }));
}

} // <anonymous>
} // sphgeom
} // lsst
4 changes: 1 addition & 3 deletions python/lsst/sphgeom/curve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ using namespace pybind11::literals;

namespace lsst {
namespace sphgeom {
namespace {

PYBIND11_MODULE(curve, mod) {
void defineCurve(py::module &mod) {
mod.def("log2", (uint8_t(*)(uint64_t)) & log2);
mod.def("mortonIndex", (uint64_t(*)(uint32_t, uint32_t)) & mortonIndex,
"x"_a, "y"_a);
Expand All @@ -48,6 +47,5 @@ PYBIND11_MODULE(curve, mod) {
"h"_a, "m"_a);
}

} // <anonymous>
} // sphgeom
} // lsst