Skip to content

Commit e1dc8a2

Browse files
committed
maint: YAML environment specification utilities
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
1 parent 7603af9 commit e1dc8a2

File tree

12 files changed

+1353
-257
lines changed

12 files changed

+1353
-257
lines changed

libmamba/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ set(
270270
${LIBMAMBA_SOURCE_DIR}/api/configuration.cpp
271271
${LIBMAMBA_SOURCE_DIR}/api/create.cpp
272272
${LIBMAMBA_SOURCE_DIR}/api/env.cpp
273+
${LIBMAMBA_SOURCE_DIR}/api/environment_yaml.cpp
274+
${LIBMAMBA_SOURCE_DIR}/api/export.cpp
273275
${LIBMAMBA_SOURCE_DIR}/api/info.cpp
274276
${LIBMAMBA_SOURCE_DIR}/api/install.cpp
275277
${LIBMAMBA_SOURCE_DIR}/api/list.cpp
@@ -423,6 +425,8 @@ set(
423425
${LIBMAMBA_INCLUDE_DIR}/mamba/api/constants.hpp
424426
${LIBMAMBA_INCLUDE_DIR}/mamba/api/create.hpp
425427
${LIBMAMBA_INCLUDE_DIR}/mamba/api/env.hpp
428+
${LIBMAMBA_INCLUDE_DIR}/mamba/api/environment_yaml.hpp
429+
${LIBMAMBA_INCLUDE_DIR}/mamba/api/export.hpp
426430
${LIBMAMBA_INCLUDE_DIR}/mamba/api/info.hpp
427431
${LIBMAMBA_INCLUDE_DIR}/mamba/api/install.hpp
428432
${LIBMAMBA_INCLUDE_DIR}/mamba/api/list.hpp
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2019, QuantStack and Mamba Contributors
2+
//
3+
// Distributed under the terms of the BSD 3-Clause License.
4+
//
5+
// The full license is in the file LICENSE, distributed with this software.
6+
7+
#ifndef MAMBA_API_ENVIRONMENT_YAML_HPP
8+
#define MAMBA_API_ENVIRONMENT_YAML_HPP
9+
10+
#include <iosfwd>
11+
#include <map>
12+
#include <string>
13+
#include <vector>
14+
15+
#include "mamba/fs/filesystem.hpp"
16+
17+
// Include install.hpp for other_pkg_mgr_spec definition (needed by yaml_file_contents)
18+
#include "mamba/api/install.hpp"
19+
20+
namespace mamba
21+
{
22+
class Context;
23+
class PrefixData;
24+
25+
namespace detail
26+
{
27+
// yaml_file_contents is now defined here instead of install.hpp
28+
struct yaml_file_contents
29+
{
30+
std::string name;
31+
std::string prefix;
32+
std::vector<std::string> dependencies, channels;
33+
std::map<std::string, std::string> variables;
34+
std::vector<other_pkg_mgr_spec> others_pkg_mgrs_specs;
35+
};
36+
}
37+
38+
// Convert PrefixData to yaml_file_contents
39+
detail::yaml_file_contents prefix_to_yaml_contents(
40+
const PrefixData& prefix_data,
41+
const Context& ctx,
42+
const std::string& env_name = "",
43+
bool no_builds = false,
44+
bool ignore_channels = false
45+
);
46+
47+
// Write yaml_file_contents to output stream
48+
void yaml_contents_to_stream(const detail::yaml_file_contents& contents, std::ostream& out);
49+
50+
// Write yaml_file_contents to YAML file
51+
void
52+
yaml_contents_to_file(const detail::yaml_file_contents& contents, const fs::u8path& yaml_file_path);
53+
54+
// Read YAML file to yaml_file_contents
55+
detail::yaml_file_contents file_to_yaml_contents(
56+
const Context& ctx,
57+
const std::string& yaml_file,
58+
const std::string& platform,
59+
bool use_uv = false
60+
);
61+
}
62+
63+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2019, QuantStack and Mamba Contributors
2+
//
3+
// Distributed under the terms of the BSD 3-Clause License.
4+
//
5+
// The full license is in the file LICENSE, distributed with this software.
6+
7+
#ifndef MAMBA_API_EXPORT_HPP
8+
#define MAMBA_API_EXPORT_HPP
9+
10+
#include "mamba/api/configuration.hpp"
11+
12+
namespace mamba
13+
{
14+
class Configuration;
15+
16+
void export_environment(Configuration& config);
17+
}
18+
19+
#endif

libmamba/include/mamba/api/install.hpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,11 @@ namespace mamba
112112

113113
bool operator==(const other_pkg_mgr_spec& s1, const other_pkg_mgr_spec& s2);
114114

115-
struct yaml_file_contents
116-
{
117-
std::string name;
118-
std::vector<std::string> dependencies, channels;
119-
std::map<std::string, std::string> variables;
120-
std::vector<other_pkg_mgr_spec> others_pkg_mgrs_specs;
121-
};
115+
// yaml_file_contents moved to environment_yaml.hpp
116+
struct yaml_file_contents; // Forward declaration
122117

123118
bool eval_selector(const std::string& selector, const std::string& platform);
124119

125-
yaml_file_contents read_yaml_file(
126-
const Context& ctx,
127-
const std::string& yaml_file,
128-
const std::string& platform,
129-
bool use_uv
130-
);
131-
132120
inline void to_json(nlohmann::json&, const other_pkg_mgr_spec&)
133121
{
134122
}

0 commit comments

Comments
 (0)