Example #1
0
def get_app_dir():
    """Get the configured JupyterLab app directory.
    """
    # Default to the override environment variable.
    if os.environ.get('JUPYTERLAB_DIR'):
        return osp.realpath(os.environ['JUPYTERLAB_DIR'])

    # Use the default locations for data_files.
    app_dir = pjoin(sys.prefix, 'share', 'jupyter', 'lab')

    # Check for a user level install.
    # Ensure that USER_BASE is defined
    if hasattr(site, 'getuserbase'):
        site.getuserbase()
    userbase = getattr(site, 'USER_BASE', None)
    if HERE.startswith(userbase) and not app_dir.startswith(userbase):
        app_dir = pjoin(userbase, 'share', 'jupyter', 'lab')

    # Check for a system install in '/usr/local/share'.
    elif (sys.prefix.startswith('/usr') and not
          osp.exists(app_dir) and
          osp.exists('/usr/local/share/jupyter/lab')):
        app_dir = '/usr/local/share/jupyter/lab'

    return osp.realpath(app_dir)
Example #2
0
    def _make_bin(self, venv_path: Path) -> Path:
        if self.location:
            bin_path = self._path / "bin"
        else:
            userbase = Path(site.getuserbase())
            bin_path = userbase / ("Scripts" if WINDOWS else "bin")

        _echo(
            "Installing {} ({}): {} {}".format(
                colored("green", "PDM", bold=True),
                colored("yellow", self.version),
                colored("cyan", "Making binary at"),
                colored("green", str(bin_path)),
            )
        )
        bin_path.mkdir(parents=True, exist_ok=True)
        if WINDOWS:
            script = bin_path / "pdm.exe"
            target = venv_path / "Scripts" / "pdm.exe"
        else:
            script = bin_path / "pdm"
            target = venv_path / "bin" / "pdm"

        if script.exists():
            script.unlink()
        try:
            script.symlink_to(target)
        except OSError:
            shutil.copy(target, script)
        return bin_path
Example #3
0
def printConf():
    print('--------- sys path --------------')
    for elt in sys.path:
        print('_____elt in sys path_____')
        print(elt)
        print('_____________________end elt')
    print('----- end sys.pach --------')
    print('--------site_config_dir-------------')
    print(site_config_dir)
    print('site_config_dir')
    print('************************')    
    print('--------site_config_dirs-------------')
    print(site_config_dirs)
    print('site_config_dirs')
    print('************************')  
    print('--------site_data_dir-------------')
    print(site_data_dir)
    print('---------site_data_dir')
    print('************************')
    print('--------site.getusersitepackages------------')
    print(site.getusersitepackages())
    print('site.getusersitepackages')
    print('************site.getusersitepackages************')
    print('************************')
    print('--------site.getuserbase-----------')
    print(site.getuserbase())
    print('')
    print('************site.getuserbase************')
Example #4
0
def issue_queries(graph, timeout):
    os.environ["PATH"] = os.pathsep.join(
        [ENV['PATH'], site.getuserbase() + '/bin'])
    os.environ["PYTHONPATH"] = os.pathsep.join(
        [ENV['PYTHONPATH'], HERE + "/generator"])
    cmd = [
        "grammarinator-generate",
        "CustomCypherGenerator.CustomCypherGenerator", "--sys-path",
        "generator/", "--jobs", "1", "-r", "oC_Query", "--stdout", "-d", "30"
    ]

    start = time()
    while time() - start < timeout:
        # Capture generated queries
        try:
            query = subprocess.check_output(cmd, encoding="utf8")
        except subprocess.CalledProcessError as e:
            # Subprocess failed, emit the thrown exception and retry
            print(str(e))
            continue

        # Log query to console
        print(query)
        try:
            graph.query(query, timeout=1000)
        except ResponseError as e:
            print("Encountered exception: %s" % str(e))
        except ConnectionError as e:
            # The previous query crashed the server, exit with exception
            raise (e)
Example #5
0
def test_create_site_dir():
    site_utils.create_site_dir("test")
    tdir = os.path.join(site.getuserbase(), "test")
    #print "tdir: %s" % str(tdir)
    assert os.path.exists(tdir)
    site_utils._remove_site_dir("test")
    assert not site_utils.site_dir_exists("test")
Example #6
0
def get_pipx_user_bin_path() -> Optional[Path]:
    """Returns None if pipx is not installed using `pip --user`
    Otherwise returns parent dir of pipx binary
    """
    # NOTE: using this method to detect pip user-installed pipx will return
    #   None if pipx was installed as editable using `pip install --user -e`

    # https://docs.python.org/3/install/index.html#inst-alt-install-user
    #   Linux + Mac:
    #       scripts in <userbase>/bin
    #   Windows:
    #       scripts in <userbase>/Python<XY>/Scripts
    #       modules in <userbase>/Python<XY>/site-packages

    pipx_bin_path = None

    script_path = Path(__file__).resolve()
    userbase_path = Path(site.getuserbase()).resolve()
    try:
        _ = script_path.relative_to(userbase_path)
    except ValueError:
        pip_user_installed = False
    else:
        pip_user_installed = True
    if pip_user_installed:
        test_paths = (
            userbase_path / "bin" / "pipx",
            Path(site.getusersitepackages()).resolve().parent / "Scripts" / "pipx.exe",
        )
        for test_path in test_paths:
            if test_path.exists():
                pipx_bin_path = test_path.parent
                break

    return pipx_bin_path
Example #7
0
def excenturyrc_str():
    """Create the excenturyrc file contents. """
    userbase = site.getuserbase()
    content = append_variable('PATH', '%s/bin' % sys.prefix)
    content += append_variable('PATH', '%s/bin' % userbase)
    # include
    path = pth.abspath(pth.dirname(__file__)+'/../extern/include')
    content += append_variable('C_INCLUDE_PATH', path)
    content += append_variable('CPLUS_INCLUDE_PATH', path)
    # matlab
    path = pth.abspath(pth.dirname(__file__)+'/../extern/matlab')
    content += append_variable('MATLABPATH', path)
    # excentury/bin
    content += append_variable('PATH',
                               '%s/lib/excentury/bin' % userbase)
    # excentury/lib
    content += append_variable('LD_LIBRARY_PATH',
                               '%s/lib/excentury/lib' % userbase)
    # excentury/matlab
    content += append_variable('MATLABPATH',
                               '%s/lib/excentury/matlab' % userbase)
    # excentury/python
    content += append_variable('PYTHONPATH',
                               '%s/lib/excentury/python' % userbase)
    return content
Example #8
0
    def test_no_home_directory(self):
        # bpo-10496: getuserbase() and getusersitepackages() must not fail if
        # the current user has no home directory (if expanduser() returns the
        # path unchanged).
        site.USER_SITE = None
        site.USER_BASE = None

        with EnvironmentVarGuard() as environ, \
             mock.patch('os.path.expanduser', lambda path: path):

            del environ['PYTHONUSERBASE']
            del environ['APPDATA']

            user_base = site.getuserbase()
            self.assertTrue(user_base.startswith('~' + os.sep),
                            user_base)

            user_site = site.getusersitepackages()
            self.assertTrue(user_site.startswith(user_base), user_site)

        with mock.patch('os.path.isdir', return_value=False) as mock_isdir, \
             mock.patch.object(site, 'addsitedir') as mock_addsitedir, \
             support.swap_attr(site, 'ENABLE_USER_SITE', True):

            # addusersitepackages() must not add user_site to sys.path
            # if it is not an existing directory
            known_paths = set()
            site.addusersitepackages(known_paths)

            mock_isdir.assert_called_once_with(user_site)
            mock_addsitedir.assert_not_called()
            self.assertFalse(known_paths)
Example #9
0
def get_install_paths(
        installer,
        install, # = self.distribution.command_options.get('install', {}),
):
    if 'user' in install:
        # this means --user was given
        installer.prefix = site.getuserbase()
        sysconfigdir = os.path.join(installer.prefix, 'etc')
        sharedir = os.path.join(installer.prefix, "share")
    elif 'prefix' in install:
        # this means --prefix was given
        installer.prefix = install.get('prefix', (None, None))[1]
        sysconfigdir = os.path.join(installer.prefix, 'etc')
        if sys.platform == "win32":
            pass
        else:
            if installer.prefix == "/usr":
                sysconfigdir = "/etc"
        sharedir = os.path.join(installer.prefix, "share")
    else:
        if sys.platform == "win32":
            sysconfigdir = 'C:\\ProgramData'
            installer.prefix = 'C:\\Program Files\\'
            sharedir = os.path.join(installer.prefix, "share")
        else:
            # these have to be absolute, otherwise they will be prefixed again
            sysconfigdir = "/etc"
            sharedir = os.path.join("/usr", "share")
            installer.prefix = '/usr'

    return sysconfigdir, sharedir
Example #10
0
 def run(self):
     # Workaround that install_data doesn't respect --prefix
     #
     # If prefix is given (via --user or via --prefix), then
     # extract it and add it to the paths in self.data_files;
     # otherwise, default to /usr/local.
     install = self.distribution.command_options.get('install', {})
     if 'user' in install:
         # this means --user was given
         self.prefix = site.getuserbase()
         sysconfigdir = os.path.join(self.prefix, "etc")
     elif 'prefix' in install:
         # this means --prefix was given
         self.prefix = install.get('prefix', (None, None))[1]
         sysconfigdir = os.path.join(self.prefix, 'etc')
     else:
         self.prefix = 'usr'
         sysconfigdir = '/etc'
     new_data_files = []
     for entry in self.data_files:
         dest_path = entry[0].replace('@prefix@', self.prefix)
         dest_path = entry[0].replace('@sysconfigdir@', sysconfigdir)
         new_data_files.append((dest_path,) + entry[1:])
     self.data_files = new_data_files
     distutils.command.install_data.install_data.run(self)
Example #11
0
def test_create_site_dir():
    site_utils.create_site_dir("test")
    tdir = os.path.join(site.getuserbase(), "test")
    #print "tdir: %s" % str(tdir)
    assert os.path.exists(tdir)
    site_utils._remove_site_dir("test")
    assert not site_utils.site_dir_exists("test")
Example #12
0
    def test_getuserbase(self):
        site.USER_BASE = None
        user_base = site.getuserbase()

        # the call sets site.USER_BASE
        self.assertEqual(site.USER_BASE, user_base)

        # let's set PYTHONUSERBASE and see if it uses it
        site.USER_BASE = None
        import sysconfig
        sysconfig._CONFIG_VARS = None

        with EnvironmentVarGuard() as environ:
            environ['PYTHONUSERBASE'] = 'xoxo'
            self.assertTrue(site.getuserbase().startswith('xoxo'),
                            site.getuserbase())
Example #13
0
    def test_no_home_directory(self):
        # bpo-10496: getuserbase() and getusersitepackages() must not fail if
        # the current user has no home directory (if expanduser() returns the
        # path unchanged).
        site.USER_SITE = None
        site.USER_BASE = None

        with EnvironmentVarGuard() as environ, \
             mock.patch('os.path.expanduser', lambda path: path):

            del environ['PYTHONUSERBASE']
            del environ['APPDATA']

            user_base = site.getuserbase()
            self.assertTrue(user_base.startswith('~' + os.sep),
                            user_base)

            user_site = site.getusersitepackages()
            self.assertTrue(user_site.startswith(user_base), user_site)

        with mock.patch('os.path.isdir', return_value=False) as mock_isdir, \
             mock.patch.object(site, 'addsitedir') as mock_addsitedir, \
             support.swap_attr(site, 'ENABLE_USER_SITE', True):

            # addusersitepackages() must not add user_site to sys.path
            # if it is not an existing directory
            known_paths = set()
            site.addusersitepackages(known_paths)

            mock_isdir.assert_called_once_with(user_site)
            mock_addsitedir.assert_not_called()
            self.assertFalse(known_paths)
Example #14
0
    def uninstall(self) -> None:
        _echo(
            "Uninstalling {}: {}".format(
                colored("green", "PDM", bold=True),
                colored("cyan", "Removing venv and script"),
            )
        )
        if self.location:
            bin_path = self._path / "bin"
        else:
            userbase = Path(site.getuserbase())
            bin_path = userbase / ("Scripts" if WINDOWS else "bin")

        if WINDOWS:
            script = bin_path / "pdm.exe"
        else:
            script = bin_path / "pdm"

        shutil.rmtree(self._path / "venv")
        script.unlink()

        if WINDOWS:
            _remove_path_windows(bin_path)

        print()
        _echo("Successfully uninstalled")
Example #15
0
    def test_getuserbase(self):
        site.USER_BASE = None
        user_base = site.getuserbase()

        # the call sets site.USER_BASE
        self.assertEqual(site.USER_BASE, user_base)

        # let's set PYTHONUSERBASE and see if it uses it
        site.USER_BASE = None
        import sysconfig
        sysconfig._CONFIG_VARS = None

        with EnvironmentVarGuard() as environ:
            environ['PYTHONUSERBASE'] = 'xoxo'
            self.assertTrue(site.getuserbase().startswith('xoxo'),
                            site.getuserbase())
Example #16
0
def jupyter_path(*subdirs):
    """Return a list of directories to search for data files

    JUPYTER_PATH environment variable has highest priority.

    If the JUPYTER_PREFER_ENV_PATH environment variable is set, the environment-level
    directories will have priority over user-level directories.

    If the Python site.ENABLE_USER_SITE variable is True, we also add the
    appropriate Python user site subdirectory to the user-level directories.


    If ``*subdirs`` are given, that subdirectory will be added to each element.

    Examples:

    >>> jupyter_path()
    ['~/.local/jupyter', '/usr/local/share/jupyter']
    >>> jupyter_path('kernels')
    ['~/.local/jupyter/kernels', '/usr/local/share/jupyter/kernels']
    """

    paths = []

    # highest priority is explicit environment variable
    if os.environ.get('JUPYTER_PATH'):
        paths.extend(
            p.rstrip(os.sep)
            for p in os.environ['JUPYTER_PATH'].split(os.pathsep))

    # Next is environment or user, depending on the JUPYTER_PREFER_ENV_PATH flag
    user = [jupyter_data_dir()]
    if site.ENABLE_USER_SITE:
        # Check if site.getuserbase() exists to be compatible with virtualenv,
        # which often does not have this method.
        if hasattr(site, 'getuserbase'):
            userbase = site.getuserbase()
        else:
            userbase = site.USER_BASE
        userdir = os.path.join(userbase, 'share', 'jupyter')
        if userdir not in user:
            user.append(userdir)

    env = [p for p in ENV_JUPYTER_PATH if p not in SYSTEM_JUPYTER_PATH]

    if envset('JUPYTER_PREFER_ENV_PATH'):
        paths.extend(env)
        paths.extend(user)
    else:
        paths.extend(user)
        paths.extend(env)

    # finally, system
    paths.extend(SYSTEM_JUPYTER_PATH)

    # add subdir, if requested
    if subdirs:
        paths = [pjoin(p, *subdirs) for p in paths]
    return paths
Example #17
0
def _find_install_path():
    if "--user" in sys.argv:
        inst = site.getusersitepackages()
        prefix = site.getuserbase()
    else:
        inst = site.getsitepackages()[0]
        prefix = sys.prefix
    return inst, prefix
Example #18
0
def _prefix_regex() -> typing.List[str]:
    raw_paths = (site.getsitepackages() + sys.path + [site.getuserbase()] +
                 [site.getusersitepackages()] +
                 [os.path.dirname(os.path.dirname(torch.__file__))])

    path_prefixes = sorted({os.path.abspath(i) for i in raw_paths})
    assert all(isinstance(i, str) for i in path_prefixes)
    return [i + os.sep for i in path_prefixes]
Example #19
0
    def test_getusersitepackages(self):
        site.USER_SITE = None
        site.USER_BASE = None
        user_site = site.getusersitepackages()

        # the call sets USER_BASE *and* USER_SITE
        self.assertEqual(site.USER_SITE, user_site)
        self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
        self.assertEqual(site.USER_BASE, site.getuserbase())
Example #20
0
def find_script(name):
    user_base = site.getuserbase()
    script_path = find_subdirectory("bin", user_base)
    if script_path is None:
        script_path = find_subdirectory("Scripts", user_base)
    script_path = os.path.join(script_path, name)
    if os.path.isfile(script_path):
        return script_path
    return None
Example #21
0
def get_install_prefix():
    #special case for "user" installations, ie:
    #$HOME/.local/lib/python2.7/site-packages/xpra/platform/paths.py
    try:
        base = site.getuserbase()
    except:
        base = site.USER_BASE
    if __file__.startswith(base):
        return base
    return sys.prefix
Example #22
0
File: paths.py Project: ljmljz/xpra
def do_get_install_prefix():
    #special case for "user" installations, ie:
    #$HOME/.local/lib/python2.7/site-packages/xpra/platform/paths.py
    try:
        base = site.getuserbase()
    except:
        base = site.USER_BASE
    if __file__.startswith(base):
        return base
    return sys.prefix
Example #23
0
def get_credentials():
    global store
    credential_path = site.getuserbase() + os.sep + 'credentials.json'
    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        print("Credentials not found. Calling oauth2callback().")
        return oauth2callback()
    else:
        print("Credentials fetched successfully.")
        return credentials
Example #24
0
def build_cpp(name, debug=None):
    """Compile a file and place it in bin. """
    root = site.getuserbase()
    if debug is None:
        out = "-o %s/lib/excentury/bin/%s.run" % (root, name)
    else:
        out = "-DDEBUG=%s -o %s/lib/excentury/bin/%s.run%s" % (debug, root, name, debug)
    root = pth.abspath(pth.dirname(__file__) + "/cpp")
    cmd = "g++ -O3 %s %s/%s.cpp" % (out, root, name)
    out, err, _ = exec_cmd(cmd)
    eq_(err, "", "Build Error -->\n%s\n%s" % (cmd, err))
Example #25
0
def get_app_dir(app_dir=None):
    """Get the configured JupyterLab app directory.
    """
    # Default to the override environment variable.
    app_dir = app_dir or os.environ.get('JUPYTERLAB_DIR')
    if app_dir:
        return os.path.realpath(app_dir)

    # Use the default locations for data_files.
    app_dir = pjoin(sys.prefix, 'share', 'jupyter', 'lab')

    # Check for a user level install.
    if hasattr(site, 'getuserbase') and here.startswith(site.getuserbase()):
        app_dir = pjoin(site.getuserbase(), 'share', 'jupyter', 'lab')

    # Check for a system install in '/usr/local/share'.
    elif (sys.prefix.startswith('/usr') and not os.path.exists(app_dir)
          and os.path.exists('/usr/local/share/jupyter/lab')):
        app_dir = '/usr/local/share/jupyter/lab'

    return os.path.realpath(app_dir)
Example #26
0
 def find_db(self):
     name = "library.sqlite"
     dir = os.path.join(site.getuserbase(), "rayopt")
     main = os.path.join(dir, name)
     if not os.path.exists(main):
         base = resource_filename(Requirement.parse("rayopt"), name)
         if not os.path.exists(base):
             base = os.path.join(os.path.split(__file__)[0], name)
         if not os.path.exists(dir):
             os.makedirs(dir)
         shutil.copy(base, main)
     return main
Example #27
0
 def find_db(self):
     name = "library.sqlite"
     dir = os.path.join(site.getuserbase(), "rayopt")
     main = os.path.join(dir, name)
     if not os.path.exists(main):
         base = resource_filename(Requirement.parse("rayopt"), name)
         if not os.path.exists(base):
             base = os.path.join(os.path.split(__file__)[0], name)
         if not os.path.exists(dir):
             os.makedirs(dir)
         shutil.copy(base, main)
     return main
def test_jupyter_path_user_site():
    with no_config_env, patch.object(site, 'ENABLE_USER_SITE', True):
        path = jupyter_path()

    # deduplicated expected values
    values = list(dict.fromkeys([
        jupyter_data_dir(),
        os.path.join(site.getuserbase(), 'share', 'jupyter'),
        paths.ENV_JUPYTER_PATH[0]
    ]))
    for p,v in zip(path, values):
        assert p == v
Example #29
0
def make_dirs():
    """Creates standard directories to place binaries and libraries
    created by excentury. """
    root = site.getuserbase()
    make_dir(root+'/lib')
    make_dir(root+'/lib/excentury')
    make_dir(root+'/lib/excentury/bin')
    make_dir(root+'/lib/excentury/lib')
    make_dir(root+'/lib/excentury/cpp')
    make_dir(root+'/lib/excentury/matlab')
    make_dir(root+'/lib/excentury/python')
    make_dir(root+'/lib/excentury/tmp')
def test_jupyter_config_path_prefer_env():
    with prefer_env, patch.object(site, 'ENABLE_USER_SITE', True):
        path = jupyter_config_path()

    # deduplicated expected values
    values = list(dict.fromkeys([
        paths.ENV_CONFIG_PATH[0],
        jupyter_config_dir(),
        os.path.join(site.getuserbase(), 'etc', 'jupyter')
    ]))
    for p,v in zip(path, values):
        assert p == v
Example #31
0
def install_base_kernel(kernel_name: str):
    data_relative_path = 'share/jupyter/kernels/kotlin'
    user_location = path.join(site.getuserbase(), data_relative_path)
    sys_location = path.join(sys.prefix, data_relative_path)
    src_paths = [user_location, sys_location]

    user_jupyter_path = get_user_jupyter_path()

    dst = path.join(user_jupyter_path, 'kernels/' + kernel_name)
    for src in src_paths:
        if not path.exists(src):
            continue
        shutil.copytree(src, dst, dirs_exist_ok=True)
Example #32
0
def get_exe_dirs():
    result = []
    if site.ENABLE_USER_SITE:
        if platform.system() == "Windows":
            if site.getusersitepackages():
                result.append(site.getusersitepackages().replace(
                    "site-packages", "Scripts"))
        else:
            if site.getuserbase():
                result.append(site.getuserbase() + "/bin")

    main_scripts = os.path.join(sys.prefix, "Scripts")
    if os.path.isdir(main_scripts) and main_scripts not in result:
        result.append(main_scripts)

    if os.path.dirname(sys.executable) not in result:
        result.append(os.path.dirname(sys.executable))

    # These entries are used by Anaconda
    for part in [
            "Library/mingw-w64/bin",
            "Library/usr/bin",
            "Library/bin",
            "Scripts",
            "bin",
            "condabin",
    ]:
        dirpath = os.path.join(sys.prefix, part.replace("/", os.sep))
        if os.path.isdir(dirpath) and dirpath not in result:
            result.append(dirpath)

    if platform.system() != "Windows" and "/usr/local/bin" not in result:
        # May be missing on macOS, when started as bundle
        # (yes, more may be missing, but this one is most useful)
        result.append("/usr/local/bin")

    return result
Example #33
0
def jupyter_config_path():
    """Return the search path for Jupyter config files as a list.

    If the JUPYTER_PREFER_ENV_PATH environment variable is set, the
    environment-level directories will have priority over user-level
    directories.

    If the Python site.ENABLE_USER_SITE variable is True, we also add the
    appropriate Python user site subdirectory to the user-level directories.
    """
    if os.environ.get('JUPYTER_NO_CONFIG'):
        # jupyter_config_dir makes a blank config when JUPYTER_NO_CONFIG is set.
        return [jupyter_config_dir()]

    paths = []

    # highest priority is explicit environment variable
    if os.environ.get('JUPYTER_CONFIG_PATH'):
        paths.extend(
            p.rstrip(os.sep)
            for p in os.environ['JUPYTER_CONFIG_PATH'].split(os.pathsep))

    # Next is environment or user, depending on the JUPYTER_PREFER_ENV_PATH flag
    user = [jupyter_config_dir()]
    if site.ENABLE_USER_SITE:
        # Check if site.getuserbase() exists to be compatible with virtualenv,
        # which often does not have this method.
        if hasattr(site, 'getuserbase'):
            userbase = site.getuserbase()
        else:
            userbase = site.USER_BASE

        userdir = os.path.join(userbase, 'etc', 'jupyter')
        if userdir not in user:
            user.append(userdir)

    env = [p for p in ENV_CONFIG_PATH if p not in SYSTEM_CONFIG_PATH]

    if envset('JUPYTER_PREFER_ENV_PATH'):
        paths.extend(env)
        paths.extend(user)
    else:
        paths.extend(user)
        paths.extend(env)

    # Finally, system path
    paths.extend(SYSTEM_CONFIG_PATH)
    return paths
Example #34
0
def load(graph):
    """Load the Trip Advisor dataset to a given graph object.

    The graph object must implement the
    :ref:`graph interface <dataset-io:graph-interface>`.

    Args:
      graph: an instance of bipartite graph.

    Returns:
      The graph instance *graph*.
    """
    base = "TripAdvisorJson.tar.bz2"
    path = join(".", base)
    if not exists(path):
        path = join(sys.prefix, "rgmining", "data", base)
    if not exists(path):
        path = join(sys.prefix, "local", "rgmining", "data", base)
    if not exists(path):
        path = join(site.getuserbase(), "rgmining", "data", base)

    R = {}  # Reviewers dict.
    with tarfile.open(path) as tar:

        for info in _files(tar):

            with closing(tar.extractfile(info)) as fp:

                obj = json.load(fp)

                target = obj["HotelInfo"]["HotelID"]
                product = graph.new_product(name=target)

                for r in obj["Reviews"]:
                    name = r["ReviewID"]
                    score = float(r["Ratings"]["Overall"]) / 5.

                    try:
                        date = datetime.datetime.strptime(
                            r["Date"], _DATE_FORMAT).strftime("%Y%m%d")
                    except ValueError:
                        date = None

                    if name not in R:
                        R[name] = graph.new_reviewer(name=name)
                    graph.add_review(R[name], product, score, date)

    return graph
Example #35
0
File: setup.py Project: FEniCS/ffc
def get_installation_prefix():
    "Get installation prefix"
    prefix = sys.prefix
    for arg in sys.argv[1:]:
        if "--user" in arg:
            import site
            prefix = site.getuserbase()
            break
        elif arg in ("--prefix", "--home", "--install-base"):
            prefix = sys.argv[sys.argv.index(arg) + 1]
            break
        elif "--prefix=" in arg or "--home=" in arg or "--install-base=" in arg:
            prefix = arg.split("=")[1]
            break

    return os.path.abspath(os.path.expanduser(prefix))
Example #36
0
def __get_scripts_directory():
    import sys
    import platform
    import site

    """Return directory where W3D scripts have been installed

    :warn: This assumes a default installation with user scheme

    :todo: Add fallbacks for alternate installations"""

    if platform.system() in ("Windows",):
        scripts_dir = os.path.join("Python{}{}".format(*(sys.version_info[:2])), "Scripts")
    else:
        scripts_dir = "bin"
    scripts_dir = os.path.join(site.getuserbase(), scripts_dir)
    return scripts_dir
Example #37
0
def run():
    """Run the command. """
    arg = config.CONFIG['arg']
    if arg.path:
        install_dir = arg.path
    elif arg.user:
        install_dir = '%s/lib/lexor' % site.getuserbase()
    else:
        install_dir = '%s/lib/lexor' % sys.prefix

    style_file = arg.style
    if '.py' not in style_file:
        style_file = '%s.py' % style_file
    if os.path.exists(style_file):
        install_style(style_file, install_dir)
        return

    matches = []
    url = 'http://jmlopez-rod.github.io/lexor-lang/lexor-lang.url'
    print '-> Searching in %s' % url
    response = urllib2.urlopen(url)
    for line in response.readlines():
        name, url = line.split(':', 1)
        if arg.style in name:
            matches.append([name.strip(), url.strip()])

    for match in matches:
        doc = urllib2.urlopen(match[1]).read()
        links = re.finditer(r' href="?([^\s^"]+)', doc)
        links = [link.group(1) for link in links if '.zip' in link.group(1)]
        for link in links:
            if 'master' in link:
                path = urllib2.urlparse.urlsplit(match[1])
                style_url = '%s://%s%s' % (path[0], path[1], link)
                local_name = download_file(style_url, '.')
                dirname = unzip_file(local_name)
                # Assuming there is only one python file
                os.chdir(dirname)
                for path in iglob('*.py'):
                    install_style(path, install_dir)
                os.chdir('..')
                os.remove(local_name)
                shutil.rmtree(dirname)
Example #38
0
def loadlib(**libname):
  '''
  Find and load a dynamic library using :any:`ctypes.CDLL`.  For each
  (supported) platform the name of the library should be specified as a keyword
  argument, including the extension, where the keywords should match the
  possible values of :any:`sys.platform`.  In addition to the default
  directories, this function searches :any:`site.PREFIXES` and
  :func:`site.getuserbase()`.

  Example
  -------

  To load the Intel MKL runtime library, write::

      loadlib(linux='libmkl_rt.so', darwin='libmkl_rt.dylib', win32='mkl_rt.dll')
  '''

  if sys.platform not in libname:
    return
  libname = libname[sys.platform]
  try:
    return ctypes.CDLL(libname)
  except (OSError, KeyError):
    pass
  libsubdir = dict(linux='lib', darwin='lib', win32='Library\\bin')[sys.platform]
  prefixes = list(site.PREFIXES)
  if hasattr(site, 'getuserbase'):
    prefixes.append(site.getuserbase())
  for prefix in prefixes:
    libdir = os.path.join(prefix, libsubdir)
    if not os.path.exists(os.path.join(libdir, libname)):
      continue
    if sys.platform == 'win32' and libdir not in os.environ.get('PATH', '').split(';'):
      # Make sure dependencies of `libname` residing in the same directory are
      # found.
      os.environ['PATH'] = os.environ.get('PATH', '').rstrip(';')+';'+libdir
    try:
      return ctypes.CDLL(os.path.join(libdir, libname))
    except (OSError, KeyError):
      pass
Example #39
0
def development_deploy(paths, dependencies=False, scripts=False, inject_setuptools=False):
    """Python packages deployment in development mode."""
    items = list(paths) if isinstance(paths, (list, tuple, set)) else [paths]

    if items:
        original_path = os.getcwd()
        user_base_path = getuserbase()
        user_sites_path = getusersitepackages()
        user_bin_path = os.path.join(user_base_path, 'bin')

        for path in items:
            os.chdir(os.path.dirname(path))

            # Making arguments
            arguments = [path, 'develop']
            arguments.extend(['--install-dir', user_sites_path])
            arguments.extend(['--script-dir', user_bin_path])
            if not dependencies:
                arguments.append('--no-deps')
            if not scripts:
                arguments.append('--exclude-scripts')

            # Processing
            if not inject_setuptools:
                subprocess.Popen([sys.executable] + arguments).wait()
            else:
                handler = open(path, 'rb')
                content = handler.read()
                handler.close()
                # Adding setuptools import
                content = "import setuptools\n" + content
                # Updating arguments, path and executing
                sys.path.insert(0, '.')
                sys.argv = arguments
                exec(content, {'__file__': path})
                sys.path[:] = sys.path[1:]

        # Go back to original path
        os.chdir(original_path)
Example #40
0
def site_dir_exists(dirname):
    udir = os.path.join(site.getuserbase(), dirname)
    return os.path.exists(udir)
Example #41
0
def get_site_base():
    return site.getuserbase()
Example #42
0
def _remove_site_dir(dirname):
    udir = os.path.join(site.getuserbase(), dirname)
    if site_dir_exists(udir):
        #print "Removing dirs..."
        shutil.rmtree(udir)
Example #43
0
def create_site_dir(dirname):
    udir = os.path.join(site.getuserbase(), dirname)
    if not site_dir_exists(dirname):
        os.makedirs(udir)
Example #44
0
def system_check():
    """
    Setting and assigning shared data paths and checking 
    the configuration folder  
    """
    copyerr = False
    existfileconf = True # il file conf esiste (True) o non esiste (False)
    
    # What is the OS ??
    OS = platform.system()

    if os.path.isdir('%s/art' % PWD):
        #launch without installing on any OS or .exe and .app
        localepath = 'locale'
        path_srcShare = '%s/share' % PWD
        IS_LOCAL = True
        
    else: # Path system installation (usr, usr/local, ~/.local, \python27\)
        if OS == 'Windows':
            #Installed with 'pip install videomass' command
            pythonpath = os.path.dirname(sys.executable)
            localepath = pythonpath + '\\share\\locale'
            path_srcShare = pythonpath + '\\share\\videomass\\config'
            IS_LOCAL = False
            
        else:
            binarypath = shutil.which('videomass')
            if binarypath == '/usr/local/bin/videomass':
                #usually Linux,MacOs,Unix
                localepath = '/usr/local/share/locale'
                path_srcShare = '/usr/local/share/videomass/config'
                IS_LOCAL = False
            elif binarypath == '/usr/bin/videomass':
                #usually Linux
                localepath = '/usr/share/locale'
                path_srcShare = '/usr/share/videomass/config'
                IS_LOCAL = False
            else:
                #installed with 'pip install --user videomass' command
                import site
                userbase = site.getuserbase()
                localepath = userbase + '/share/locale'
                path_srcShare = userbase + '/share/videomass/config'
                IS_LOCAL = False

    #### check videomass.conf and config. folder
    if os.path.exists('%s/.videomass' % DIRNAME):#if exist folder ~/.videomass
        if os.path.isfile('%s/.videomass/videomass.conf' % DIRNAME):
            fileconf = parsing_fileconf() # fileconf data
            if fileconf == 'corrupted':
                print ('videomass.conf is corrupted! try to restore..')
                existfileconf = False
            if float(fileconf[0]) != 1.3:
                existfileconf = False
        else:
            existfileconf = False
        
        if not existfileconf:
            try:
                if OS == ('Linux') or OS == ('Darwin'):
                    shutil.copyfile('%s/videomass.conf' % path_srcShare, 
                                    '%s/.videomass/videomass.conf' % DIRNAME)
                elif OS == ('Windows'):
                    shutil.copyfile('%s/videomassWin32.conf' % path_srcShare, 
                                    '%s/.videomass/videomass.conf' % DIRNAME)
                fileconf = parsing_fileconf() # fileconf data, reread the file
            except IOError:
                copyerr = True
                fileconf = 'corrupted'
    else:
        try:
            shutil.copytree(path_srcShare,'%s/.videomass' % DIRNAME)
            if OS == ('Windows'):
                os.remove("%s/.videomass/videomass.conf" % (DIRNAME))
                os.rename("%s/.videomass/videomassWin32.conf" % (DIRNAME),
                          "%s/.videomass/videomass.conf" % (DIRNAME))
            fileconf = parsing_fileconf() # fileconf data, reread the file
        except OSError:
            copyerr = True
            fileconf = 'corrupted'
        except IOError:
            copyerr = True
            fileconf = 'corrupted'

    return (OS, path_srcShare, copyerr, IS_LOCAL, fileconf, localepath)
Example #45
0
----------------------------------------------------------------
To enable tab completion, add the following to your '~/.bashrc':

  source {0}

----------------------------------------------------------------
""".format(os.path.join(self.install_data,
                        'etc/bash_completion.d',
                        'catkin_tools-completion.bash')))

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--user', '--home', action='store_true')
parser.add_argument('--prefix', default=None)

opts, _ = parser.parse_known_args(sys.argv)
userbase = site.getuserbase() if opts.user else None
prefix = userbase or opts.prefix or sys.prefix

setup(
    name='catkin_tools',
    version='0.4.4',
    packages=find_packages(exclude=['tests*', 'docs']),
    package_data={
        'catkin_tools': [
            'notifications/resources/linux/catkin_icon.png',
            'notifications/resources/linux/catkin_icon_red.png',
            'verbs/catkin_shell_verbs.bash',
            'docs/examples',
        ] + osx_notification_resources
    },
    data_files=get_data_files(prefix),

print("JAVA_HOM  : ",javahome,'\n')

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






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

# Example to use site package

userBase    =   site.getuserbase()
absPath     =   site.abs_paths()

print("USER BASE   : ",userBase,'\n')

print("ABSOLUTE PATHS   : ",absPath,'\n')

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






# ------------------------------------------------- #
# Example to use for loop
Example #47
0
def promusrc_str():
    """Create the promusrc file contents. """
    userbase = site.getuserbase()
    content = append_variable('PATH', '%s/bin' % sys.prefix)
    content += append_variable('PATH', '%s/bin' % userbase)
    return content
Example #48
0
----------------------------------------------------------------
""".format(os.path.join(self.install_data,
                        'etc/bash_completion.d',
                        'catkin_tools-completion.bash')))

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--user', '--home', action='store_true')
parser.add_argument('--prefix', default=None)

opts, _ = parser.parse_known_args(sys.argv)
if opts.user and not (opts.prefix == None or opts.prefix == ""):
    raise Exception("error: argument --prefix: must be unspecified or empty if given with argument --user/--home")

prefix = None
if opts.user:
    prefix = site.getuserbase()
elif opts.prefix != None:
    prefix = opts.prefix
else:
    prefix = sys.prefix

setup(
    name='catkin_tools',
    version='0.4.5',
    packages=find_packages(exclude=['tests*', 'docs']),
    package_data={
        'catkin_tools': [
            'notifications/resources/linux/catkin_icon.png',
            'notifications/resources/linux/catkin_icon_red.png',
            'verbs/catkin_shell_verbs.bash',
            'docs/examples',
Example #49
0
 def __init__(self, IS_LOCAL, iconset):
     """
     The paths where the icon sets are located depend on where the program 
     is run and on which operating system.
     Each icons set is defined by the name of the folder that contains it.  
     """
     if IS_LOCAL:
         url = '%s/art/icons' % os.getcwd() # work current directory
         self.videomass_icon = "%s/videomass.png" % url
         self.wizard_icon = "%s/videomass_wizard.png" % url
         
     else:
         import sys
         import platform
         OS = platform.system()
         
         if OS == 'Windows':
             #Installed with 'pip install videomass' cmd
             pythonpath = os.path.dirname(sys.executable)
             url = pythonpath + '\\share\\videomass\\icons'
             self.videomass_icon = url + "\\videomass.png" 
             self.wizard_icon = url + "\\videomass_wizard.png"
         else:
             from videomass2.vdms_SYS.whichcraft import which
             binarypath = which('videomass')
             
             if binarypath == '/usr/local/bin/videomass':
                 #usually Linux,MacOs,Unix
                 url = '/usr/local/share/videomass/icons'
                 share = '/usr/local/share/pixmaps'
                 self.videomass_icon = share + '/videomass.png'
                 self.wizard_icon = url + '/videomass_wizard.png'
                 
             elif binarypath == '/usr/bin/videomass':
                 #usually Linux 
                 url = '/usr/share/videomass/icons'
                 share = '/usr/share/pixmaps'
                 self.videomass_icon = share + "/videomass.png"
                 self.wizard_icon = url + "/videomass_wizard.png"
                 
             else: 
                 #installed with 'pip install --user videomass' cmd
                 import site
                 userbase = site.getuserbase()
                 url = userbase + '/share/videomass/icons'
                 share = '/share/pixmaps'
                 self.videomass_icon = userbase+share + "/videomass.png"
                 self.wizard_icon = userbase+url+"/videomass_wizard.png"
                 
     # videomass sign
     if iconset == 'Videomass_Sign_Icons': # default
         self.x36 = '%s/Videomass_Sign_Icons/36x36' % url
         self.x24 = '%s/Videomass_Sign_Icons/24x24' % url
         self.x18 = '%s/Videomass_Sign_Icons/18x18' % url
     # material design black
     if iconset == 'Material_Design_Icons_black':
         self.x36 = '%s/Material_Design_Icons_black/36x36' % url
         self.x24 = '%s/Material_Design_Icons_black/24x24' % url
         self.x18 = '%s/Material_Design_Icons_black/18x18' % url
         self.icons_set()
     # material design white
     elif iconset == 'Material_Design_Icons_white':
         self.x36 = '%s/Material_Design_Icons_white/36x36' % url
         self.x24 = '%s/Material_Design_Icons_black/24x24' % url
         self.x18 = '%s/Material_Design_Icons_black/18x18' % url
         self.icons_set()
     # flat-colours
     elif iconset == 'Flat_Color_Icons':
         self.x36 = '%s/Flat_Color_Icons/36x36' % url
         self.x24 = '%s/Flat_Color_Icons/24x24' % url
         self.x18 = '%s/Flat_Color_Icons/18x18' % url
         self.icons_set()
Example #50
0
    'mdtxt': 'markdown',
    'mdtext': 'markdown',
    'text': 'markdown',
    'lex': 'lexor',
    'pyhtml': 'html',
    'pyxml': 'xml',
}
DESC = """
Show the styles available to lexor through the current configuration
file. You should run this command whenever you create a new
configuration file so that lexor may select the available languages
for you without the need to reinstall the styles.

"""
LEXOR_PATH = [
    '%s/lib/lexor' % site.getuserbase(),
    '%s/lib/lexor' % sys.prefix
]

if 'LEXORPATH' in os.environ:
    LEXOR_PATH = os.environ['LEXORPATH'].split(':') + LEXOR_PATH


def add_parser(subp, fclass):
    """Add a parser to the main subparser. """
    subp.add_parser('lang', help='see available styles',
                    formatter_class=fclass,
                    description=textwrap.dedent(DESC))


def _handle_kind(paths, cfg):
Example #51
0
import site
from excentury.command.config import get_cfg
from excentury.lang import FileParser, check_inputs, extract_name
from excentury.lang.matlab.cpp_writer import write_cpp_function
from excentury.lang.matlab.matlab_writer import write_matlab_file
from excentury.lang.matlab.matlab_writer import write_matlab_defs


DESC = """
Creates a mex executable from the xcpp file and a matlab
function wrapper that calls the executable.

"""

DEFAULTS = {
    'dir': site.getuserbase()+'/lib/excentury/cpp',
    'wrapper': site.getuserbase()+'/lib/excentury/matlab',
    'dump': 'text',
    'load': 'text',
    'cxx': 'g++',
    'cxxlib': '',
    'cxxinc': '',
    'cxxopt': '-O3',
    'mexopt': '-largeArrayDims',
    'debug': '0',
    'force': 'false',
    'epilog': '',
    'verbose': 'false',
}

#! /usr/bin/python

import site
import os
import sys
import json
import datetime

PATH_NAME = "paths.json"
BOARD_NAME = "dionysus"
SITE_NYSA = os.path.join(site.getuserbase(), "nysa")
SITE_PATH = os.path.join(SITE_NYSA, PATH_NAME)
PLATFORM_PATH = os.path.abspath(os.path.dirname(__file__))
CONFIG_PATH = os.path.join(PLATFORM_PATH, BOARD_NAME, "board", "config.json")

if __name__ == "__main__":
    f = open(CONFIG_PATH, "r")
    config_dict = json.load(f)
    f.close()

    name = config_dict["board_name"].lower()
    now = datetime.datetime.now()
    #timestamp = now.strftime("%m/%d/%Y %X")
    timestamp = now.strftime("%x %X")

    #print "board name: %s" % name
    #print "Timestamp: %s" % timestamp
    #print "Base directory: %s" % PLATFORM_PATH
    #print "Path directory: %s" % SITE_PATH

    try: