forked from lsst/qserv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mimic dependencies of lsst.log in lsst.utils
lsst.log depends on a couple functions in lsst.utils, and lsst.utils depends on numpy, but not for functions used by lsst.log. To reduce the run container size we remove numpy and "mimic" the functions in lsst.utils, by copying them into a duplicate module tree and installing into the qserv run image.
- Loading branch information
Showing
6 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,7 +224,6 @@ RUN pip3 install \ | |
deprecated \ | ||
jinja2 \ | ||
mysql-connector-python \ | ||
numpy \ | ||
pyyaml \ | ||
requests \ | ||
sqlalchemy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
install(DIRECTORY python/lsst/utils DESTINATION ${CMAKE_INSTALL_PREFIX}/python/lsst/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The mimic module has small amounts of python code copied from modules that we do | ||
not want to import all of, because of unused indirect dependencies, or | ||
installation time or size. | ||
|
||
For example, lsst.log depends on a couple functions in lsst.utils, and | ||
lsst.utils depends on numpy, but lsst.log does not indirectly depend on numpy; | ||
i.e. lsst.log does not use functions in lsst.utils that depend on numpy. Since | ||
the amount of code used by lsst.log in lsst.utils is small, we copy the code | ||
here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# This file is part of qserv. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
"""This module mimics the lsst.utils.wrappers.py module. | ||
This provides only the dependencies for modules we use (`lsst.log`) and reduces | ||
upstream dependencies, i.e. `lsst.utls` depends on numpy, but we don't need | ||
numpy for the `lsst.utils` functions used by `lsst.log` | ||
""" | ||
|
||
|
||
import sys | ||
|
||
|
||
def continueClass(cls): | ||
"""Re-open the decorated class, adding any new definitions into the | ||
original. | ||
For example: | ||
.. code-block:: python | ||
class Foo: | ||
pass | ||
@continueClass | ||
class Foo: | ||
def run(self): | ||
return None | ||
is equivalent to: | ||
.. code-block:: python | ||
class Foo: | ||
def run(self): | ||
return None | ||
.. warning:: | ||
Python's built-in `super` function does not behave properly in classes | ||
decorated with `continueClass`. Base class methods must be invoked | ||
directly using their explicit types instead. | ||
""" | ||
orig = getattr(sys.modules[cls.__module__], cls.__name__) | ||
for name in dir(cls): | ||
# Common descriptors like classmethod and staticmethod can only be | ||
# accessed without invoking their magic if we use __dict__; if we use | ||
# getattr on those we'll get e.g. a bound method instance on the dummy | ||
# class rather than a classmethod instance we can put on the target | ||
# class. | ||
attr = cls.__dict__.get(name, None) or getattr(cls, name) | ||
if isAttributeSafeToTransfer(name, attr): | ||
setattr(orig, name, attr) | ||
return orig | ||
|
||
|
||
INTRINSIC_SPECIAL_ATTRIBUTES = frozenset(( | ||
"__qualname__", | ||
"__module__", | ||
"__metaclass__", | ||
"__dict__", | ||
"__weakref__", | ||
"__class__", | ||
"__subclasshook__", | ||
"__name__", | ||
"__doc__", | ||
)) | ||
|
||
|
||
def isAttributeSafeToTransfer(name, value): | ||
"""Return True if an attribute is safe to monkeypatch-transfer to another | ||
class. | ||
This rejects special methods that are defined automatically for all | ||
classes, leaving only those explicitly defined in a class decorated by | ||
`continueClass` or registered with an instance of `TemplateMeta`. | ||
""" | ||
if name.startswith("__") and (value is getattr(object, name, None) | ||
or name in INTRINSIC_SPECIAL_ATTRIBUTES): | ||
return False | ||
return True |