Skip to content

Commit

Permalink
remove useless get_cwd (#8551)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Mar 1, 2021
1 parent e7fe5f0 commit dec9e02
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 45 deletions.
3 changes: 1 addition & 2 deletions conans/client/cache/cache.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions conans/client/cmd/profile.py
Expand Up @@ -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


Expand Down Expand Up @@ -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")
Expand All @@ -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":
Expand All @@ -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]
Expand All @@ -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(":")
Expand All @@ -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)
15 changes: 7 additions & 8 deletions conans/client/command.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
29 changes: 14 additions & 15 deletions conans/client/conan_api.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 "
Expand Down
5 changes: 2 additions & 3 deletions conans/client/conan_command_output.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions conans/client/tools/files.py
Expand Up @@ -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)

Expand All @@ -24,7 +23,7 @@

@contextmanager
def chdir(newdir):
old_path = get_cwd()
old_path = os.getcwd()
os.chdir(newdir)
try:
yield
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions conans/client/tools/win.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions conans/unicode.py

This file was deleted.

0 comments on commit dec9e02

Please sign in to comment.