How to use the setupmeta.SimpleModule function in setupmeta

To help you get started, we’ve selected a few setupmeta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zsimic / setupmeta / setupmeta.py View on Github external
if vdef:
                self.add_definition(
                    vdef.key,
                    vdef.value,
                    vdef.source
                )

        # Scan the usual/conventional places
        for py_module in py_modules:
            self.merge(SimpleModule('%s.py' % py_module))

        for package in packages:
            self.merge(
                SimpleModule(package, '__about__.py'),
                SimpleModule(package, '__version__.py'),
                SimpleModule(package, '__init__.py'),
                SimpleModule('src', package, '__about__.py'),
                SimpleModule('src', package, '__version__.py'),
                SimpleModule('src', package, '__init__.py'),
            )

        url = self.value('url')
        download_url = self.value('download_url')

        if url and self.name:
            parts = url.split('/')
            if len(parts) == 4 and 'github.com' == parts[2]:
                # Convenience: auto-complete url with package name
                url = os.path.join(url, self.name)

        if download_url and url and '://' not in download_url:
            # Convenience: auto-complete relative download_url
github zsimic / setupmeta / setupmeta.py View on Github external
# I symlink setupmeta.py to my own checkout of the main setupmeta...
        short_path = short(csm.full_path, c=0)
        sys.exit("'%s' is a symlink, can't upgrade" % short_path)

    try:
        fh = urlopen(args.url)
        contents = to_str(fh.read())

        with open(project_path(rsmlp), 'w') as fh:
            fh.write(contents)

    except Exception as e:
        print("Could not fetch %s: %s" % (args.url, e))
        sys.exit(1)

    rsm = SimpleModule(rsmlp)           # remote script module
    try:
        nv = rsm.value('version')
        if not nv or not rsm.value('url'):
            # Sanity check what we downloaded
            sys.exit("Invalid url %s, please check %s" % (
                args.url,
                short(rsm.full_path, c=0))
            )

        current = load_contents(csm.relative_path)
        tc = load_contents(rsmlp)
        if current == tc:
            print("Already up to date, v%s" % __version__)
            sys.exit(0)

        if current:
github zsimic / setupmeta / setupmeta.py View on Github external
'pygradle'
            )
        elif os.path.isfile(project_path('gradle.properties')):
            # Convenience: calling pygradle setup.py outside of pygradle
            props = SimpleModule('gradle.properties')
            vdef = props.definitions.get('version')
            if vdef:
                self.add_definition(
                    vdef.key,
                    vdef.value,
                    vdef.source
                )

        # Scan the usual/conventional places
        for py_module in py_modules:
            self.merge(SimpleModule('%s.py' % py_module))

        for package in packages:
            self.merge(
                SimpleModule(package, '__about__.py'),
                SimpleModule(package, '__version__.py'),
                SimpleModule(package, '__init__.py'),
                SimpleModule('src', package, '__about__.py'),
                SimpleModule('src', package, '__version__.py'),
                SimpleModule('src', package, '__init__.py'),
            )

        url = self.value('url')
        download_url = self.value('download_url')

        if url and self.name:
            parts = url.split('/')
github zsimic / setupmeta / setupmeta.py View on Github external
args = parser.parse_args(*argv)

    if args.command != 'upgrade':
        sys.exit("Command must be 'upgrade' (this is to avoid accidentals)")

    args.target = os.path.abspath(os.path.expanduser(args.target))
    if not os.path.isdir(args.target):
        sys.exit("'%s' is not a valid directory" % args.target)

    PROJECT_DIR = args.target

    spy = SimpleModule('setup.py')
    if not spy.exists:
        sys.exit("Run upgrade only on folders that have a setup.py")

    csm = SimpleModule('setupmeta.py')  # current script module
    rsmlp = 'setupmeta.tmp'             # remote script module local path
    if os.path.islink(csm.full_path):
        # Symlink is convenient when iterating on setupmeta itself:
        # I symlink setupmeta.py to my own checkout of the main setupmeta...
        short_path = short(csm.full_path, c=0)
        sys.exit("'%s' is a symlink, can't upgrade" % short_path)

    try:
        fh = urlopen(args.url)
        contents = to_str(fh.read())

        with open(project_path(rsmlp), 'w') as fh:
            fh.write(contents)

    except Exception as e:
        print("Could not fetch %s: %s" % (args.url, e))
github zsimic / setupmeta / setupmeta.py View on Github external
default='.',
        nargs='?',
        help="Folder to install/upgrade (default: %(default)s)"
    )
    args = parser.parse_args(*argv)

    if args.command != 'upgrade':
        sys.exit("Command must be 'upgrade' (this is to avoid accidentals)")

    args.target = os.path.abspath(os.path.expanduser(args.target))
    if not os.path.isdir(args.target):
        sys.exit("'%s' is not a valid directory" % args.target)

    PROJECT_DIR = args.target

    spy = SimpleModule('setup.py')
    if not spy.exists:
        sys.exit("Run upgrade only on folders that have a setup.py")

    csm = SimpleModule('setupmeta.py')  # current script module
    rsmlp = 'setupmeta.tmp'             # remote script module local path
    if os.path.islink(csm.full_path):
        # Symlink is convenient when iterating on setupmeta itself:
        # I symlink setupmeta.py to my own checkout of the main setupmeta...
        short_path = short(csm.full_path, c=0)
        sys.exit("'%s' is a symlink, can't upgrade" % short_path)

    try:
        fh = urlopen(args.url)
        contents = to_str(fh.read())

        with open(project_path(rsmlp), 'w') as fh:
github zsimic / setupmeta / setupmeta.py View on Github external
props = SimpleModule('gradle.properties')
            vdef = props.definitions.get('version')
            if vdef:
                self.add_definition(
                    vdef.key,
                    vdef.value,
                    vdef.source
                )

        # Scan the usual/conventional places
        for py_module in py_modules:
            self.merge(SimpleModule('%s.py' % py_module))

        for package in packages:
            self.merge(
                SimpleModule(package, '__about__.py'),
                SimpleModule(package, '__version__.py'),
                SimpleModule(package, '__init__.py'),
                SimpleModule('src', package, '__about__.py'),
                SimpleModule('src', package, '__version__.py'),
                SimpleModule('src', package, '__init__.py'),
            )

        url = self.value('url')
        download_url = self.value('download_url')

        if url and self.name:
            parts = url.split('/')
            if len(parts) == 4 and 'github.com' == parts[2]:
                # Convenience: auto-complete url with package name
                url = os.path.join(url, self.name)
github zsimic / setupmeta / setupmeta.py View on Github external
for frame in inspect.stack():
                module = inspect.getmodule(frame[0])
                if Meta.is_setup_py_path(module.__file__):
                    setup_py_path = module.__file__
                    break

        if setup_py_path:
            global PROJECT_DIR
            PROJECT_DIR = os.path.dirname(os.path.abspath(setup_py_path))

        if self.value('use_scm_version'):
            # Don't look for version, let setuptools_scm do its thing
            self.ignore.add('version')

        # Allow to auto-fill 'name' from setup.py's __title__, if any
        self.merge(SimpleModule('setup.py', allowed='title'))
        title = self.definitions.pop('title', None)
        if title:
            self.auto_fill('name', title.value, source=title.source)

        packages = self.attrs.get('packages', [])
        py_modules = self.attrs.get('py_modules', [])

        if not packages and not py_modules and self.name:
            # Try to auto-determine a good default from 'self.name'
            if os.path.isfile(project_path(self.name, '__init__.py')):
                packages = [self.name]
                self.auto_fill('packages', packages)

            if os.path.isfile(project_path('src', self.name, '__init__.py')):
                packages = [self.name]
                self.auto_fill('packages', packages)
github zsimic / setupmeta / setupmeta.py View on Github external
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
        self.add_classifiers()

        # Entry points are more handily described in their own file
        self.add_full_contents('entry_points', ['entry_points.ini'])

        if 'PYGRADLE_PROJECT_VERSION' in os.environ:
            # Convenience: support https://github.com/linkedin/pygradle
            self.add_definition(
                'version',
                os.environ['PYGRADLE_PROJECT_VERSION'],
                'pygradle'
            )
        elif os.path.isfile(project_path('gradle.properties')):
            # Convenience: calling pygradle setup.py outside of pygradle
            props = SimpleModule('gradle.properties')
            vdef = props.definitions.get('version')
            if vdef:
                self.add_definition(
                    vdef.key,
                    vdef.value,
                    vdef.source
                )

        # Scan the usual/conventional places
        for py_module in py_modules:
            self.merge(SimpleModule('%s.py' % py_module))

        for package in packages:
            self.merge(
                SimpleModule(package, '__about__.py'),
                SimpleModule(package, '__version__.py'),