Skip to content

Commit

Permalink
Merge pull request #5930: Add pants source roots and a constant for p…
Browse files Browse the repository at this point in the history
…ack common lib directory
  • Loading branch information
cognifloyd authored Mar 10, 2023
2 parents c5ec5b0 + c97aa6e commit 3803450
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Added
to pants' use of PEX lockfiles. This is not a user-facing addition.
#5778 #5789 #5817 #5795 #5830 #5833 #5834 #5841 #5840 #5838 #5842 #5837 #5849 #5850
#5846 #5853 #5848 #5847 #5858 #5857 #5860 #5868 #5871 #5864 #5874 #5884 #5893 #5891
#5890 #5898 #5901 #5906 #5899 #5907 #5909 #5922 #5926 #5927 #5925 #5928 #5929
#5890 #5898 #5901 #5906 #5899 #5907 #5909 #5922 #5926 #5927 #5925 #5928 #5929 #5930
Contributed by @cognifloyd

* Added a joint index to solve the problem of slow mongo queries for scheduled executions. #5805
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
)
from st2common.constants.action import LIVEACTION_STATUS_TIMED_OUT
from st2common.constants.action import MAX_PARAM_LENGTH
from st2common.constants.pack import COMMON_LIB_DIR
from st2common.constants.pack import SYSTEM_PACK_NAME
from st2common.persistence.execution import ActionExecutionOutput
from python_runner.python_action_wrapper import PythonActionWrapper
Expand Down Expand Up @@ -951,7 +952,7 @@ def test_content_version_contains_common_libs_config_enabled(

_, call_kwargs = mock_popen.call_args
actual_env = call_kwargs["env"]
pack_common_lib_path = os.path.join(runner.git_worktree_path, "lib")
pack_common_lib_path = os.path.join(runner.git_worktree_path, COMMON_LIB_DIR)
self.assertIn("PYTHONPATH", actual_env)
self.assertIn(pack_common_lib_path, actual_env["PYTHONPATH"])

Expand Down
7 changes: 5 additions & 2 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ root_patterns = [
"/contrib/packs",
"/st2tests/testpacks/checks",
"/st2tests/testpacks/errorcheck",
# odd import in examples.isprime
"/contrib/examples/lib",
# pack common lib directories that ST2 adds to the PATH for actions/sensors
"/contrib/*/lib",
"/contrib/*/actions/lib",
# other special-cased pack directories
"/contrib/examples/actions/ubuntu_pkg_info", # python script runs via shell expecting cwd in PYTHONPATH
# lint plugins
"/pylint_plugins",
# pants plugins
Expand Down
3 changes: 3 additions & 0 deletions st2common/st2common/constants/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

__all__ = [
"COMMON_LIB_DIR",
"PACKS_PACK_NAME",
"PACK_REF_WHITELIST_REGEX",
"RESERVED_PACK_LIST",
Expand All @@ -32,6 +33,8 @@
"CONFIG_SCHEMA_FILE_NAME",
]

COMMON_LIB_DIR = "lib"

# Prefix for render context w/ config
PACK_CONFIG_CONTEXT_KV_PREFIX = "config_context"

Expand Down
3 changes: 2 additions & 1 deletion st2common/st2common/util/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from collections.abc import Iterable
from st2common.util import schema as util_schema
from st2common.constants.pack import COMMON_LIB_DIR
from st2common.constants.pack import MANIFEST_FILE_NAME
from st2common.constants.pack import PACK_REF_WHITELIST_REGEX
from st2common.constants.pack import RESERVED_PACK_LIST
Expand Down Expand Up @@ -215,7 +216,7 @@ def get_pack_common_libs_path_for_pack_db(pack_db):
if not pack_dir:
return None

libs_path = os.path.join(pack_dir, "lib")
libs_path = os.path.join(pack_dir, COMMON_LIB_DIR)

return libs_path

Expand Down
5 changes: 4 additions & 1 deletion st2common/st2common/util/sandboxing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from oslo_config import cfg

from st2common.constants.action import LIBS_DIR as ACTION_LIBS_DIR
from st2common.constants.pack import SYSTEM_PACK_NAMES
from st2common.content.utils import get_pack_base_path

Expand Down Expand Up @@ -149,7 +150,9 @@ def get_sandbox_python_path_for_python_action(
]

# Add the pack's lib directory (lib/python3.x) in front of the PYTHONPATH.
pack_actions_lib_paths = os.path.join(pack_base_path, "actions", "lib")
pack_actions_lib_paths = os.path.join(
pack_base_path, "actions", ACTION_LIBS_DIR
)
pack_virtualenv_lib_path = os.path.join(virtualenv_path, "lib")
pack_venv_lib_directory = os.path.join(
pack_virtualenv_lib_path, virtualenv_directories[0]
Expand Down

0 comments on commit 3803450

Please sign in to comment.