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

[infra] fix: config_file parametrization #1344

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions python-package/basedosdados/upload/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def __init__(
config_path = (
config.project_config_path
if config.project_config_path is not None
else config_path
else Path.home() / config_path
)

self.config_path = Path.home() / config_path
self.config_path = config_path
self._init_config(force=overwrite_cli_config)
self.config = self._load_config()
self._config_log(config.verbose)
Expand Down Expand Up @@ -199,7 +199,7 @@ def _init_config(self, force):
config_file = self.config_path / "config.toml"

# Create credentials folder
credentials_folder = Path.home() / self.config_path / "credentials"
credentials_folder = self.config_path / "credentials"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isso vai funcionar só se o usuário passar o caminho absoluto no project_config_path. Não tem nada validando o path que o usuário passa.

Copy link
Member Author

Choose a reason for hiding this comment

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

Acho que sempre tem que ser o path absoluto, pq n tem como saber se ele passou a partir da home ou n. Da pra levantar um raise caso n seja path absoluto

credentials_folder.mkdir(exist_ok=True, parents=True)

# Create template folder
Expand Down Expand Up @@ -259,7 +259,7 @@ def _init_config(self, force):

############# STEP 2 - CREDENTIALS PATH ######################

credentials_path = Path.home() / ".basedosdados" / "credentials"
credentials_path = self.config_path / "credentials"
credentials_path = Path(
self._selection_yn(
first_question=(
Expand Down Expand Up @@ -335,7 +335,7 @@ def _init_config(self, force):

############# STEP 6 - SET TEMPLATES #######################

c_file["templates_path"] = str(Path.home() / ".basedosdados" / "templates")
c_file["templates_path"] = str(self.config_path / "templates")

config_file.open("w", encoding="utf-8").write(tomlkit.dumps(c_file))

Expand All @@ -360,7 +360,7 @@ def _load_config(self):
if getenv(constants.ENV_CONFIG.value):
return tomlkit.parse(self._decode_env(constants.ENV_CONFIG.value))
return tomlkit.parse(
(Path.home() / ".basedosdados" / "config.toml")
(self.config_path / "config.toml")
.open("r", encoding="utf-8")
.read()
)
Expand Down