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

Refactor GAM to be "import"able #23

Closed
daethnir opened this issue Dec 2, 2014 · 16 comments · Fixed by #1165
Closed

Refactor GAM to be "import"able #23

daethnir opened this issue Dec 2, 2014 · 16 comments · Fixed by #1165

Comments

@daethnir
Copy link
Contributor

daethnir commented Dec 2, 2014

I'd like to use some of the GAM logic in separate scripts. GAM already does a lot of the hard work to set up API objects and the like.

I'd like to refactor the code to start making it reusable in new scripts.

My first step would be to pull out the object initialization into a new file, such as gamlib.py, which would be used by gam.py. Everything that ends up in gamlib.py would be something that is built to be reused - all OO, no globals, etc.

Would you like to discuss this and tell me what requirements you'd have for it to be something you're willing to merge in?

@bpabel
Copy link

bpabel commented Jan 18, 2015

I too would like gam to be an importable package. Another idea instead of a gamlib package with a gam py2exe wrapper would be to just make "gam" the python package, and then use python entry points to declare a "gam" console script to be used much like the current gam executable.

@bpabel
Copy link

bpabel commented Feb 4, 2015

You can kind of hack it by making a small modification to gam.py and creating a custom setup.py script.

At the bottom of gam.py, move all the command line parsing logic under a if __name__ == '__main__' block to prevent it from executing when importing the module. It will still work when used with py2exe.

Then create another setup script.

setup-package.py

from setuptools import setup, find_packages

requires = []

setup(
    name='gam',
    version='0.2',
    packages=['atom', 'gdata', 'googleapiclient', 'httplib2', 'oauth2client', 'passlib', 'uritemplate'],
    zip_safe=False,
    install_requires=requires,
    py_modules=['gam'],
)

Alternatively, you could specify the required packages (ie. httplib2, passlib, etc.) as dependencies using requires. The only one that wouldn't install from pypi is atom. That way they're installed as they're own package and can have they're versions and dependencies managed by pip/easy_install.

from setuptools import setup, find_packages

requires = ['gdata', 'googleapiclient', 'httplib2', 'oauth2client', 'passlib', 'uritemplate']

setup(
    name='gam',
    version='0.2',
    packages=['atom'],
    zip_safe=False,
    install_requires=requires,
    py_modules=['gam'],
)

Then just run the setup script.

python setup-package.py install

@Turin86
Copy link

Turin86 commented Mar 17, 2015

Making GAM a library which the GAM cmd parser would use makes perfect sense to me. I had thought some time ago that if GAM was like this and would raise catchable exceptions then I could even drop my own Google API client.

@benkoller
Copy link

That would be great. Ideally you move the conversion of json to "human readable" as well!

@jkrauska
Copy link

I also would find this incredibly useful. I end up wrapping some more complex gam runs in subprocess, and it would be so much nicer to keep it all in python.

@cbini
Copy link

cbini commented Jun 4, 2015

This would kick some serious ass

@timbre
Copy link

timbre commented Jun 10, 2015

Was considering writing tab-completion for GAM, but holding off in hope that this happens

@brainysmurf
Copy link

Importable module would be great. +1

@PPGDa5id
Copy link

This would be so nice. Please and thank you!

@april-easypost
Copy link

This would be awesome. When writing automation scripts, I hate having to either a) run the bash command, or b) re-invent the wheel by figuring out the API by hand. +1 from me.

@jacobsvante
Copy link

Distributed through PyPI please! :-)

@bondr007
Copy link

Would really like to see this happen.

Thanks!

@bforesman
Copy link

+1; I am currently using subprocess.check_call in my python classes in order to use gam; I'd love to have direct access to its methods.

@LewisLebentz
Copy link
Contributor

Has there been any progress with this?

Would love to be able to import this too.

@thalesvon
Copy link

Is this still a thing?

@Epy
Copy link

Epy commented Dec 9, 2020

Helloo
sorry to bother, as this is closed and PR is merged, work seems done for this ?
Do someone have a draft of documentation for this ?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.