Coder Social home page Coder Social logo

require.distro.package about fabtools HOT 8 OPEN

fabtools avatar fabtools commented on July 27, 2024
require.distro.package

from fabtools.

Comments (8)

ronnix avatar ronnix commented on July 27, 2024

Yes, I've been thinking about adding this kind of layer.

One issue that we need to address is that package names may vary from one distro to another. See the implementation of require.git.command() for example.

I'd like the API to keep the common case simple, but allow the user to override the default package name with alternate names for given distros / families. Something like:

# Simple case
require.system.package('python-dev')

# System-specific overrides
require.system.package('git', debian='git-core', sun='scmgit-base')

For installing multiple packages, each list item could be either a string or a dictionary, but it's not as pretty:

require.system.packages([
    'curl',
    'python-dev',
    {'default': 'git', 'debian': 'git-core', 'sun': 'scmgit-base'},
])

from fabtools.

ponty avatar ponty commented on July 27, 2024

The same concept with less magic:

def choose_by_distrib_family(default, **kwargs):
    return dict(**kwargs).get(distrib_family(), default)

# Simple case
require.system.package(
    choose_by_distrib_family('git', debian='git-core', sun='scmgit-base'))

# multiple packages
require.system.packages([
    'curl',
    'python-dev',
    choose_by_distrib_family(default='git', debian='git-core', sun='scmgit-base'),
])

from fabtools.

ronnix avatar ronnix commented on July 27, 2024

Nice! Make it shorter maybe (by_distrib_family)?

from fabtools.

ronnix avatar ronnix commented on July 27, 2024

Also, we may want to cache the result of distrib_family()...

from fabtools.

ponty avatar ponty commented on July 27, 2024

Most of the functions in system.py can be cached, but this should be a new ticket.

This could be implemented using memoization.

Original code:
http://stackoverflow.com/questions/1988804/what-is-memoization-and-how-can-i-use-it-in-python

Modified with env.host

def memoize(fn):
    """returns a memoized version of any function that can be called
    with the same list of arguments.
    Usage: foo = memoize(foo)"""

    def foo(*args, **kwargs):
        items = tuple(sorted(kwargs.items()))
        if (args, items, env.host) not in foo.past_calls:
            foo.past_calls[(args, items, env.host)] = fn(*args,**kwargs)
        return foo.past_calls[(args, items, env.host)]
    foo.past_calls = dict([])
    foo.__name__ = 'memoized_' + fn.__name__ 
    return foo

@memoize
def distrib_family():
    """
    """

from fabtools.

nicfit avatar nicfit commented on July 27, 2024

Where does this stand? I've created something similar in my tree.

Also, memoize cache would need to be cleared for each host change. e.g.,
fab -H centos_host, debian_host deploy

from fabtools.

ponty avatar ponty commented on July 27, 2024

I didn't implemented it yet.

from fabtools.

deronnax avatar deronnax commented on July 27, 2024

no news ? I was thinking, something like a json file with a map between package canonical name and its name in the different OS would be awesome. When doing a require.package, fabtools would check in the file if the package in present, and use the package name.
The file would be bundled with fabtools with a name like packages_name_map.json, and the user could override it in various ways. Thanks to the json format, to change it or correct it, even a no-programmer can edit it.

For git, it would be:

[ {"git": {"debian": "git-core", "sun" : "git-scm", "gentoo": "git-scm"}}]

from fabtools.

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.