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

Fix python-minimal installation issues #1240

Merged
merged 3 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ possible.
Development Site
================

The current development version is 2.6.0b1. The current stable version is
The current development version is 2.6.0b2. The current stable version is
2.5.1. The `latest Cantera source code <https://github.com/Cantera/cantera>`_,
the `issue tracker <https://github.com/Cantera/cantera/issues>`_ for bugs and
enhancement requests, `downloads of Cantera releases and binary installers
Expand Down
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ for arg in ARGUMENTS:
logger.error(f"Encountered unexpected command line option: '{arg}'")
sys.exit(1)

env["cantera_version"] = "2.6.0b1"
env["cantera_version"] = "2.6.0b2"
# For use where pre-release tags are not permitted (MSI, sonames)
env['cantera_pure_version'] = re.match(r'(\d+\.\d+\.\d+)', env['cantera_version']).group(0)
env['cantera_short_version'] = re.match(r'(\d+\.\d+)', env['cantera_version']).group(0)
Expand Down
2 changes: 1 addition & 1 deletion doc/doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = Cantera
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.6.0b1
PROJECT_NUMBER = 2.6.0b2

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/ck2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ def write_yaml(self, name='gas', out_name='mech.yaml'):
metadata = BlockMap([
("generator", "ck2yaml"),
("input-files", FlowList(files)),
("cantera-version", "2.6.0b1"),
("cantera-version", "2.6.0b2"),
("date", formatdate(localtime=True)),
])
if desc.strip():
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/cti2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ def convert(filename=None, output_name=None, text=None, encoding="latin-1"):
# information regarding conversion
metadata = BlockMap([
("generator", "cti2yaml"),
("cantera-version", "2.6.0b1"),
("cantera-version", "2.6.0b2"),
("date", formatdate(localtime=True)),
])
if filename != "<string>":
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/ctml2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2641,7 +2641,7 @@ def convert(
metadata = BlockMap(
{
"generator": "ctml2yaml",
"cantera-version": "2.6.0b1",
"cantera-version": "2.6.0b2",
"date": formatdate(localtime=True),
}
)
Expand Down
47 changes: 44 additions & 3 deletions interfaces/python_minimal/SConscript
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Minimal Python Module"""
from pathlib import Path
from buildutils import *
import json
import re

Import('env', 'build', 'install')

Expand Down Expand Up @@ -32,17 +34,56 @@ localenv.Depends(mod, [make_setup, readme, license, "setup.py", "pyproject.toml"
install_cmd = ["$python_cmd_esc", "-m", "pip", "install"]
user_install = False
python_prefix = None
python_root = None
if localenv["PYTHON_INSTALLER"] == "direct":
if localenv["python_prefix"] == "USER":
# Install to the OS-dependent user site-packages directory
install_cmd.append("--user")
user_install = True
elif localenv["python_prefix"]:
# A specific location for the Cantera python module has been given
install_cmd.extend((f"--prefix={localenv.subst('python_prefix')}",
install_cmd.extend((f"--prefix={localenv.subst('$python_prefix')}",
"--no-warn-script-location"))
python_prefix = localenv.subst("python_prefix")
python_prefix = localenv.subst("$python_prefix")
elif not env["default_prefix"]:
install_cmd.append(f"--prefix={env['prefix']}")
python_prefix = env["prefix"]

# Get information about installation paths
script = """\
import json
import site
vars = {
"site_packages": site.getsitepackages(),
"user_site_packages": site.getusersitepackages(),
}
print(json.dumps(vars))
"""
info = json.loads(get_command_output(localenv["python_cmd"], "-c", script))
site_packages = info["site_packages"]
user_site_packages = info["user_site_packages"]

# Check for existing Python module installation. Allow pip to remove an existing
# installation only if we're installing to the same location. Also disable
# uninstallation if we're installing to a staging directory.
if env["stage_dir"]:
install_cmd.append("--ignore-installed")
else:
info = get_command_output(
localenv["python_cmd"], "-m", "pip", "show", "cantera-minimal",
ignore_errors=True
)

if user_install:
test_prefix = Path(user_site_packages).parents[2]
elif python_prefix is None:
test_prefix = Path(site_packages[0]).parents[2]
else:
test_prefix = Path(python_prefix)

match = re.search(r"Location: (.*)\n", info, re.MULTILINE)
existing_prefix = Path(match.group(1)).parents[2] if match else None
if existing_prefix and existing_prefix != test_prefix:
install_cmd.append("--ignore-installed")

if env["stage_dir"]:
# Get the absolute path to the stage directory. If the stage directory is a relative
Expand Down