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

dvc: refactor config #3298

Merged
merged 5 commits into from
Feb 13, 2020
Merged

dvc: refactor config #3298

merged 5 commits into from
Feb 13, 2020

Conversation

Suor
Copy link
Contributor

@Suor Suor commented Feb 10, 2020

Advantages:

  • read like a dict
  • modify as a dict for testing or manipulation purposes
  • wrap modifications into context manager to save them:
    with config.edit("local") as conf:
        conf["core"]["remote"] = "new-default"

Design decisions:

  • dropped string constants
  • remote sections are parsed into a simple subdict upon load
  • remote config schema is now defined by url scheme
  • relative paths are handled transparently upon load/save
  • user config and remote manipulations are moved to commands
  • same dev manipulations are done by simply modifying a config dict

@Suor Suor requested a review from efiop February 10, 2020 15:54
@efiop
Copy link
Contributor

efiop commented Feb 10, 2020

@Suor Looks amazing! Please check the tests though, looks like slight hickup with schemas for some remotes.

@Suor
Copy link
Contributor Author

Suor commented Feb 10, 2020

@efiop I see two issues:

  • setting type for hdfs remote fails, which makes sense, tests need to be adjusted
  • windows paths not being recognized sometimes by validation

I will fix these tomorrow.

@efiop efiop added refactoring Factoring and re-factoring p1-important Important, aka current backlog of things to do labels Feb 11, 2020
@efiop
Copy link
Contributor

efiop commented Feb 11, 2020

@Suor Please rebase.

@Suor
Copy link
Contributor Author

Suor commented Feb 11, 2020

@efiop rebased

Copy link
Contributor

@pared pared left a comment

Choose a reason for hiding this comment

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

One question


self.extra_args = {}

self.sse = config.get(Config.SECTION_AWS_SSE, "")
self.sse = config.get("sse")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't here be config.get("sse","")? And if not, why do we do config.get("acl","")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't matter really until it's boolean false it won't be used anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed "" for consistency.

cache_dir = config.get(Config.SECTION_REMOTE_URL)

if cache_dir is not None and not os.path.isabs(cache_dir):
cwd = config[Config.PRIVATE_CWD]
Copy link
Contributor

Choose a reason for hiding this comment

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

@Suor You might've lost _cwd logic, which was resolving relative paths based on config location. Or am I missing something here?

Copy link
Member

Choose a reason for hiding this comment

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

I thought that we have test for this 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not needed anymore:

relative paths are handled transparently upon load/save

Copy link
Contributor

Choose a reason for hiding this comment

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

@Suor Could you please refer me to some part of the code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, I see it now.

Advantages:
- read like a dict
- modify as a dict for testing or manipulation purposes
- wrap modifications into context manager to save them:

    with config.edit("local") as conf:
        conf["core"]["remote"] = "new-default"

Design decisions:
- dropped string constants
- remote sections are parsed into a simple subdict upon load
- remote config schema is now defined by url scheme
- relative paths are handled transparently upon load/save
- user config and remote manipulations are moved to commands
- same dev manipulations are done by simply modifying a config dict
@efiop
Copy link
Contributor

efiop commented Feb 13, 2020

@Suor Please check the DS and CC reports, there are some good points there.

dvc/config.py Outdated
def resolve(path):
if os.path.isabs(path) or re.match(r"\w+://", path):
return path
return RelPath(os.path.join(cwd, path))
Copy link
Contributor

Choose a reason for hiding this comment

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

cwd is defined after this helper in which it is used. This is error-prone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is minor. Nothing functionally wrong about it because of the same namespace, but causes a mental hickup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Defining subfunction in the middle causes mental hiccup too)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can move it if that worries you.

@Suor
Copy link
Contributor Author

Suor commented Feb 13, 2020

@efiop I actually looked them through a couple of days ago) Most of them not introduced by this PR, from the rest:

  • ByUrl complexity here - splitting it is not a good idea
  • not calling dict.__init__() here - Config has very different constructor signature.
  • self in .validate() here and if/elif here just nitpicks, can't cause any issues
  • get_dir() here protected by an assert.

While some stylistic changes can be done, that will bring no value. Diving into DS was a waste of time again.

@efiop
Copy link
Contributor

efiop commented Feb 13, 2020

@Suor

ByUrl complexity here - splitting it is not a good idea

👍

not calling dict.init() here - Config has very different constructor signature.

👍

self in .validate() here and if/elif here just nitpicks, can't cause any issues

These are worth fixing, it affects the code style, we avoid such things in other places.

get_dir() here protected by an assert.

👍

While some stylistic changes can be done, that will bring no value. Diving into DS was a waste of time again.

Style is not a waste of time for DVC, please fix those few issues left.

@efiop efiop merged commit 6ccae71 into iterative:master Feb 13, 2020
@efiop
Copy link
Contributor

efiop commented Feb 13, 2020

Thanks @Suor ! 🙏

@pared pared mentioned this pull request Feb 14, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p1-important Important, aka current backlog of things to do refactoring Factoring and re-factoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants