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

Windows menuinst #3846

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
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 .github/workflows/windows_impl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ jobs:
$env:MAMBA_TEST_SHELL_TYPE='powershell'
Remove-Item -Path "env:CONDARC"
# Only rerun flaky tests on the `main` branch
python -m pytest micromamba/tests/ `
python -m pytest micromamba/tests/test_menuinst.py `
${{ runner.debug == 'true' && '-v --capture=tee-sys' || '--exitfirst' }} `
${{ github.ref == 'refs/heads/main' && '--reruns 3' || '' }}
4 changes: 4 additions & 0 deletions libmamba/src/core/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ namespace mamba

bool LinkPackage::execute()
{
// std::cout << "IN LinkPackage::execute()" << std::endl;
const auto& context = m_context->context();

nlohmann::json index_json, out_json;
Expand Down Expand Up @@ -1074,13 +1075,16 @@ namespace mamba
}

// Create all start menu shortcuts if prefix name doesn't start with underscore
// std::cout << "Creating all start menu shortcuts" << std::endl;
if (util::on_win && context.shortcuts
&& m_context->target_prefix.filename().string()[0] != '_')
{
for (auto& path : paths_data)
{
// std::cout << "path.path is: " << path.path << std::endl;
if (std::regex_match(path.path, MENU_PATH_REGEX))
{
std::cout << "yes matching regex: " << path.path << std::endl;
create_menu_from_json(context, m_context->target_prefix / path.path, m_context);
}
}
Expand Down
15 changes: 15 additions & 0 deletions libmamba/src/core/menuinst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// The full license is in the file LICENSE, distributed with this software.

#include <iostream>
#include <string>

#include "mamba/util/path_manip.hpp"
Expand Down Expand Up @@ -260,6 +261,7 @@ namespace mamba
[[maybe_unused]] bool remove
)
{
std::cout << "IN create_remove_shortcut_impl" << std::endl;
std::string json_content = mamba::read_contents(json_file);
replace_variables(ctx, json_content, transaction_context);
auto j = nlohmann::json::parse(json_content);
Expand All @@ -275,6 +277,7 @@ namespace mamba
}

#ifdef _WIN32
std::cout << "#ifdef _WIN32 CASE" << std::endl;

// {
// "menu_name": "Miniforge${PY_VER}",
Expand Down Expand Up @@ -333,13 +336,22 @@ namespace mamba
}
};

std::cout << "Before for loop " << std::endl;
for (auto& item : j["menu_items"])
{
std::cout << "IN for loop " << std::endl;
std::string name = item["name"];
std::cout << "Item name: " << name << std::endl;
std::string full_name = util::concat(name, name_suffix);
std::cout << "full name: " << full_name << std::endl;

std::vector<std::string> arguments;
fs::u8path script;
for (auto& el : item.items())
{
std::cout << "Key: " << el.key() << ", Value: " << el.value() << std::endl;
}
std::cout << "BEFORE checking content " << std::endl;
if (item.contains("pywscript"))
{
script = root_pyw;
Expand Down Expand Up @@ -386,8 +398,10 @@ namespace mamba
fs::u8path dst = target_dir / (full_name + ".lnk");
fs::u8path workdir = item.value("workdir", "");
fs::u8path iconpath = item.value("icon", "");
std::cout << "Before checking false case" << std::endl;
if (remove == false)
{
std::cout << "false case" << std::endl;
std::string argstring;
std::string lscript = util::to_lower(script.string());

Expand Down Expand Up @@ -429,6 +443,7 @@ namespace mamba
}

mamba::win::create_shortcut(script, full_name, dst, argstring, workdir, iconpath, 0);
std::cout << "END false case" << std::endl;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/core/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ namespace mamba
bool
MTransaction::execute(const Context& ctx, ChannelContext& channel_context, PrefixData& prefix)
{
std::cout << "EXECUTING TRANSACTION " << std::endl;
// JSON output
// back to the top level if any action was required
if (!empty())
Expand Down
9 changes: 7 additions & 2 deletions micromamba/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,18 @@ def create(
cmd += ["--dry-run"]

try:
res = subprocess_run(*cmd, **kwargs)
print(f"Executing cmd: '{' '.join(cmd)}'")
# res = subprocess_run(*cmd, **kwargs)
res = subprocess.run(cmd, capture_output=True, **kwargs)
print(res.stdout.decode())
print(res.stderr.decode())
if "--json" in args:
j = json.loads(res)
return j
if "--print-config-only" in args:
return yaml.load(res, Loader=yaml.FullLoader)
return res.decode()
# return res.decode()
return res.stdout.decode()
except subprocess.CalledProcessError as e:
print(f"Error when executing '{' '.join(cmd)}'")
raise (e)
Expand Down
20 changes: 20 additions & 0 deletions micromamba/tests/test_menuinst.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,23 @@ def test_shortcut_weird_env(self):

shutil.rmtree(root_prefix)
os.environ["MAMBA_ROOT_PREFIX"] = self.root_prefix

@pytest.mark.skipif(
not sys.platform.startswith("win"),
reason="skipping windows-only tests",
)
def test_spyder_shortcut(self):
env_name = random_string()
create("python=3.12", "spyder=6.0.3", "-n", env_name, no_dry_run=True)
print("menuinst.win32.dirs_src: ", menuinst.win32.dirs_src)
d = menuinst.win32.dirs_src["user"]["start"][0]
list_start_dirs = os.listdir(d)
print("ls: ", list_start_dirs)
# distribution_name = os.getenv("DISTRIBUTION_NAME")
for el in list_start_dirs:
el_path = os.path.join(d, el)
if os.path.isdir(el_path):
print("ls ", el_path, ": ", os.listdir(el_path))
# spyder_path = os.path.join(d, "spyder")
# print("ls spyder path: ", os.listdir(spyder_path))
assert False
Loading