Exemplo n.º 1
0
    def run(self):
        version_info = self._get_package_version()
        if not (self.force or self._needs_static(version_info)):
            log.info("skipped asset build (version already built)")
            return

        log.info("building assets for Sentry v{} (build {})".format(
            version_info['version'] or 'UNKNOWN',
            version_info['build'] or 'UNKNOWN',
        ))
        try:
            self._build_static()
        except Exception:
            traceback.print_exc()
            log.fatal("unable to build Sentry's static assets!\n"
                      "Hint: You might be running an invalid version of NPM.")
            sys.exit(1)

        if version_info['version'] and version_info['build']:
            log.info("writing version manifest")
            manifest = self._write_version_file(version_info)
            log.info("recorded manifest\n{}".format(
                json.dumps(manifest, indent=2),
            ))

        # if we were invoked from sdist, we need to inform sdist about
        # which files we just generated.  Otherwise they will be missing
        # in the manifest.  This adds the files for what webpack generates
        # plus our own sentry-package.json file.
        sdist = self.distribution.get_command_obj('sdist')
        if sdist.finalized and not self.inplace:
            self._update_sdist_manifest(sdist.filelist)
Exemplo n.º 2
0
    def test_non_ascii(self):
        # Issues #8663, #34421: test that non-encodable text is escaped with
        # backslashreplace error handler and encodable non-ASCII text is
        # output as is.
        for errors in ('strict', 'backslashreplace', 'surrogateescape',
                       'replace', 'ignore'):
            with self.subTest(errors=errors):
                stdout = io.TextIOWrapper(io.BytesIO(),
                                          encoding='cp437', errors=errors)
                stderr = io.TextIOWrapper(io.BytesIO(),
                                          encoding='cp437', errors=errors)
                old_threshold = log.set_threshold(log.DEBUG)
                try:
                    with swap_attr(sys, 'stdout', stdout), \
                         swap_attr(sys, 'stderr', stderr):
                        log.debug('Dεbug\tMėssãge')
                        log.fatal('Fαtal\tÈrrōr')
                finally:
                    log.set_threshold(old_threshold)

                stdout.seek(0)
                self.assertEqual(stdout.read().rstrip(),
                        'Dεbug\tM?ss?ge' if errors == 'replace' else
                        'Dεbug\tMssge' if errors == 'ignore' else
                        'Dεbug\tM\\u0117ss\\xe3ge')
                stderr.seek(0)
                self.assertEqual(stderr.read().rstrip(),
                        'Fαtal\t?rr?r' if errors == 'replace' else
                        'Fαtal\trrr' if errors == 'ignore' else
                        'Fαtal\t\\xc8rr\\u014dr')
Exemplo n.º 3
0
    def run(self):
        version_info = self._get_package_version()
        if not (self.force or self._needs_static(version_info)):
            log.info("skipped asset build (version already built)")
            self.update_manifests()
            return

        log.info("building assets for Sentry v{} (build {})".format(
            version_info['version'] or 'UNKNOWN',
            version_info['build'] or 'UNKNOWN',
        ))
        if not version_info['version'] or not version_info['build']:
            log.fatal('Could not determine sentry version or build')
            sys.exit(1)

        try:
            self._build_static()
        except Exception:
            traceback.print_exc()
            log.fatal("unable to build Sentry's static assets!\n"
                      "Hint: You might be running an invalid version of NPM.")
            sys.exit(1)

        log.info("writing version manifest")
        manifest = self._write_version_file(version_info)
        log.info("recorded manifest\n{}".format(
            json.dumps(manifest, indent=2),
        ))
        self.update_manifests()
Exemplo n.º 4
0
    def _process_version_config(self, name, strategy_config, default_strategy=None, kwargs=None):
        try:
            version_type = strategy_config[self.FIELD_VERSION_STRATEGY]
        except KeyError:
            if default_strategy:
                version_type = default_strategy
            else:
                raise ValueError('No default version strategy :(')

        version_value = strategy_config.get(self.FIELD_VERSION_VALUE)

        try:
            version_strategy = self._registry[version_type]
        except KeyError:
            raise ValueError('Oh no! Unknown version strategy!')

        resolved_version = version_strategy(version_value, **(kwargs or {}))

        output_filename = strategy_config.get(self.FIELD_OUTPUT)
        if output_filename:
            norm_filename = os.path.join(*output_filename.split('/'))
            try:
                with codecs.open(norm_filename, mode='w', encoding='utf-8') as fp:
                    fp.write(resolved_version)
            except IOError:
                log.fatal("[{facility}] Cannot write version to {fn}".format(
                    facility=name, fn=norm_filename
                ))
                raise SystemExit(1)

        # TODO: deal gracefully with failed attempts, with a nice error message.
        # (e.g. no git binary, file doesn't exist, etc)
        return resolved_version
Exemplo n.º 5
0
    def _build(self):
        version_info = self._get_package_version()
        log.info(
            'building assets for {} v{} (build {})'.format(
                self.distribution.get_name(),
                version_info['version'] or 'UNKNOWN',
                version_info['build'] or 'UNKNOWN',
            )
        )
        if not version_info['version'] or not version_info['build']:
            log.fatal('Could not determine sentry version or build')
            sys.exit(1)

        try:
            self._build_static()
        except Exception:
            traceback.print_exc()
            log.fatal(
                'unable to build Sentry\'s static assets!\n'
                'Hint: You might be running an invalid version of NPM.'
            )
            sys.exit(1)

        log.info('writing version manifest')
        manifest = self._write_version_file(version_info)
        log.info('recorded manifest\n{}'.format(
            json.dumps(manifest, indent=2),
        ))
Exemplo n.º 6
0
    def _setup_npm(self):
        node_version = []
        for app in 'node', 'npm', 'yarn':
            try:
                node_version.append(
                    self._run_command([app, '--version']).rstrip())
            except OSError:
                if app == 'yarn':
                    # yarn is optional
                    node_version.append(None)
                else:
                    log.fatal(
                        'Cannot find `{0}` executable. Please install {0}`'
                        ' and try again.'.format(app))
                    sys.exit(1)

        if node_version[2] is not None:
            log.info('using node ({0}) and yarn ({2})'.format(*node_version))
            self._run_command([
                'yarn', 'install', '--production', '--pure-lockfile',
                '--ignore-optional'
            ])
        else:
            log.info('using node ({0}) and npm ({1})'.format(*node_version))
            self._run_command(['npm', 'install', '--production', '--quiet'])
Exemplo n.º 7
0
    def test_non_ascii(self):
        # Issues #8663, #34421: test that non-encodable text is escaped with
        # backslashreplace error handler and encodable non-ASCII text is
        # output as is.
        for errors in ('strict', 'backslashreplace', 'surrogateescape',
                       'replace', 'ignore'):
            with self.subTest(errors=errors), \
                 NamedTemporaryFile("w+", encoding='cp437', errors=errors) as stdout, \
                 NamedTemporaryFile("w+", encoding='cp437', errors=errors) as stderr:
                old_threshold = log.set_threshold(log.DEBUG)
                try:
                    with swap_attr(sys, 'stdout', stdout), \
                         swap_attr(sys, 'stderr', stderr):
                        log.debug('Dεbug\tMėssãge')
                        log.fatal('Fαtal\tÈrrōr')
                finally:
                    log.set_threshold(old_threshold)

                stdout.seek(0)
                self.assertEqual(
                    stdout.read().rstrip(),
                    'Dεbug\tM?ss?ge' if errors == 'replace' else 'Dεbug\tMssge'
                    if errors == 'ignore' else 'Dεbug\tM\\u0117ss\\xe3ge')
                stderr.seek(0)
                self.assertEqual(
                    stderr.read().rstrip(),
                    'Fαtal\t?rr?r' if errors == 'replace' else 'Fαtal\trrr'
                    if errors == 'ignore' else 'Fαtal\t\\xc8rr\\u014dr')
Exemplo n.º 8
0
    def run(self):
        version_info = self._get_package_version()
        if not (self.force or self._needs_static(version_info)):
            log.info("skipped asset build (version already built)")
            return

        log.info("building assets for Sentry v{} (build {})".format(
            version_info['version'] or 'UNKNOWN',
            version_info['build'] or 'UNKNOWN',
        ))
        try:
            self._build_static()
        except Exception:
            traceback.print_exc()
            log.fatal("unable to build Sentry's static assets!\n"
                      "Hint: You might be running an invalid version of NPM.")
            sys.exit(1)

        if version_info['version'] and version_info['build']:
            log.info("writing version manifest")
            manifest = self._write_version_file(version_info)
            log.info("recorded manifest\n{}".format(
                json.dumps(manifest, indent=2),
            ))

        # if we were invoked from sdist, we need to inform sdist about
        # which files we just generated.  Otherwise they will be missing
        # in the manifest.  This adds the files for what webpack generates
        # plus our own sentry-package.json file.
        sdist = self.distribution.get_command_obj('sdist')
        if sdist.finalized and not self.inplace:
            self._update_sdist_manifest(sdist.filelist)
Exemplo n.º 9
0
    def _build(self):
        try:
            self._build_static()
        except Exception:
            traceback.print_exc()
            log.fatal('unable to build Seed\'s static assets!\n')
            sys.exit(1)

        self._move_statics()
Exemplo n.º 10
0
def call_git(*params):
    # Might throw EnvironmentError if git isn't on the path.
    try:
        result = Popen(('git', ) + params, stdout=PIPE, stderr=PIPE).communicate()[0]
    except EnvironmentError as ex:
        log.fatal("[git-pep440] Cannot call git... {}".format(ex))
        raise SystemExit(getattr(ex, 'errno', 1))

    return result.strip().decode('utf-8')
Exemplo n.º 11
0
 def run(self):
     install_command = self.get_finalized_command('install')
     for e in self.extras:
         try:
             extras = self.distribution.extras_require[e]
         except KeyError:
             log.fatal('Extra \'{}\' not found'.format(e))
             raise
         install_command.distribution.install_requires.extend(extras)
Exemplo n.º 12
0
def set_working_dir():
    """ Make sure we're working in the right directory, and ensure this is
        actually a setup.py file.
    """
    setup_py = sys.argv[0]
    if os.path.basename(setup_py) == 'setup.py':
        setup_py_dir = os.path.dirname(setup_py)
        if setup_py_dir:
            os.chdir(setup_py_dir)
    if not os.path.isfile(os.path.join(os.getcwd(), 'setup.cfg')):
        log.fatal("Can't find setup.cfg")
Exemplo n.º 13
0
def set_working_dir():
    """ Make sure we're working in the right directory, and ensure this is
        actually a setup.py file.
    """
    setup_py = sys.argv[0]
    if os.path.basename(setup_py) != 'setup.py':
        log.fatal("You should only only be running this as 'python path/to/setup.py'")
        sys.exit(1)

    setup_py_dir = os.path.dirname(setup_py)
    if setup_py_dir:
        os.chdir(setup_py_dir)
Exemplo n.º 14
0
    def _setup_js_deps(self):
        node_version = None
        try:
            node_version = self._run_command(["node", "--version"]).decode("utf-8").rstrip()
        except OSError:
            log.fatal("Cannot find node executable. Please install node" " and try again.")
            sys.exit(1)

        if node_version[2] is not None:
            log.info("using node ({0})".format(node_version))
            self._run_npm_command(["install"])
            self._run_npm_command(["run", "build", "--quiet"])
Exemplo n.º 15
0
    def _setup_js_deps(self):
        node_version = None
        try:
            node_version = self._run_command(["node", "--version"]).rstrip()
        except OSError:
            log.fatal(u"Cannot find node executable. Please install node"
                      " and try again.")
            sys.exit(1)

        if node_version[2] is not None:
            log.info(u"using node ({0})".format(node_version))
            self._run_yarn_command(
                ["install", "--production", "--frozen-lockfile", "--quiet"])
Exemplo n.º 16
0
    def _setup_npm(self):
        node_version = []
        for app in 'node', 'npm':
            try:
                node_version.append(
                    self._run_command([app, '--version']).rstrip())
            except OSError:
                log.fatal('Cannot find `{0}` executable. Please install {0}`'
                          ' and try again.'.format(app))
                sys.exit(1)

        log.info('using node ({}) and npm ({})'.format(*node_version))

        self._run_command(['npm', 'install', '--production', '--quiet'])
Exemplo n.º 17
0
def main():
    """Main method of pycheckout"""
    # TODO: allow cmdline override of org config?
    org.setup_global_org_config()
    options = get_options()

    try:
        pypi = PyPi(options.pypi)
        process_pkg(pypi, options.package, options.dest_dir, options,
                    options.deps)
        log.info("Done!")

    except (CalledProcessError, UserError), e:
        log.fatal(e)
        sys.exit(15)
Exemplo n.º 18
0
    def _setup_npm(self):
        work_path = self.work_path
        node_version = []
        for app in 'node', 'npm':
            try:
                node_version.append(check_output([app, '--version']).rstrip())
            except OSError:
                log.fatal('Cannot find `{0}` executable. Please install {0}`'
                          ' and try again.'.format(app))
                sys.exit(1)

        log.info('using node ({}) and npm ({})'.format(*node_version))

        log.info('running [npm install --production --quiet]')
        check_output(['npm', 'install', '--production', '--quiet'], cwd=work_path)
Exemplo n.º 19
0
def main():
    """Main method of pycheckout"""
    # TODO: allow cmdline override of org config?
    config.setup_org_config()
    options = get_options()

    try:
        pypi = PyPi(options.pypi)
        process_pkg(pypi, options.package, options.dest_dir, options,
                    options.deps)
        log.info("Done!")

    except (CalledProcessError, UserError), e:
        log.fatal(e)
        sys.exit(15)
Exemplo n.º 20
0
    def _setup_npm(self):
        node_version = []
        for app in 'node', 'npm':
            try:
                node_version.append(
                    self._run_command([app, '--version']).rstrip()
                )
            except OSError:
                log.fatal('Cannot find `{0}` executable. Please install {0}`'
                          ' and try again.'.format(app))
                sys.exit(1)

        log.info('using node ({}) and npm ({})'.format(*node_version))

        self._run_command(['npm', 'install', '--production', '--quiet'])
Exemplo n.º 21
0
    def _setup_js_deps(self):
        node_version = None
        try:
            node_version = self._run_command(['node', '--version']).rstrip()
        except OSError:
            log.fatal(
                u'Cannot find node executable. Please install node'
                ' and try again.'
            )
            sys.exit(1)

        if node_version[2] is not None:
            log.info(u'using node ({0}))'.format(node_version))
            self._run_yarn_command(
                ['install', '--production', '--pure-lockfile', '--quiet']
            )
Exemplo n.º 22
0
def resolve_interpreter(exe):
    """
    If the executable given isn't an absolute path, search $PATH for the interpreter
    """
    if os.path.abspath(exe) != exe:
        paths = os.environ.get('PATH', '').split(os.pathsep)
        for path in paths:
            if os.path.exists(os.path.join(path, exe)):
                exe = os.path.join(path, exe)
                break
            elif os.path.exists(os.path.join(path, exe + '.exe')):
                exe = os.path.join(path, exe + '.exe')
                break
    if not os.path.exists(exe):
        log.fatal('The executable %s (from -p %s) does not exist' % (exe, exe))
        sys.exit(3)
    return exe
Exemplo n.º 23
0
    def __call__(self, config, facility_section_name):
        metadata_config = config.setdefault('metadata', {})

        files_config = config.setdefault('files', {})
        self._expand_data_files_globs(files_config)
        self._expand_scripts_globs(files_config)
        self._add_extra_files_from_cfg(files_config)

        facility_config = config.setdefault(facility_section_name, {})

        if parse_boolean(facility_config.get(self.FIELD_MANUAL, '')):
            return

        root = self._get_packages_root(files_config)

        try:
            external_extra_files = self._finder()
        except RuntimeError:
            # Looks like someone tries to install us
            external_extra_files = self._get_extra_files_from_egg_info(metadata_config, root)

        if parse_boolean(facility_config.get(self.FIELD_EVERYTHING, '')):
            for filename in external_extra_files:
                self._add_file(filename)
                return  # TODO: refactor

        # TODO: add option to disable auto package-data

        packages = files_config.get('packages', '').strip()
        if not packages:
            return

        package_list = packages.split('\n')

        if root and not os.path.isdir(root):
            log.fatal("[%s] The 'packages_root' value should be a dir name" % facility_section_name)
            raise SystemExit(1)

        extra_files_in_root = [f for f in external_extra_files
                               if os.path.commonprefix([root, f]) == root and not f.endswith('.py')]

        package_paths = [os.path.join(root, *p.split('.')) for p in package_list]

        for filename in filter(None, extra_files_in_root):
            if any(filename.startswith(p) for p in package_paths):
                self._add_file(filename)
Exemplo n.º 24
0
 def test_non_ascii(self):
     old_stdout = sys.stdout
     old_stderr = sys.stderr
     old_threshold = log.set_threshold(log.DEBUG)
     try:
         with NamedTemporaryFile(mode='w+', encoding='ascii'
             ) as stdout, NamedTemporaryFile(mode='w+', encoding='ascii'
             ) as stderr:
             sys.stdout = stdout
             sys.stderr = stderr
             log.debug('debug:é')
             log.fatal('fatal:é')
             stdout.seek(0)
             self.assertEqual(stdout.read().rstrip(), 'debug:\\xe9')
             stderr.seek(0)
             self.assertEqual(stderr.read().rstrip(), 'fatal:\\xe9')
     finally:
         log.set_threshold(old_threshold)
         sys.stdout = old_stdout
         sys.stderr = old_stderr
Exemplo n.º 25
0
 def test_non_ascii(self):
     # Issue #8663: test that non-ASCII text is escaped with
     # backslashreplace error handler (stream use ASCII encoding and strict
     # error handler)
     old_stdout = sys.stdout
     old_stderr = sys.stderr
     try:
         log.set_threshold(log.DEBUG)
         with NamedTemporaryFile(mode="w+", encoding='ascii') as stdout, \
              NamedTemporaryFile(mode="w+", encoding='ascii') as stderr:
             sys.stdout = stdout
             sys.stderr = stderr
             log.debug("debug:\xe9")
             log.fatal("fatal:\xe9")
             stdout.seek(0)
             self.assertEqual(stdout.read().rstrip(), "debug:\\xe9")
             stderr.seek(0)
             self.assertEqual(stderr.read().rstrip(), "fatal:\\xe9")
     finally:
         sys.stdout = old_stdout
         sys.stderr = old_stderr
Exemplo n.º 26
0
    def _build(self):
        version_info = self._get_package_version()
        log.info("building assets for {} v{} (build {})".format(
            self.distribution.get_name(),
            version_info["version"] or "UNKNOWN",
            version_info["build"] or "UNKNOWN",
        ))
        if not version_info["version"] or not version_info["build"]:
            log.fatal("Could not determine sentry version or build")
            sys.exit(1)

        try:
            self._build_static()
        except Exception:
            traceback.print_exc()
            log.fatal("unable to build Sentry's static assets!")
            sys.exit(1)

        log.info("writing version manifest")
        manifest = self._write_version_file(version_info)
        log.info(f"recorded manifest\n{json.dumps(manifest, indent=2)}")
Exemplo n.º 27
0
 def test_non_ascii(self):
     # Issue #8663: test that non-ASCII text is escaped with
     # backslashreplace error handler (stream use ASCII encoding and strict
     # error handler)
     old_stdout = sys.stdout
     old_stderr = sys.stderr
     try:
         log.set_threshold(log.DEBUG)
         with NamedTemporaryFile(mode="w+", encoding='ascii') as stdout, \
              NamedTemporaryFile(mode="w+", encoding='ascii') as stderr:
             sys.stdout = stdout
             sys.stderr = stderr
             log.debug("debug:\xe9")
             log.fatal("fatal:\xe9")
             stdout.seek(0)
             self.assertEqual(stdout.read().rstrip(), "debug:\\xe9")
             stderr.seek(0)
             self.assertEqual(stderr.read().rstrip(), "fatal:\\xe9")
     finally:
         sys.stdout = old_stdout
         sys.stderr = old_stderr
Exemplo n.º 28
0
    def _get_facility_config(config, facility_section_name, separator=':'):
        facility_config = config.setdefault(facility_section_name, {})

        extra_config = OrderedDict()
        for key in config:
            if separator not in key:
                continue

            tokens = key.split(separator, 1)
            main_token, extra_name = tokens
            if main_token != facility_section_name:
                continue

            if not extra_name:
                log.fatal(
                    "[{facility}] The '{key}' is wrong section name (it cannot end with a colon)"
                    .format(facility=facility_section_name, key=key))
                raise SystemExit(1)

            extra_config[extra_name] = config[key]

        return facility_config, extra_config
Exemplo n.º 29
0
    def run(self):
        version_info = self._get_package_version()
        if not (self.force or self._needs_static(version_info)):
            log.info("skipped asset build (version already built)")
            return

        log.info("building assets for Sentry v{} (build {})".format(
            version_info['version'] or 'UNKNOWN',
            version_info['build'] or 'UNKNOWN',
        ))
        try:
            self._build_static()
        except Exception:
            log.fatal("unable to build Sentry's static assets!\n"
                      "Hint: You might be running an invalid version of NPM.")
            sys.exit(1)

        if version_info['version'] and version_info['build']:
            log.info("writing version manifest")
            manifest = self._write_version_file(version_info)
            log.info("recorded manifest\n{}".format(
                json.dumps(manifest, indent=2), ))
Exemplo n.º 30
0
    def _build(self):
        version_info = self._get_package_version()
        log.info(u'building assets for {} v{} (build {})'.format(
            self.distribution.get_name(),
            version_info['version'] or 'UNKNOWN',
            version_info['build'] or 'UNKNOWN',
        ))
        if not version_info['version'] or not version_info['build']:
            log.fatal('Could not determine sentry version or build')
            sys.exit(1)

        try:
            self._build_static()
        except Exception:
            traceback.print_exc()
            log.fatal('unable to build Sentry\'s static assets!')
            sys.exit(1)

        log.info('writing version manifest')
        manifest = self._write_version_file(version_info)
        log.info(u'recorded manifest\n{}'.format(
            json.dumps(manifest, indent=2), ))
Exemplo n.º 31
0
    def _setup_npm(self):
        node_version = []

        log.info("setup node and npm.....")
        for app in ['node', 'npm']:
            try:
                log.info('testing %s version.....' % app)
                node_version.append(
                    self._run_command([app, '--version']).rstrip())
            except OSError as e:
                log.fatal('Cannot find {app} excutable. Please install {app}'
                          'and try again.'.format(app=app))
                sys.exit(1)

        if node_version[0] >= b'v6.8.1':
            log.fatal(
                'The node version need v7.8.1, the current node version is %s'
                % node_version[0])
            sys.exit(1)

        log.info('using node ({0}) and npm ({1})'.format(*node_version))
        self._run_command(['npm', 'install'])
Exemplo n.º 32
0
    def _setup_npm(self):
        node_version = []
        for app in 'node', 'npm', 'yarn':
            try:
                node_version.append(
                    self._run_command([app, '--version']).rstrip()
                )
            except OSError:
                if app == 'yarn':
                    # yarn is optional
                    node_version.append(None)
                else:
                    log.fatal('Cannot find `{0}` executable. Please install {0}`'
                              ' and try again.'.format(app))
                    sys.exit(1)

        if node_version[2] is not None:
            log.info('using node ({0}) and yarn ({2})'.format(*node_version))
            self._run_command(['yarn', 'install', '--production', '--pure-lockfile', '--ignore-optional'])
        else:
            log.info('using node ({0}) and npm ({1})'.format(*node_version))
            self._run_command(['npm', 'install', '--production', '--quiet'])
Exemplo n.º 33
0
Arquivo: setup.py Projeto: wlcx/sentry
    def run(self):
        need_integration_docs = not os.path.isdir(INTEGRATION_DOC_FOLDER)
        version_info = self._get_package_version()

        if not (self.force or self._needs_static(version_info)):
            log.info("skipped asset build (version already built)")
        else:
            log.info("building assets for Sentry v{} (build {})".format(
                version_info['version'] or 'UNKNOWN',
                version_info['build'] or 'UNKNOWN',
            ))
            if not version_info['version'] or not version_info['build']:
                log.fatal('Could not determine sentry version or build')
                sys.exit(1)

            try:
                self._build_static()
            except Exception:
                traceback.print_exc()
                log.fatal("unable to build Sentry's static assets!\n"
                          "Hint: You might be running an invalid version of NPM.")
                sys.exit(1)

            log.info("writing version manifest")
            manifest = self._write_version_file(version_info)
            log.info("recorded manifest\n{}".format(
                json.dumps(manifest, indent=2),
            ))
            need_integration_docs = True

        if not need_integration_docs:
            log.info('skipped integration docs (already downloaded)')
        else:
            log.info('downloading integration docs')
            from sentry.utils.integrationdocs import sync_docs
            sync_docs()

        self.update_manifests()
Exemplo n.º 34
0
    def run(self):
        need_integration_docs = not os.path.isdir(INTEGRATION_DOC_FOLDER)
        version_info = self._get_package_version()

        if not (self.force or self._needs_static(version_info)):
            log.info("skipped asset build (version already built)")
        else:
            log.info("building assets for Sentry v{} (build {})".format(
                version_info['version'] or 'UNKNOWN',
                version_info['build'] or 'UNKNOWN',
            ))
            if not version_info['version'] or not version_info['build']:
                log.fatal('Could not determine sentry version or build')
                sys.exit(1)

            try:
                self._build_static()
            except Exception:
                traceback.print_exc()
                log.fatal(
                    "unable to build Sentry's static assets!\n"
                    "Hint: You might be running an invalid version of NPM.")
                sys.exit(1)

            log.info("writing version manifest")
            manifest = self._write_version_file(version_info)
            log.info("recorded manifest\n{}".format(
                json.dumps(manifest, indent=2), ))
            need_integration_docs = True

        if not need_integration_docs:
            log.info('skipped integration docs (already downloaded)')
        else:
            log.info('downloading integration docs')
            from sentry.utils.integrationdocs import sync_docs
            sync_docs()

        self.update_manifests()
Exemplo n.º 35
0
    def _setup_npm(self):
        node_version = []
        for candidates in ['node', 'nodejs'], ['npm']:
            found = False

            for name in candidates:
                try:
                    node_version.append(
                        self._run_command([name, '--version']).rstrip())

                    found = True
                    break
                except OSError:
                    pass

            if not found:
                log.fatal('Cannot find `{0}` executable. Please install {0}`'
                          ' and try again.'.format(candidates[0]))
                sys.exit(1)

        log.info('using node ({}) and npm ({})'.format(*node_version))

        self._run_command(['npm', 'install', '--production', '--quiet'])
Exemplo n.º 36
0
    def _process_version_config(self,
                                name,
                                strategy_config,
                                default_strategy=None,
                                kwargs=None):
        try:
            version_type = strategy_config[self.FIELD_VERSION_STRATEGY]
        except KeyError:
            if default_strategy:
                version_type = default_strategy
            else:
                raise ValueError('No default version strategy :(')

        version_value = strategy_config.get(self.FIELD_VERSION_VALUE)

        try:
            version_strategy = self._registry[version_type]
        except KeyError:
            raise ValueError('Oh no! Unknown version strategy!')

        resolved_version = version_strategy(version_value, **(kwargs or {}))

        output_filename = strategy_config.get(self.FIELD_OUTPUT)
        if output_filename:
            norm_filename = os.path.join(*output_filename.split('/'))
            try:
                with codecs.open(norm_filename, mode='w',
                                 encoding='utf-8') as fp:
                    fp.write(resolved_version)
            except IOError:
                log.fatal("[{facility}] Cannot write version to {fn}".format(
                    facility=name, fn=norm_filename))
                raise SystemExit(1)

        # TODO: deal gracefully with failed attempts, with a nice error message.
        # (e.g. no git binary, file doesn't exist, etc)
        return resolved_version
Exemplo n.º 37
0
    def run(self):
        need_integration_docs = not os.path.isdir(INTEGRATION_DOC_FOLDER)
        version_info = self._get_package_version()

        if not (self.force or self._needs_static(version_info)):
            log.info("skipped asset build (version already built)")
        else:
            log.info("building assets for Sentry v{} (build {})".format(
                version_info['version'] or 'UNKNOWN',
                version_info['build'] or 'UNKNOWN',
            ))
            if not version_info['version'] or not version_info['build']:
                log.fatal('Could not determine sentry version or build')
                sys.exit(1)

            node_version = []
            for app in 'node', 'npm':
                try:
                    node_version.append(
                        check_output([app, '--version']).rstrip())
                except OSError:
                    log.fatal(
                        'Cannot find `{0}` executable. Please install {0}`'
                        ' and try again.'.format(app))
                    sys.exit(1)

            log.info('using node ({}) and npm ({})'.format(*node_version))

            try:
                self._build_static()
            except Exception:
                traceback.print_exc()
                log.fatal(
                    "unable to build Sentry's static assets!\n"
                    "Hint: You might be running an invalid version of NPM.")
                sys.exit(1)

            log.info("writing version manifest")
            manifest = self._write_version_file(version_info)
            log.info("recorded manifest\n{}".format(
                json.dumps(manifest, indent=2), ))
            need_integration_docs = True

        if not need_integration_docs:
            log.info('skipped integration docs (already downloaded)')
        else:
            log.info('downloading integration docs')
            from sentry.utils.integrationdocs import sync_docs
            sync_docs()

        self.update_manifests()
Exemplo n.º 38
0
    def run(self):
        need_integration_docs = not os.path.isdir(INTEGRATION_DOC_FOLDER)
        version_info = self._get_package_version()

        if not (self.force or self._needs_static(version_info)):
            log.info("skipped asset build (version already built)")
        else:
            log.info("building assets for Sentry v{} (build {})".format(
                version_info['version'] or 'UNKNOWN',
                version_info['build'] or 'UNKNOWN',
            ))
            if not version_info['version'] or not version_info['build']:
                log.fatal('Could not determine sentry version or build')
                sys.exit(1)

            node_version = []
            for app in 'node', 'npm':
                try:
                    node_version.append(check_output([app, '--version']).rstrip())
                except OSError:
                    log.fatal('Cannot find `{0}` executable. Please install {0}`'
                              ' and try again.'.format(app))
                    sys.exit(1)

            log.info('using node ({}) and npm ({})'.format(*node_version))

            try:
                self._build_static()
            except Exception:
                traceback.print_exc()
                log.fatal("unable to build Sentry's static assets!\n"
                          "Hint: You might be running an invalid version of NPM.")
                sys.exit(1)

            log.info("writing version manifest")
            manifest = self._write_version_file(version_info)
            log.info("recorded manifest\n{}".format(
                json.dumps(manifest, indent=2),
            ))
            need_integration_docs = True

        if not need_integration_docs:
            log.info('skipped integration docs (already downloaded)')
        else:
            log.info('downloading integration docs')
            from sentry.utils.integrationdocs import sync_docs
            sync_docs()

        self.update_manifests()
Exemplo n.º 39
0
import re
import shutil
import subprocess
import sys
import tempfile
from distutils import log
from distutils.command.install import install
from distutils.command.install_data import install_data
from distutils.command.install_lib import install_lib
from distutils.core import setup
from distutils.debug import DEBUG

VERSION = "4.0.0"

if sys.version_info < (2, 7):
    log.fatal('WeeWX requires Python V2.7 or greater.')
    log.fatal('For earlier versions of Python, use WeeWX V3.9.')
    sys.exit("Python version unsupported.")

this_file = os.path.join(os.getcwd(), __file__)
this_dir = os.path.abspath(os.path.dirname(this_file))

# ==============================================================================
# install
# ==============================================================================


class weewx_install(install):
    """Specialized version of install, which runs a post-install script"""
    def finalize_options(self):
        # Call my superclass's version
Exemplo n.º 40
0
    # Get GDAL API version from environment variable.
    if 'GDAL_VERSION' in os.environ:
        gdalversion = os.environ['GDAL_VERSION']
        log.info("GDAL API version obtained from environment: %s", gdalversion)

    # Get GDAL API version from the command line if specified there.
    if '--gdalversion' in sys.argv:
        index = sys.argv.index('--gdalversion')
        sys.argv.pop(index)
        gdalversion = sys.argv.pop(index)
        log.info("GDAL API version obtained from command line option: %s",
                 gdalversion)

    if not gdalversion:
        log.fatal("A GDAL API version must be specified. Provide a path "
                  "to gdal-config using a GDAL_CONFIG environment variable "
                  "or use a GDAL_VERSION environment variable.")
        sys.exit(1)

    if os.environ.get('PACKAGE_DATA'):
        destdir = 'fiona/gdal_data'
        if gdal_output[2]:
            log.info("Copying gdal data from %s" % gdal_output[2])
            copy_data_tree(gdal_output[2], destdir)
        else:
            # check to see if GDAL_DATA is defined
            gdal_data = os.environ.get('GDAL_DATA', None)
            if gdal_data:
                log.info("Copying gdal data from %s" % gdal_data)
                copy_data_tree(gdal_data, destdir)
Exemplo n.º 41
0
    def run(self):
        # base run
        _build.run(self)

        # custom run
        log.info('Now building cppyy-cling')
        builddir = get_builddir()
        prefix   = get_prefix()
        srcdir   = get_srcdir()
        if not os.path.exists(srcdir):
            log.info('No src directory ... creating with "python create_src_directory.py"')
            if subprocess.call(['python', 'create_src_directory.py']) != 0:
                log.error('ERROR: the source directory "%s" does not exist' % srcdir)
                log.error('Please run "python create_src_directory.py" first.')
                sys.exit(1)

        if not os.path.exists(builddir):
            log.info('Creating build directory %s ...' % builddir)
            os.makedirs(builddir)

        # get C++ standard to use, if set
        try:
            stdcxx = os.environ['STDCXX']
        except KeyError:
            if is_manylinux():
                stdcxx = '11'
            elif 'win32' in sys.platform:
                stdcxx = '14'     # current cmake claims MSVC'17 does not support C++17 yet
            else:
                stdcxx = '17'

        if not stdcxx in ['11', '14', '17']:
            log.fatal('FATAL: envar STDCXX should be one of 11, 14, or 17')
            sys.exit(1)

        stdcxx='-Dcxx'+stdcxx+'=ON'

        # extra optimization flags for Cling
        if not 'EXTRA_CLING_ARGS' in os.environ:
            has_avx = False
            if not is_manylinux():
                try:
                    for line in open('/proc/cpuinfo', 'r'):
                        if 'avx' in line:
                            has_avx = True
                            break
                except Exception:
                    try:
                        cli_arg = subprocess.check_output(['sysctl', 'machdep.cpu.features'])
                        has_avx = 'avx' in cli_arg.decode("utf-8").strip().lower()
                    except Exception:
                        pass
            extra_args = '-O2'
            if has_avx: extra_args += ' -mavx'
            os.putenv('EXTRA_CLING_ARGS', extra_args)

        CMAKE_COMMAND = ['cmake', srcdir,
                stdcxx, '-DLLVM_ENABLE_TERMINFO=0',
                '-Dminimal=ON', '-Dasimage=OFF', '-Droot7=OFF', '-Dhttp=OFF',
                '-Dbuiltin_pcre=ON', '-Dbuiltin_freetype=ON', '-Dbuiltin_zlib=ON', '-Dbuiltin_xxhash=ON']
        if 'darwin' in sys.platform:
            CMAKE_COMMAND.append('-Dlibcxx=ON')
        CMAKE_COMMAND.append('-DCMAKE_BUILD_TYPE='+get_build_type())
        if 'win32' in sys.platform:
            import platform
            if '64' in platform.architecture()[0]:
                CMAKE_COMMAND += ['-Thost=x64', '-DCMAKE_GENERATOR_PLATFORM=x64', '-Dall=OFF',
                        '-Dmathmore=OFF', '-Dbuiltin_ftgl=OFF', '-Droofit=OFF', '-Dgfal=OFF', '-Dfftw3=OFF']
                FFTW_INC = os.environ.get("FFTW_INC", None)
                FFTW_LIB = os.environ.get("FFTW_LIB", None)
                if FFTW_INC and FFTW_LIB:
                    CMAKE_COMMAND += ["-DFFTW_INCLUDE_DIR={}".format(FFTW_INC), "-DFFTW_LIBRARY={}".format(FFTW_LIB)]
        else:
            CMAKE_COMMAND += ['-Dbuiltin_freetype=OFF']
        CMAKE_COMMAND.append('-DCMAKE_INSTALL_PREFIX='+prefix)

        log.info('Running cmake for cppyy-cling: %s', ' '.join(CMAKE_COMMAND))
        if subprocess.call(CMAKE_COMMAND, cwd=builddir) != 0:
            raise DistutilsSetupError('Failed to configure cppyy-cling')

        # use $MAKE to build if it is defined
        env_make = os.getenv('MAKE')
        if not env_make:
            build_cmd = 'cmake'
            # default to using all available cores (x2 if hyperthreading enabled)
            nprocs = os.getenv("MAKE_NPROCS") or '0'
            try:
                nprocs = int(nprocs)
            except ValueError:
                log.warn("Integer expected for MAKE_NPROCS, but got %s (ignored)", nprocs)
                nprocs = 0
            if nprocs < 1:
                nprocs = multiprocessing.cpu_count()
            build_args = ['--build', '.', '--config', get_build_type(), '--']
            if 'win32' in sys.platform:
                build_args.append('/maxcpucount:' + str(nprocs))
            else:
                build_args.append('-j' + str(nprocs))
        else:
            build_args = env_make.split()
            build_cmd, build_args = build_args[0], build_args[1:]
        log.info('Now building cppyy-cling and dependencies ...')
        if env_make: os.unsetenv("MAKE")
        if subprocess.call([build_cmd] + build_args, cwd=builddir) != 0:
            raise DistutilsSetupError('Failed to build cppyy-cling')
        if env_make: os.putenv('MAKE', env_make)

        log.info('Build finished')
Exemplo n.º 42
0
#   user's home directory and prompts of the password if it has been left
#   out of the configuration file.
#
#   This has to be done very first thing to get around the convoluted class
#   hierarchy of the upload/register commands.

from pkglib.setuptools.command.pypirc import PyPIRCCommand
import distutils.config
distutils.config.PyPIRCCommand = PyPIRCCommand

from distutils import log
try:
    from setuptools import _distribute
except ImportError, e:
    log.fatal("Please install distribute to continue. "
              "Eg: 'easy_install distribute'. \n"
              "If using virtualenv you can do this with "
              "'virtualenv pyenv --distribute'")
    sys.exit(1)

from setuptools.command import develop, easy_install
from setuptools.dist import Distribution

from pkglib import config, CONFIG
from pkglib.setuptools import _setup
from pkglib.setuptools.command import develop as pkglib_develop


def get_index_url():
    url = CONFIG.pypi_url
    if not url.endswith('/simple') and not url.endswith('/simple/'):
        url += '/simple'
Exemplo n.º 43
0
    def run(self):
        # base run
        _build.run(self)

        # custom run
        log.info('Now building cppyy-cling')
        builddir = get_builddir()
        prefix = get_prefix()
        srcdir = get_srcdir()
        if not os.path.exists(srcdir):
            log.info(
                'No src directory ... creating with "python create_src_directory.py"'
            )
            if subprocess.call(['python', 'create_src_directory.py']) != 0:
                log.error('ERROR: the source directory "%s" does not exist' %
                          srcdir)
                log.error('Please run "python create_src_directory.py" first.')
                sys.exit(1)

        if not os.path.exists(builddir):
            log.info('Creating build directory %s ...' % builddir)
            os.makedirs(builddir)

        # get C++ standard to use, if set
        try:
            stdcxx = os.environ['STDCXX']
        except KeyError:
            if is_manylinux():
                stdcxx = '11'
            elif 'win32' in sys.platform:
                stdcxx = '14'  # current cmake claims MSVC'17 does not support C++17 yet
            else:
                stdcxx = '17'

        if not stdcxx in ['11', '14', '17']:
            log.fatal('FATAL: envar STDCXX should be one of 11, 14, or 17')
            sys.exit(1)

        stdcxx = '-Dcxx' + stdcxx + '=ON'

        # extra optimization flags for Cling
        if not 'EXTRA_CLING_ARGS' in os.environ:
            has_avx = False
            if not is_manylinux():
                try:
                    for line in open('/proc/cpuinfo', 'r'):
                        if 'avx' in line:
                            has_avx = True
                            break
                except Exception:
                    try:
                        cli_arg = subprocess.check_output(
                            ['sysctl', 'machdep.cpu.features'])
                        has_avx = 'avx' in cli_arg.decode(
                            "utf-8").strip().lower()
                    except Exception:
                        pass
            extra_args = '-O2'
            if has_avx: extra_args += ' -mavx'
            os.putenv('EXTRA_CLING_ARGS', extra_args)

        CMAKE_COMMAND = [
            'cmake', srcdir, stdcxx, '-DLLVM_ENABLE_TERMINFO=0',
            '-Dminimal=ON', '-Dasimage=OFF', '-Droot7=OFF', '-Dhttp=OFF',
            '-Dbuiltin_pcre=ON', '-Dbuiltin_freetype=ON', '-Dbuiltin_zlib=ON',
            '-Dbuiltin_xxhash=ON'
        ]
        if 'darwin' in sys.platform:
            CMAKE_COMMAND.append('-Dlibcxx=ON')
        CMAKE_COMMAND.append('-DCMAKE_BUILD_TYPE=' + get_build_type())
        if 'win32' in sys.platform:
            import platform
            if '64' in platform.architecture()[0]:
                CMAKE_COMMAND += [
                    '-Thost=x64', '-DCMAKE_GENERATOR_PLATFORM=x64',
                    '-Dall=OFF', '-Dmathmore=OFF', '-Dbuiltin_ftgl=OFF',
                    '-Droofit=OFF', '-Dgfal=OFF', '-Dfftw3=OFF'
                ]
                FFTW_INC = os.environ.get("FFTW_INC", None)
                FFTW_LIB = os.environ.get("FFTW_LIB", None)
                if FFTW_INC and FFTW_LIB:
                    CMAKE_COMMAND += [
                        "-DFFTW_INCLUDE_DIR={}".format(FFTW_INC),
                        "-DFFTW_LIBRARY={}".format(FFTW_LIB)
                    ]
        else:
            CMAKE_COMMAND += ['-Dbuiltin_freetype=OFF']
        CMAKE_COMMAND.append('-DCMAKE_INSTALL_PREFIX=' + prefix)

        log.info('Running cmake for cppyy-cling: %s', ' '.join(CMAKE_COMMAND))
        if subprocess.call(CMAKE_COMMAND, cwd=builddir) != 0:
            raise DistutilsSetupError('Failed to configure cppyy-cling')

        # use $MAKE to build if it is defined
        env_make = os.getenv('MAKE')
        if not env_make:
            build_cmd = 'cmake'
            # default to using all available cores (x2 if hyperthreading enabled)
            nprocs = os.getenv("MAKE_NPROCS") or '0'
            try:
                nprocs = int(nprocs)
            except ValueError:
                log.warn(
                    "Integer expected for MAKE_NPROCS, but got %s (ignored)",
                    nprocs)
                nprocs = 0
            if nprocs < 1:
                nprocs = multiprocessing.cpu_count()
            build_args = ['--build', '.', '--config', get_build_type(), '--']
            if 'win32' in sys.platform:
                build_args.append('/maxcpucount:' + str(nprocs))
            else:
                build_args.append('-j' + str(nprocs))
        else:
            build_args = env_make.split()
            build_cmd, build_args = build_args[0], build_args[1:]
        log.info('Now building cppyy-cling and dependencies ...')
        if env_make: os.unsetenv("MAKE")
        if subprocess.call([build_cmd] + build_args, cwd=builddir) != 0:
            raise DistutilsSetupError('Failed to build cppyy-cling')
        if env_make: os.putenv('MAKE', env_make)

        log.info('Build finished')
	def do_build_files (self, action):

		if os.name == 'posix':

			# First check if we have everything installed we need to build the
			# distribution

			if os.path.isdir ('po'):
				# xgettext
				if os.system ("pygettext --version > /dev/null") != 0:
					log.fatal("Could not find 'pygettext'. Strange.")
					log.fatal("It should be included in the Python distribution.")
					sys.exit (1)

				# msgmerge
				if os.system ("msgmerge --version > /dev/null") != 0:
					log.fatal("Could not find 'msgmerge'. Please install Gettext.")
					sys.exit (1)

				# msgfmt
				if os.system ("msgfmt --version > /dev/null") != 0:
					log.fatal("Could not find 'msgfmt'. Please install Gettext.")
					sys.exit (1)

			# -----------------------------------------------------------------------

			if action == 'sdist':
				# build ChangeLog file
				log.info("building ChangeLog")
				ChangeLog.build ()

			# build translations
			if os.path.isdir ('po'):
				log.info("building translations")
				if os.system ("cd po && make gmo") != 0:
					sys.exit (1)

		else:
			# on non posix systems just run msgfmt on existing .po files
			if os.path.isdir ('po'):
				# msgfmt.py
				argv0_path = os.path.dirname(os.path.abspath(sys.executable))
				sys.path.append(argv0_path + "\\tools\\i18n")

				msgfmtOK = 0
				try:
					import msgfmt
					msgfmtOK = 1
				except:
					pass

				if msgfmtOK == 1:
					# pygettext.py exist in Python, but no msgmerge, so
					# just create a placeholder...
					potfile = open('po/'+ self.package +'.pot', 'w')
					potfile.write("#placeholder")
					potfile.close()

					# build translations
					log.info("building translations")
					for f in os.listdir('po'):
						if f[-3:] == '.po':
							msgfmt.make ('po/'+f, 'po/'+f[:-3]+'.gmo')
							msgfmt.MESSAGES = {}

		# -------------------------------------------------------------------------

		# do package specific stuff
		self.build_files (action)
Exemplo n.º 45
0
    def run(self):
        # base run
        _build.run(self)

        # custom run
        log.info('Now building cppyy_backend')
        builddir = get_builddir()
        prefix = get_prefix()
        srcdir = get_srcdir()
        if not os.path.exists(srcdir):
            log.info(
                'No src directory ... creating with "python create_src_directory.py"'
            )
            if subprocess.call(['python', 'create_src_directory.py']) != 0:
                log.error('ERROR: the source directory "%s" does not exist' %
                          srcdir)
                log.error('Please run "python create_src_directory.py" first.')
                sys.exit(1)

        if not os.path.exists(builddir):
            log.info('Creating build directory %s ...' % builddir)
            os.makedirs(builddir)

        # get C++ standard to use, if set
        try:
            stdcxx = os.environ['STDCXX']
        except KeyError:
            stdcxx = '14'

        if not stdcxx in ['11', '14', '17']:
            log.fatal('FATAL: envar STDCXX should be one of 11, 14, or 17')
            sys.exit(1)

        stdcxx = '-Dcxx' + stdcxx + '=ON'

        log.info('Running cmake for cppyy_backend')
        if subprocess.call([
                'cmake', srcdir, stdcxx, '-Dminimal=ON', '-Dasimage=OFF',
                '-Droot7=OFF', '-Dhttp=OFF', '-Dbuiltin_freetype=OFF',
                '-DCMAKE_BUILD_TYPE=RelWithDebInfo',
                '-DCMAKE_INSTALL_PREFIX=' + prefix
        ],
                           cwd=builddir) != 0:
            raise DistutilsSetupError('Failed to configure cppyy_backend')

        # default to using all available cores (x2 if hyperthreading enabled)
        nprocs = os.getenv("MAKE_NPROCS") or '0'
        try:
            nprocs = int(nprocs)
        except ValueError:
            log.warn("Integer expected for MAKE_NPROCS, but got %s (ignored)",
                     nprocs)
            nprocs = 0
        if nprocs < 1:
            nprocs = multiprocessing.cpu_count()
        build_args = ['--build', '.', '--config', 'RelWithDebInfo', '--']
        if 'win32' in sys.platform:
            build_args.append('/maxcpucount:' + str(nprocs))
        else:
            build_args.append('-j' + str(nprocs))
        log.info('Now building cppyy_backend and dependencies ...')
        if subprocess.call(['cmake'] + build_args, cwd=builddir) != 0:
            raise DistutilsSetupError('Failed to build cppyy_backend')

        log.info('Build finished')
Exemplo n.º 46
0
    # Get GDAL API version from environment variable.
    if 'GDAL_VERSION' in os.environ:
        gdalversion = os.environ['GDAL_VERSION']
        log.info("GDAL API version obtained from environment: %s", gdalversion)

    # Get GDAL API version from the command line if specified there.
    if '--gdalversion' in sys.argv:
        index = sys.argv.index('--gdalversion')
        sys.argv.pop(index)
        gdalversion = sys.argv.pop(index)
        log.info("GDAL API version obtained from command line option: %s",
                 gdalversion)

    if not gdalversion:
        log.fatal("A GDAL API version must be specified. Provide a path "
                  "to gdal-config using a GDAL_CONFIG environment variable "
                  "or use a GDAL_VERSION environment variable.")
        sys.exit(1)

    if os.environ.get('PACKAGE_DATA'):
        destdir = 'fiona/gdal_data'
        if gdal_output[2]:
            log.info("Copying gdal data from %s" % gdal_output[2])
            copy_data_tree(gdal_output[2], destdir)
        else:
            # check to see if GDAL_DATA is defined
            gdal_data = os.environ.get('GDAL_DATA', None)
            if gdal_data:
                log.info("Copying gdal data from %s" % gdal_data)
                copy_data_tree(gdal_data, destdir)