From dec9e0288f81462c53b9222a206002fbc525ea65 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 1 Mar 2021 10:53:18 +0100 Subject: [PATCH] remove useless get_cwd (#8551) --- conans/client/cache/cache.py | 3 +-- conans/client/cmd/profile.py | 13 ++++++------ conans/client/command.py | 15 +++++++------- conans/client/conan_api.py | 29 +++++++++++++-------------- conans/client/conan_command_output.py | 5 ++--- conans/client/tools/files.py | 5 ++--- conans/client/tools/win.py | 5 ++--- conans/unicode.py | 4 ---- 8 files changed, 34 insertions(+), 45 deletions(-) delete mode 100644 conans/unicode.py diff --git a/conans/client/cache/cache.py b/conans/client/cache/cache.py index 33c55cdf155..5b921e28ac3 100644 --- a/conans/client/cache/cache.py +++ b/conans/client/cache/cache.py @@ -22,7 +22,6 @@ from conans.paths import ARTIFACTS_PROPERTIES_FILE from conans.paths.package_layouts.package_cache_layout import PackageCacheLayout from conans.paths.package_layouts.package_editable_layout import PackageEditableLayout -from conans.unicode import get_cwd from conans.util.files import list_folder_subdirs, load, normalize, save, remove from conans.util.locks import Lock @@ -212,7 +211,7 @@ def hooks_path(self): @property def default_profile(self): self.initialize_default_profile() - default_profile, _ = read_profile(self.default_profile_path, get_cwd(), self.profiles_path) + default_profile, _ = read_profile(self.default_profile_path, os.getcwd(), self.profiles_path) # Mix profile settings with environment mixed_settings = _mix_settings_with_env(default_profile.settings) diff --git a/conans/client/cmd/profile.py b/conans/client/cmd/profile.py index 7b86f58d11a..1a18edecf75 100644 --- a/conans/client/cmd/profile.py +++ b/conans/client/cmd/profile.py @@ -5,7 +5,6 @@ from conans.errors import ConanException from conans.model.options import OptionsValues from conans.model.profile import Profile -from conans.unicode import get_cwd from conans.util.files import save @@ -36,7 +35,7 @@ def cmd_profile_list(cache_profiles_path, output): def cmd_profile_create(profile_name, cache_profiles_path, output, detect=False, force=False): - profile_path = get_profile_path(profile_name, cache_profiles_path, get_cwd(), + profile_path = get_profile_path(profile_name, cache_profiles_path, os.getcwd(), exists=False) if not force and os.path.exists(profile_path): raise ConanException("Profile already exists") @@ -60,7 +59,7 @@ def cmd_profile_create(profile_name, cache_profiles_path, output, detect=False, def cmd_profile_update(profile_name, key, value, cache_profiles_path): first_key, rest_key = _get_profile_keys(key) - profile, _ = read_profile(profile_name, get_cwd(), cache_profiles_path) + profile, _ = read_profile(profile_name, os.getcwd(), cache_profiles_path) if first_key == "settings": profile.settings[rest_key] = value elif first_key == "options": @@ -72,13 +71,13 @@ def cmd_profile_update(profile_name, key, value, cache_profiles_path): raise ConanException("Edit the profile manually to change the build_requires") contents = profile.dumps() - profile_path = get_profile_path(profile_name, cache_profiles_path, get_cwd()) + profile_path = get_profile_path(profile_name, cache_profiles_path, os.getcwd()) save(profile_path, contents) def cmd_profile_get(profile_name, key, cache_profiles_path): first_key, rest_key = _get_profile_keys(key) - profile, _ = read_profile(profile_name, get_cwd(), cache_profiles_path) + profile, _ = read_profile(profile_name, os.getcwd(), cache_profiles_path) try: if first_key == "settings": return profile.settings[rest_key] @@ -98,7 +97,7 @@ def cmd_profile_get(profile_name, key, cache_profiles_path): def cmd_profile_delete_key(profile_name, key, cache_profiles_path): first_key, rest_key = _get_profile_keys(key) - profile, _ = read_profile(profile_name, get_cwd(), cache_profiles_path) + profile, _ = read_profile(profile_name, os.getcwd(), cache_profiles_path) try: package, name = rest_key.split(":") @@ -119,5 +118,5 @@ def cmd_profile_delete_key(profile_name, key, cache_profiles_path): raise ConanException("Profile key '%s' doesn't exist" % key) contents = profile.dumps() - profile_path = get_profile_path(profile_name, cache_profiles_path, get_cwd()) + profile_path = get_profile_path(profile_name, cache_profiles_path, os.getcwd()) save(profile_path, contents) diff --git a/conans/client/command.py b/conans/client/command.py index 53bebd5e47f..98622cedbb5 100644 --- a/conans/client/command.py +++ b/conans/client/command.py @@ -22,7 +22,6 @@ ConanMigrationError from conans.model.ref import ConanFileReference, PackageReference, get_reference_fields, \ check_valid_ref -from conans.unicode import get_cwd from conans.util.config_parser import get_bool_from_text from conans.util.files import exception_message_safe from conans.util.files import save @@ -260,7 +259,7 @@ def dump_custom_types(obj): json_output = json.dumps(result, default=dump_custom_types) if not os.path.isabs(args.json): - json_output_file = os.path.join(get_cwd(), args.json) + json_output_file = os.path.join(os.getcwd(), args.json) else: json_output_file = args.json save(json_output_file, json_output) @@ -356,7 +355,7 @@ def create(self, *args): # Now if parameter --test-folder=None (string None) we have to skip tests args.test_folder = False - cwd = get_cwd() + cwd = os.getcwd() info = None try: @@ -482,7 +481,7 @@ def install(self, *args): profile_build = ProfileData(profiles=args.profile_build, settings=args.settings_build, options=args.options_build, env=args.env_build) - cwd = get_cwd() + cwd = os.getcwd() # We need @ otherwise it could be a path, so check strict path_is_reference = check_valid_ref(args.path_or_reference) @@ -710,7 +709,7 @@ def info(self, *args): install_folder=args.install_folder) if args.json: json_arg = True if args.json == "1" else args.json - self._outputer.json_build_order(ret, json_arg, get_cwd()) + self._outputer.json_build_order(ret, json_arg, os.getcwd()) else: self._outputer.build_order(ret) @@ -728,7 +727,7 @@ def info(self, *args): install_folder=args.install_folder) if args.json: json_arg = True if args.json == "1" else args.json - self._outputer.json_nodes_to_build(nodes, json_arg, get_cwd()) + self._outputer.json_nodes_to_build(nodes, json_arg, os.getcwd()) else: self._outputer.nodes_to_build(nodes) @@ -764,10 +763,10 @@ def info(self, *args): else: template = self._conan.app.cache.get_template(templates.INFO_GRAPH_DOT, user_overrides=True) - self._outputer.info_graph(args.graph, deps_graph, get_cwd(), template=template) + self._outputer.info_graph(args.graph, deps_graph, os.getcwd(), template=template) if args.json: json_arg = True if args.json == "1" else args.json - self._outputer.json_info(deps_graph, json_arg, get_cwd(), show_paths=args.paths) + self._outputer.json_info(deps_graph, json_arg, os.getcwd(), show_paths=args.paths) if not args.graph and not args.json: self._outputer.info(deps_graph, only, args.package_filter, args.paths) diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py index 95b0456360c..13952b6ccc9 100644 --- a/conans/client/conan_api.py +++ b/conans/client/conan_api.py @@ -63,7 +63,6 @@ from conans.paths.package_layouts.package_cache_layout import PackageCacheLayout from conans.search.search import search_recipes from conans.tools import set_global_instances -from conans.unicode import get_cwd from conans.util.conan_v2_mode import conan_v2_error from conans.util.files import exception_message_safe, mkdir, save_files, load, save from conans.util.log import configure_logger @@ -112,7 +111,7 @@ def _make_abs_path(path, cwd=None, default=None): """convert 'path' to absolute if necessary (could be already absolute) if not defined (empty, or None), will return 'default' one or 'cwd' """ - cwd = cwd or get_cwd() + cwd = cwd or os.getcwd() if not path: abs_path = default or cwd elif os.path.isabs(path): @@ -253,7 +252,7 @@ def new(self, name, header=False, pure_c=False, test=False, exports_sources=Fals circleci_gcc_versions=None, circleci_clang_versions=None, circleci_osx_versions=None, template=None): from conans.client.cmd.new import cmd_new - cwd = os.path.abspath(cwd or get_cwd()) + cwd = os.path.abspath(cwd or os.getcwd()) files = cmd_new(name, header=header, pure_c=pure_c, test=test, exports_sources=exports_sources, bare=bare, visual_versions=visual_versions, @@ -278,7 +277,7 @@ def inspect(self, path, attributes, remote_name=None): try: ref = ConanFileReference.loads(path) except ConanException: - conanfile_path = _get_conanfile_path(path, get_cwd(), py=True) + conanfile_path = _get_conanfile_path(path, os.getcwd(), py=True) conanfile = self.app.loader.load_named(conanfile_path, None, None, None, None) else: if remote_name: @@ -322,7 +321,7 @@ def test(self, path, reference, profile_names=None, settings=None, options=None, remotes = self.app.load_remotes(remote_name=remote_name, update=update) conanfile_path = _get_conanfile_path(path, cwd, py=True) - cwd = cwd or get_cwd() + cwd = cwd or os.getcwd() lockfile = _make_abs_path(lockfile, cwd) if lockfile else None graph_info = get_graph_info(profile_host, profile_build, cwd, None, self.app.cache, self.app.out, lockfile=lockfile) @@ -407,7 +406,7 @@ def export_pkg(self, conanfile_path, name, channel, source_folder=None, build_fo profile_host = ProfileData(profiles=profile_names, settings=settings, options=options, env=env) remotes = self.app.load_remotes() - cwd = cwd or get_cwd() + cwd = cwd or os.getcwd() recorder = ActionRecorder() try: @@ -489,7 +488,7 @@ def workspace_install(self, path, settings=None, options=None, env=None, update=False, cwd=None, install_folder=None, profile_build=None): profile_host = ProfileData(profiles=profile_name, settings=settings, options=options, env=env) - cwd = cwd or get_cwd() + cwd = cwd or os.getcwd() abs_path = os.path.normpath(os.path.join(cwd, path)) remotes = self.app.load_remotes(remote_name=remote_name, update=update) @@ -682,7 +681,7 @@ def config_init(self, force=False): def _info_args(self, reference_or_path, install_folder, profile_host, profile_build, lockfile=None): - cwd = get_cwd() + cwd = os.getcwd() if check_valid_ref(reference_or_path): ref = ConanFileReference.loads(reference_or_path) install_folder = _make_abs_path(install_folder, cwd) if install_folder else None @@ -754,7 +753,7 @@ def build(self, conanfile_path, source_folder=None, package_folder=None, build_f install_folder=None, should_configure=True, should_build=True, should_install=True, should_test=True, cwd=None): self.app.load_remotes() - cwd = cwd or get_cwd() + cwd = cwd or os.getcwd() conanfile_path = _get_conanfile_path(conanfile_path, cwd, py=True) build_folder = _make_abs_path(build_folder, cwd) install_folder = _make_abs_path(install_folder, cwd, default=build_folder) @@ -772,7 +771,7 @@ def package(self, path, build_folder, package_folder, source_folder=None, instal cwd=None): self.app.load_remotes() - cwd = cwd or get_cwd() + cwd = cwd or os.getcwd() conanfile_path = _get_conanfile_path(path, cwd, py=True) build_folder = _make_abs_path(build_folder, cwd) install_folder = _make_abs_path(install_folder, cwd, default=build_folder) @@ -796,7 +795,7 @@ def package(self, path, build_folder, package_folder, source_folder=None, instal def source(self, path, source_folder=None, info_folder=None, cwd=None): self.app.load_remotes() - cwd = cwd or get_cwd() + cwd = cwd or os.getcwd() conanfile_path = _get_conanfile_path(path, cwd, py=True) source_folder = _make_abs_path(source_folder, cwd) info_folder = _make_abs_path(info_folder, cwd) @@ -822,7 +821,7 @@ def imports(self, path, dest=None, info_folder=None, cwd=None): :param cwd: Current working directory :return: None """ - cwd = cwd or get_cwd() + cwd = cwd or os.getcwd() info_folder = _make_abs_path(info_folder, cwd) dest = _make_abs_path(dest, cwd) @@ -835,7 +834,7 @@ def imports(self, path, dest=None, info_folder=None, cwd=None): @api_method def imports_undo(self, manifest_path): - cwd = get_cwd() + cwd = os.getcwd() manifest_path = _make_abs_path(manifest_path, cwd) undo_imports(manifest_path, self.app.out) @@ -1141,7 +1140,7 @@ def delete_profile_key(self, profile_name, key): @api_method def read_profile(self, profile=None): - p, _ = read_profile(profile, get_cwd(), self.app.cache.profiles_path) + p, _ = read_profile(profile, os.getcwd(), self.app.cache.profiles_path) return p @api_method @@ -1373,7 +1372,7 @@ def lock_create(self, path, lockfile_out, base=None, lockfile=None): # profile_host is mandatory profile_host = profile_host or ProfileData(None, None, None, None) - cwd = get_cwd() + cwd = os.getcwd() if path and reference: raise ConanException("Both path and reference arguments were provided. Please provide " diff --git a/conans/client/conan_command_output.py b/conans/client/conan_command_output.py index 87e7bf1691e..d653aca62c9 100644 --- a/conans/client/conan_command_output.py +++ b/conans/client/conan_command_output.py @@ -9,7 +9,6 @@ from conans.client.printer import Printer from conans.model.ref import ConanFileReference, PackageReference from conans.search.binary_html_table import html_binary_graph -from conans.unicode import get_cwd from conans.util.dates import iso8601_to_str from conans.util.files import save from conans import __version__ as client_version @@ -63,13 +62,13 @@ def json_build_order(self, info, json_output, cwd): if json_output is True: # To the output self._output.write(json_str) else: # Path to a file - cwd = os.path.abspath(cwd or get_cwd()) + cwd = os.path.abspath(cwd or os.getcwd()) if not os.path.isabs(json_output): json_output = os.path.join(cwd, json_output) save(json_output, json_str) def json_output(self, info, json_output, cwd): - cwd = os.path.abspath(cwd or get_cwd()) + cwd = os.path.abspath(cwd or os.getcwd()) if not os.path.isabs(json_output): json_output = os.path.join(cwd, json_output) diff --git a/conans/client/tools/files.py b/conans/client/tools/files.py index 5582a3580e5..13ed35e54c1 100644 --- a/conans/client/tools/files.py +++ b/conans/client/tools/files.py @@ -13,7 +13,6 @@ from conans.client.output import ConanOutput from conans.errors import ConanException -from conans.unicode import get_cwd from conans.util.fallbacks import default_output from conans.util.files import (_generic_algorithm_sum, load, save) @@ -24,7 +23,7 @@ @contextmanager def chdir(newdir): - old_path = get_cwd() + old_path = os.getcwd() os.chdir(newdir) try: yield @@ -89,7 +88,7 @@ def unzip(filename, destination=".", keep_permissions=False, pattern=None, outpu return untargz(filename, destination, pattern, strip_root) import zipfile - full_path = os.path.normpath(os.path.join(get_cwd(), destination)) + full_path = os.path.normpath(os.path.join(os.getcwd(), destination)) if hasattr(sys.stdout, "isatty") and sys.stdout.isatty(): def print_progress(the_size, uncomp_size): diff --git a/conans/client/tools/win.py b/conans/client/tools/win.py index a48f43b650e..d04f4f0dd06 100644 --- a/conans/client/tools/win.py +++ b/conans/client/tools/win.py @@ -12,7 +12,6 @@ from conans.client.tools.oss import OSInfo, detected_architecture, get_build_os_arch from conans.errors import ConanException from conans.model.version import Version -from conans.unicode import get_cwd from conans.util.conan_v2_mode import conan_v2_error from conans.util.env_reader import get_env from conans.util.fallbacks import default_output @@ -693,9 +692,9 @@ def get_path_value(container, subsystem_name): # Needed to change to that dir inside the bash shell if cwd and not os.path.isabs(cwd): - cwd = os.path.join(get_cwd(), cwd) + cwd = os.path.join(os.getcwd(), cwd) - curdir = unix_path(cwd or get_cwd(), path_flavor=subsystem) + curdir = unix_path(cwd or os.getcwd(), path_flavor=subsystem) to_run = 'cd "%s"%s && %s ' % (curdir, hack_env, bashcmd) bash_path = OSInfo.bash_path() bash_path = '"%s"' % bash_path if " " in bash_path else bash_path diff --git a/conans/unicode.py b/conans/unicode.py deleted file mode 100644 index 09393ed0497..00000000000 --- a/conans/unicode.py +++ /dev/null @@ -1,4 +0,0 @@ -import os - -# FIXME: This has to be removed in Conan 2.0 -get_cwd = os.getcwd