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

Filesystem library #2879

Merged
merged 5 commits into from
Oct 5, 2023
Merged

Filesystem library #2879

merged 5 commits into from
Oct 5, 2023

Conversation

AntoinePrv
Copy link
Member

No description provided.

libmamba/include/mamba/filesystem/u8path.hpp Outdated Show resolved Hide resolved
libmamba/include/mamba/filesystem/u8path.hpp Outdated Show resolved Hide resolved
libmamba/include/mamba/filesystem/u8path.hpp Outdated Show resolved Hide resolved
libmamba/include/mamba/filesystem/u8path.hpp Outdated Show resolved Hide resolved
libmamba/src/filesystem/u8path.cpp Outdated Show resolved Hide resolved
static constexpr wchar_t platform_separator = L'\\';
static constexpr wchar_t other_separator = L'/';

auto pos = native_string.find(other_separator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was util::replace_all not good enough here? Also I would prefer this loop to be a function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I am trying to get to a state of multiple internal "libraries" where there is no cyclic dependencies between them.
The goal is to restrict what code can be used where, so that for instance "filesystem" or "util" does not start calling code form "core". These restrictions would then restrict the opportunities for spaghetti code.

Or maybe I am being too dogmatic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine but it's not clear to me how this is related to this code, is it because otherwise there is a cyclic dependency between the filesystem and utils? If so, maybe isolating that specific replace function in it's header would solve the issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Klaim I wanted to use CMake add_library(mamba-fs OBJECT filesystem.cpp) to literally forbid including code from the rest of mamba in this library (and then do the same with mamba-util, mamba-solv-cpp...).
With more investigation, it turns out it's not so easy to do: since the headers are public, they still need to be added to libmamba to be installed, so I'm not sure it's worth the trouble.

For this particular issue, it turns out that since L"\\" and L"/" are in fact single characters, a simple call to std::replace will do (and is probably more performant). What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see, following your intention would also mean splitting utility in small libraries and making the filesystem library only depend on what it needs in the utility libraries. Note that, it can be done but then these libraries needs to not be distributed separately but only be an implementation detail, linked statically into libmamba. If they are public, then yep we either have to distribute them on the side of libmamba or not make it a library, same conclusion as yours.

For std::replace I would agree in general but I didnt check if it's strictly equivalent to what the utility function was doing? Or said another way: do you see why the function was initially created? What's the difference with std::replace?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway if it's tested and std::replace works in that specific function, I'm fine by it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For std::replace I would agree in general but I didnt check if it's strictly equivalent to what the utility function was doing? Or said another way: do you see why the function was initially created? What's the difference with std::replace?

@Klaim util::replace_all works with string_view. It will look for substrings, and replace with another string, moving all characters:

util::replace_all("ab_ab", "ab", "hello");  # "hello_hello"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then I guess we can use replace

micromamba/src/login.cpp Outdated Show resolved Hide resolved
micromamba/src/login.cpp Outdated Show resolved Hide resolved
micromamba/src/login.cpp Outdated Show resolved Hide resolved
@AntoinePrv AntoinePrv marked this pull request as ready for review October 2, 2023 17:44
@AntoinePrv AntoinePrv force-pushed the filesystem branch 2 times, most recently from 94abf13 to 7e6cd56 Compare October 4, 2023 13:02
@@ -17,11 +16,12 @@
#include "mamba/core/context.hpp"
#include "mamba/core/download.hpp"
#include "mamba/core/error_handling.hpp"
#include "mamba/core/mamba_fs.hpp"
#include "mamba/core/fetch.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: subdirdata has been refactored and does not depend anymore on this file, so we should not include it. This can be removed later, when fetch.hpp is removed from the code base.

#ifndef MAMBA_CORE_FS_HPP
#define MAMBA_CORE_FS_HPP
#ifndef MAMBA_CORE_FS_FILESYSTEM_HPP
#define MAMBA_CORE_FS_FILESYSTEM_HPP
Copy link
Member

@JohanMabille JohanMabille Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: should the inclusion guard be MAMBA_FS_FILESYSTEM? As for previous comment, this can be done in a further PR, to avoid conflicts if we are slow to merge this.

@JohanMabille JohanMabille merged commit 5a302fc into mamba-org:main Oct 5, 2023
23 checks passed
@AntoinePrv AntoinePrv deleted the filesystem branch October 6, 2023 06:51
@AntoinePrv AntoinePrv self-assigned this Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants