Skip to content

Commit

Permalink
Some future proofing MatchSpec (#3082)
Browse files Browse the repository at this point in the history
* Private MatchSpec::name

* Private MatchSpec::filename

* Private MatchSpec::url

* Make MatchSpec::is_file a function

* Private MatchSpec::namespace

* Private MatchSpec::build_number

* Remove dead affectation

* Private MatchSpec::optional

* Remove dead code

* Clean MatchSpec dist parsing

* Fix MatchSpec dist parse

* Private MatchSpec::version

* Private MatchSpec::build_string

* Private MatchSpec::channel

* Add missing MatchSpec setters

* Put MatchSpec in specs::
  • Loading branch information
AntoinePrv authored Dec 26, 2023
1 parent 6bd785d commit 15e8056
Show file tree
Hide file tree
Showing 32 changed files with 534 additions and 382 deletions.
4 changes: 2 additions & 2 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ set(
${LIBMAMBA_SOURCE_DIR}/specs/repo_data.cpp
${LIBMAMBA_SOURCE_DIR}/specs/version.cpp
${LIBMAMBA_SOURCE_DIR}/specs/version_spec.cpp
${LIBMAMBA_SOURCE_DIR}/specs/match_spec.cpp
# Artifacts validation
${LIBMAMBA_SOURCE_DIR}/validation/tools.cpp
${LIBMAMBA_SOURCE_DIR}/validation/errors.cpp
Expand All @@ -200,7 +201,6 @@ set(
${LIBMAMBA_SOURCE_DIR}/core/transaction_context.cpp
${LIBMAMBA_SOURCE_DIR}/core/link.cpp
${LIBMAMBA_SOURCE_DIR}/core/history.cpp
${LIBMAMBA_SOURCE_DIR}/core/match_spec.cpp
${LIBMAMBA_SOURCE_DIR}/core/menuinst.cpp
${LIBMAMBA_SOURCE_DIR}/core/mirror.cpp
${LIBMAMBA_SOURCE_DIR}/core/output.cpp
Expand Down Expand Up @@ -288,6 +288,7 @@ set(
${LIBMAMBA_INCLUDE_DIR}/mamba/specs/repo_data.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/specs/version.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/specs/version_spec.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/specs/match_spec.hpp
# Artifacts validation
${LIBMAMBA_INCLUDE_DIR}/mamba/validation/tools.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/validation/errors.hpp
Expand All @@ -308,7 +309,6 @@ set(
${LIBMAMBA_INCLUDE_DIR}/mamba/core/satisfiability_error.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/history.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/link.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/match_spec.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/menuinst.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/mirror.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/output.hpp
Expand Down
4 changes: 2 additions & 2 deletions libmamba/include/mamba/api/install.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include <solv/solver.h>
#include <yaml-cpp/yaml.h>

#include "mamba/core/match_spec.hpp"
#include "mamba/core/package_cache.hpp"
#include "mamba/core/package_info.hpp"
#include "mamba/core/pool.hpp"
#include "mamba/core/repo.hpp"
#include "mamba/fs/filesystem.hpp"
#include "mamba/specs/match_spec.hpp"

namespace mamba
{
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace mamba

yaml_file_contents read_yaml_file(fs::u8path yaml_file, const std::string platform);

std::tuple<std::vector<PackageInfo>, std::vector<MatchSpec>>
std::tuple<std::vector<PackageInfo>, std::vector<specs::MatchSpec>>
parse_urls_to_package_info(const std::vector<std::string>& urls);

inline void to_json(nlohmann::json&, const other_pkg_mgr_spec&)
Expand Down
6 changes: 3 additions & 3 deletions libmamba/include/mamba/core/history.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <unordered_map>
#include <vector>

#include "mamba/core/channel_context.hpp"
#include "mamba/fs/filesystem.hpp"

#include "match_spec.hpp"
#include "mamba/specs/match_spec.hpp"

namespace mamba
{
Expand Down Expand Up @@ -52,7 +52,7 @@ namespace mamba
std::vector<ParseResult> parse();
bool parse_comment_line(const std::string& line, UserRequest& req);
std::vector<UserRequest> get_user_requests();
std::unordered_map<std::string, MatchSpec> get_requested_specs_map();
std::unordered_map<std::string, specs::MatchSpec> get_requested_specs_map();
void add_entry(const History::UserRequest& entry);

fs::u8path m_prefix;
Expand Down
4 changes: 1 addition & 3 deletions libmamba/include/mamba/core/link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
#define MAMBA_CORE_LINK

#include <regex>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#include "mamba/core/package_info.hpp"
#include "mamba/fs/filesystem.hpp"
#include "mamba/util/build.hpp"

#include "match_spec.hpp"
#include "package_paths.hpp"
#include "transaction.hpp"
#include "transaction_context.hpp"

namespace mamba
Expand Down
48 changes: 0 additions & 48 deletions libmamba/include/mamba/core/match_spec.hpp

This file was deleted.

8 changes: 6 additions & 2 deletions libmamba/include/mamba/core/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace mamba
{
class MatchSpec;
class ChannelContext;
class Context;

Expand All @@ -25,6 +24,11 @@ namespace mamba
class ObjPool;
}

namespace specs
{
class MatchSpec;
}

/**
* Pool of solvable involved in resolving en environment.
*
Expand All @@ -44,7 +48,7 @@ namespace mamba
void create_whatprovides();

std::vector<Id> select_solvables(Id id, bool sorted = false) const;
Id matchspec2id(const MatchSpec& ms);
Id matchspec2id(const specs::MatchSpec& ms);

std::optional<PackageInfo> id2pkginfo(Id solv_id) const;
std::optional<std::string> dep2str(Id dep_id) const;
Expand Down
12 changes: 5 additions & 7 deletions libmamba/include/mamba/core/satisfiability_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@
#include <array>
#include <functional>
#include <initializer_list>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>
#include <variant>
#include <vector>

#include <fmt/color.h>

#include "mamba/core/match_spec.hpp"
#include "mamba/core/package_info.hpp"
#include "mamba/specs/match_spec.hpp"
#include "mamba/util/flat_set.hpp"
#include "mamba/util/graph.hpp"

Expand Down Expand Up @@ -81,17 +79,17 @@ namespace mamba
{
};

struct UnresolvedDependencyNode : MatchSpec
struct UnresolvedDependencyNode : specs::MatchSpec
{
};

struct ConstraintNode : MatchSpec
struct ConstraintNode : specs::MatchSpec
{
};

using node_t = std::variant<RootNode, PackageNode, UnresolvedDependencyNode, ConstraintNode>;

using edge_t = MatchSpec;
using edge_t = specs::MatchSpec;

using graph_t = util::DiGraph<node_t, edge_t>;
using node_id = graph_t::node_id;
Expand Down Expand Up @@ -213,7 +211,7 @@ namespace mamba
UnresolvedDependencyListNode,
ConstraintListNode>;

using edge_t = NamedList<MatchSpec>;
using edge_t = NamedList<specs::MatchSpec>;

using graph_t = util::DiGraph<node_t, edge_t>;
using node_id = graph_t::node_id;
Expand Down
21 changes: 10 additions & 11 deletions libmamba/include/mamba/core/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include "mamba/core/package_info.hpp"
#include "mamba/core/pool.hpp"
#include "mamba/core/satisfiability_error.hpp"

#include "match_spec.hpp"
#include "mamba/specs/match_spec.hpp"

#define PY_MAMBA_NO_DEPS 0b0001
#define PY_MAMBA_ONLY_DEPS 0b0010
Expand Down Expand Up @@ -105,10 +104,10 @@ namespace mamba
[[nodiscard]] MPool& pool() &;
[[nodiscard]] MPool&& pool() &&;

[[nodiscard]] const std::vector<MatchSpec>& install_specs() const;
[[nodiscard]] const std::vector<MatchSpec>& remove_specs() const;
[[nodiscard]] const std::vector<MatchSpec>& neuter_specs() const;
[[nodiscard]] const std::vector<MatchSpec>& pinned_specs() const;
[[nodiscard]] const std::vector<specs::MatchSpec>& install_specs() const;
[[nodiscard]] const std::vector<specs::MatchSpec>& remove_specs() const;
[[nodiscard]] const std::vector<specs::MatchSpec>& neuter_specs() const;
[[nodiscard]] const std::vector<specs::MatchSpec>& pinned_specs() const;

operator const Solver*() const;
operator Solver*();
Expand All @@ -118,10 +117,10 @@ namespace mamba
private:

std::vector<std::pair<int, int>> m_libsolv_flags;
std::vector<MatchSpec> m_install_specs;
std::vector<MatchSpec> m_remove_specs;
std::vector<MatchSpec> m_neuter_specs;
std::vector<MatchSpec> m_pinned_specs;
std::vector<specs::MatchSpec> m_install_specs;
std::vector<specs::MatchSpec> m_remove_specs;
std::vector<specs::MatchSpec> m_neuter_specs;
std::vector<specs::MatchSpec> m_pinned_specs;
// Order of m_pool and m_solver is critical since m_pool must outlive m_solver.
MPool m_pool;
// Temporary Pimpl all libsolv to keep it private
Expand All @@ -130,7 +129,7 @@ namespace mamba
Flags m_flags = {};
bool m_is_solved;

void add_reinstall_job(MatchSpec& ms, int job_flag);
void add_reinstall_job(const specs::MatchSpec& ms, int job_flag);
void apply_libsolv_flags();
};
} // namespace mamba
Expand Down
8 changes: 4 additions & 4 deletions libmamba/include/mamba/core/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include "mamba/api/install.hpp"
#include "mamba/fs/filesystem.hpp"
#include "mamba/specs/match_spec.hpp"

#include "match_spec.hpp"
#include "package_cache.hpp"
#include "package_info.hpp"
#include "pool.hpp"
Expand All @@ -33,8 +33,8 @@ namespace mamba

MTransaction(
MPool& pool,
const std::vector<MatchSpec>& specs_to_remove,
const std::vector<MatchSpec>& specs_to_install,
const std::vector<specs::MatchSpec>& specs_to_remove,
const std::vector<specs::MatchSpec>& specs_to_install,
MultiPackageCache& caches
);
MTransaction(MPool& pool, MSolver& solver, MultiPackageCache& caches);
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace mamba

History::UserRequest m_history_entry;

std::vector<MatchSpec> m_requested_specs;
std::vector<specs::MatchSpec> m_requested_specs;

MTransaction(MPool&, MultiPackageCache&);
};
Expand Down
13 changes: 6 additions & 7 deletions libmamba/include/mamba/core/transaction_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@

#include <reproc++/reproc.hpp>

#include "mamba/core/context.hpp"
#include "mamba/core/util.hpp"
#include "mamba/fs/filesystem.hpp"

#include "context.hpp"
#include "match_spec.hpp"
#include "util.hpp"
#include "mamba/specs/match_spec.hpp"

namespace mamba
{
Expand All @@ -42,15 +41,15 @@ namespace mamba
const Context& context,
const fs::u8path& target_prefix,
const std::pair<std::string, std::string>& py_versions,
const std::vector<MatchSpec>& requested_specs
const std::vector<specs::MatchSpec>& requested_specs
);

TransactionContext(
const Context& context,
const fs::u8path& target_prefix,
const fs::u8path& relocate_prefix,
const std::pair<std::string, std::string>& py_versions,
const std::vector<MatchSpec>& requested_specs
const std::vector<specs::MatchSpec>& requested_specs
);
~TransactionContext();
bool try_pyc_compilation(const std::vector<fs::u8path>& py_files);
Expand All @@ -70,7 +69,7 @@ namespace mamba
bool compile_pyc = true;
// this needs to be done when python version changes
bool relink_noarch = false;
std::vector<MatchSpec> requested_specs;
std::vector<specs::MatchSpec> requested_specs;

const Context& context() const
{
Expand Down
Loading

0 comments on commit 15e8056

Please sign in to comment.