Giter VIP home page Giter VIP logo

Comments (7)

josegonzalez avatar josegonzalez commented on July 3, 2024 1

I don't really care to be honest. I've been merging almost every pull request, so go nuts.

from python-github-backup.

josegonzalez avatar josegonzalez commented on July 3, 2024

Go for it. Honestly, I more or less merge anything that doesn't break functionality I use, so if you think this is a good move, thats fine by me.

from python-github-backup.

josegonzalez avatar josegonzalez commented on July 3, 2024

Doesn't seem like this is going to happen, but PRs welcome :)

from python-github-backup.

timm3 avatar timm3 commented on July 3, 2024

I apologize for bumping a dead issue, but thought I could mention a workaround I put together until a PR gets made addressing this.

I used some importlib magic in my code to expose the github_backup library functions.
This has only been used in an Ubuntu 18.04 & lambda environment, and has not been tested with other operating systems or flavors.
This exact code may not work, as I had to exclude most of the content, and only copied what I recall as being relevant.
You should not use this in production. Just sayin'.

import os
import sys

from importlib.util import spec_from_loader, module_from_spec
from importlib.machinery import SourceFileLoader

try:
    # "normal" pycharm development
    import github_backup
except ModuleNotFoundError:
    # docker/lambda development
    # `package` is in the path because that's what I named the directory for my lambda package...
    import package.github_backup as github_backup
init_path = github_backup.__file__
if "/lib" in init_path:
    init_ancestor = init_path.split('/lib', maxsplit=1)[0]
else:
    init_ancestor = init_path.split('/github_backup', maxsplit=1)[0]
desired_path = os.sep.join([init_ancestor, 'bin', 'github-backup'])
zspec = spec_from_loader("github_backup", SourceFileLoader("github_backup", desired_path))
zmodule = module_from_spec(zspec)
zspec.loader.exec_module(zmodule)
sys.modules["github_backup"] = zmodule
github_backup = zmodule

You can then pump arguments into sys.argv before calling github_backup.main(), though I did it before this oddball loading business.

EDIT:
I should add that this isn't everything required to make it work in lambda. I also had to change the way github_backup imports __version__ from "itself" to used the import path package.github_backup.

from python-github-backup.

timm3 avatar timm3 commented on July 3, 2024

@josegonzalez Is there a particular reason for structuring the module such that the actual code resides in bin/github-backup while the module's init file resides in github_backup/__init__.py?

What was the motivation for putting the code in the bin directory?

from python-github-backup.

josegonzalez avatar josegonzalez commented on July 3, 2024

None, other than it was a very small binary before and I didn't see a need to put it into the namespace.

from python-github-backup.

timm3 avatar timm3 commented on July 3, 2024

@josegonzalez are there any functions you wouldn't want exposed when the library gets imported?

from python-github-backup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.