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

Any suggected way to use dvc from python? #3278

Closed
byaka opened this issue Feb 3, 2020 · 3 comments
Closed

Any suggected way to use dvc from python? #3278

byaka opened this issue Feb 3, 2020 · 3 comments
Labels
awaiting response we are waiting for your reply, please respond! :) question I have a question?

Comments

@byaka
Copy link

byaka commented Feb 3, 2020

We want to use dvc commands right from our software.

As i see dvc dont have stable api for this.

what way u suggest?

i find this and here they use it like

from setuptools import setup
from setuptools.command.build_py import build_py
from dvc.main import main


class FetchError(Exception):
    pass


class AssetFetcher(build_py):

    def run(self):
        print('Start pulling dvc asset')
        
        ret = main(['pull', 'train.dvc'])
        if ret != 0:
            msg = 'DVC returned error code {} while pulling assets'
            raise FetchError(msg.format(ret))
        
        print('Asset pulled successfully !')
        build_py.run(self)


setup(
    name='vat_detection',
    # and many other arguments ...
    cmdclass={'build_py': AssetFetcher}
)

Is this way ok or it can breaks on new versions?

@triage-new-issues triage-new-issues bot added the triage Needs to be triaged label Feb 3, 2020
@ghost
Copy link

ghost commented Feb 3, 2020

@byaka , that's a good option, if you need more control over the operations, you can try using dvc.repo.Repo

It is not likely that we're going to introduce breaking changes in the near future since we value backwards compatibility, it is not guaranteed, tho 🙂

@ghost ghost added the question I have a question? label Feb 3, 2020
@triage-new-issues triage-new-issues bot removed the triage Needs to be triaged label Feb 3, 2020
@efiop
Copy link
Contributor

efiop commented Feb 4, 2020

@byaka Your example uses CLI through a python entrypoint. That is pretty stable, almost no chance of us moving main() somewhere else anywhere in the future. So that (or just os.system("dvc ...") or Popen) totally works 🙂

The Repo class mentioned by @MrOutis is officially not as secure from changes as CLI, but you should be fine, as long as you use specific dvc version as a dependency in your project. 🙂

@efiop efiop added the awaiting response we are waiting for your reply, please respond! :) label Feb 4, 2020
@efiop efiop closed this as completed Feb 5, 2020
@byaka
Copy link
Author

byaka commented Feb 5, 2020

Good to know this, thx!
We give it a try :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response we are waiting for your reply, please respond! :) question I have a question?
Projects
None yet
Development

No branches or pull requests

2 participants