Skip to content

Commit

Permalink
add index_url paramter for setup env
Browse files Browse the repository at this point in the history
  • Loading branch information
yhkl-dev committed Dec 14, 2024
1 parent e74d7c9 commit a424619
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
6 changes: 5 additions & 1 deletion contrib/packs/actions/pack_mgmt/setup_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ def __init__(self, config=None, action_service=None):
):
os.environ["no_proxy"] = self.no_proxy

def run(self, packs, update=False, no_download=True):
def run(self, packs, index_url, update=False, no_download=True):
"""
:param packs: A list of packs to create the environment for.
:type: packs: ``list``
:param update: True to update dependencies inside the virtual environment.
:type update: ``bool``
:param index_url: Package index options.
:type index_url: ``str``
"""

for pack_name in packs:
Expand All @@ -96,6 +99,7 @@ def run(self, packs, update=False, no_download=True):
logger=self.logger,
proxy_config=self.proxy_config,
no_download=no_download,
index_url=index_url,
)

message = "Successfully set up virtualenv for the following packs: %s" % (
Expand Down
6 changes: 6 additions & 0 deletions contrib/packs/actions/setup_virtualenv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@
required: false
description: Action timeout in seconds. Action will get killed if it doesn't finish in timeout
type: integer
index_url:
default: "https://pypi.org/simple"
required: false
description: Package Index options
type: string

7 changes: 7 additions & 0 deletions st2common/st2common/cmd/setup_pack_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def _register_cli_opts():
"exist, it will create it.."
),
),
cfg.StrOpt(
"index_url",
default=False,
help="Package Index options",
),
]
do_register_cli_opts(cli_opts)

Expand All @@ -64,6 +69,7 @@ def main(argv):

packs = cfg.CONF.pack
update = cfg.CONF.update
index_url = cfg.CONF.index_url

proxy_config = get_and_set_proxy_config()

Expand All @@ -76,6 +82,7 @@ def main(argv):
logger=LOG,
proxy_config=proxy_config,
no_download=True,
index_url=index_url,
)
LOG.info('Successfully set up virtualenv for pack "%s"' % (pack))

Expand Down
13 changes: 11 additions & 2 deletions st2common/st2common/util/virtualenvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def setup_pack_virtualenv(
no_download=True,
force_owner_group=True,
inject_parent_virtualenv_sites=True,
index_url=None,
):

"""
Expand All @@ -78,6 +79,9 @@ def setup_pack_virtualenv(
:param no_download: Do not download and install latest version of pre-installed packages such
as pip and setuptools.
:type no_download: ``bool``
:param index_url: Package index options.
:type index_url: ``str``
"""
logger = logger or LOG

Expand Down Expand Up @@ -137,6 +141,7 @@ def setup_pack_virtualenv(
requirement=requirement,
proxy_config=proxy_config,
logger=logger,
index_url=index_url,
)

# 4. Install pack-specific requirements
Expand All @@ -152,6 +157,7 @@ def setup_pack_virtualenv(
requirements_file_path=requirements_file_path,
proxy_config=proxy_config,
logger=logger,
index_url=index_url,
)
else:
logger.debug("No pack specific requirements found")
Expand Down Expand Up @@ -319,7 +325,7 @@ def inject_st2_pth_into_virtualenv(virtualenv_path: str, logger: Logger = None)


def install_requirements(
virtualenv_path, requirements_file_path, proxy_config=None, logger=None
virtualenv_path, requirements_file_path, proxy_config=None, logger=None, index_url=None,
):
"""
Install requirements from a file.
Expand All @@ -346,6 +352,7 @@ def install_requirements(
cmd.append("install")
cmd.extend(pip_opts)
cmd.extend(["-U", "-r", requirements_file_path])
cmd.extend(["-i", index_url])

env = get_env_for_subprocess_command()

Expand All @@ -372,7 +379,7 @@ def install_requirements(
return True


def install_requirement(virtualenv_path, requirement, proxy_config=None, logger=None):
def install_requirement(virtualenv_path, requirement, proxy_config=None, logger=None, index_url=None,):
"""
Install a single requirement.
Expand Down Expand Up @@ -400,6 +407,8 @@ def install_requirement(virtualenv_path, requirement, proxy_config=None, logger=
cmd.append("install")
cmd.extend(pip_opts)
cmd.extend([requirement])
cmd.extend(["-i", index_url])

env = get_env_for_subprocess_command()
logger.debug(
"Installing requirement %s with command %s.", requirement, " ".join(cmd)
Expand Down

0 comments on commit a424619

Please sign in to comment.