diff --git a/doc/source/conf.py b/doc/source/conf.py index 9444c4cb321..5d93f79174f 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -11,12 +11,14 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os, datetime +import datetime +import os +import sys ####### REQUIRED GALAXY INCLUDES -sys.path.append(os.path.join(os.getcwd(), '../../lib')) +sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'lib'))) ####### diff --git a/lib/galaxy/main.py b/lib/galaxy/main.py index 83e08d9076e..87ecd3f3b66 100644 --- a/lib/galaxy/main.py +++ b/lib/galaxy/main.py @@ -58,7 +58,7 @@ REQUIRES_DAEMONIZE_MESSAGE = "Attempted to use Galaxy in daemon mode, but daemon log = logging.getLogger(__name__) -GALAXY_ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +GALAXY_ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) GALAXY_LIB_DIR = os.path.join(GALAXY_ROOT_DIR, "lib") DEFAULT_INI_APP = "main" DEFAULT_INIS = ["config/galaxy.ini", "universe_wsgi.ini", "config/galaxy.ini.sample"] diff --git a/lib/galaxy_ext/metadata/set_metadata.py b/lib/galaxy_ext/metadata/set_metadata.py index 9dc2def3f93..ca069d0f8f7 100644 --- a/lib/galaxy_ext/metadata/set_metadata.py +++ b/lib/galaxy_ext/metadata/set_metadata.py @@ -11,28 +11,30 @@ set to the path of the dataset on which metadata is being set constructed automatically). """ -import logging -logging.basicConfig() -log = logging.getLogger( __name__ ) - import cPickle import json +import logging import os import sys +# insert *this* galaxy before all others on sys.path +sys.path.insert( 1, os.path.abspath( os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir ) ) ) + +from galaxy import eggs +eggs.require('SQLAlchemy') +from sqlalchemy.orm import clear_mappers + +import galaxy.model.mapping # need to load this before we unpickle, in order to setup properties assigned by the mappers +from galaxy.model.custom_types import total_size +from galaxy.util import stringify_dictionary_keys + # ensure supported version assert sys.version_info[:2] >= ( 2, 6 ) and sys.version_info[:2] <= ( 2, 7 ), 'Python version must be 2.6 or 2.7, this is: %s' % sys.version -# insert *this* galaxy before all others on sys.path -new_path = os.path.abspath( os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir ) ) -sys.path.insert( 0, new_path ) - -import galaxy.model.mapping # need to load this before we unpickle, in order to setup properties assigned by the mappers -from galaxy.model.custom_types import total_size +logging.basicConfig() +log = logging.getLogger( __name__ ) galaxy.model.Job() # this looks REAL stupid, but it is REQUIRED in order for SA to insert parameters into the classes defined by the mappers --> it appears that instantiating ANY mapper'ed class would suffice here -from galaxy.util import stringify_dictionary_keys -from sqlalchemy.orm import clear_mappers def set_meta_with_tool_provided( dataset_instance, file_dict, set_meta_kwds, datatypes_registry ): diff --git a/test/base/tool_shed_util.py b/test/base/tool_shed_util.py index 193ffbb9d91..fd7c10d8d95 100644 --- a/test/base/tool_shed_util.py +++ b/test/base/tool_shed_util.py @@ -2,14 +2,8 @@ import logging import os import sys -cwd = os.getcwd() -if cwd not in sys.path: - sys.path.append( cwd ) - -new_path = [ os.path.join( cwd, "lib" ) ] -if new_path not in sys.path: - new_path.extend( sys.path ) - sys.path = new_path +galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) +sys.path.insert(1, os.path.join(galaxy_root, 'lib')) from galaxy.util import parse_xml @@ -70,7 +64,7 @@ def parse_tool_panel_config( config, shed_tools_dict ): has_test_data = True if galaxy_test_file_dir != last_galaxy_test_file_dir: if not os.path.isabs( galaxy_test_file_dir ): - galaxy_test_file_dir = os.path.join( os.getcwd(), galaxy_test_file_dir ) + galaxy_test_file_dir = os.path.join( galaxy_root, galaxy_test_file_dir ) guid = elem.get( 'guid' ) shed_tools_dict[ guid ] = galaxy_test_file_dir last_galaxy_test_file_dir = galaxy_test_file_dir @@ -89,7 +83,7 @@ def parse_tool_panel_config( config, shed_tools_dict ): has_test_data = True if galaxy_test_file_dir != last_galaxy_test_file_dir: if not os.path.isabs( galaxy_test_file_dir ): - galaxy_test_file_dir = os.path.join( os.getcwd(), galaxy_test_file_dir ) + galaxy_test_file_dir = os.path.join( galaxy_root, galaxy_test_file_dir ) guid = section_elem.get( 'guid' ) shed_tools_dict[ guid ] = galaxy_test_file_dir last_galaxy_test_file_dir = galaxy_test_file_dir diff --git a/test/install_and_test_tool_shed_repositories/base/util.py b/test/install_and_test_tool_shed_repositories/base/util.py index a52e2537039..c70d4d606f0 100644 --- a/test/install_and_test_tool_shed_repositories/base/util.py +++ b/test/install_and_test_tool_shed_repositories/base/util.py @@ -8,13 +8,10 @@ import sys import time from datetime import datetime, timedelta -cwd = os.getcwd() -sys.path.append( cwd ) -new_path = [ os.path.join( cwd, "lib" ), - os.path.join( cwd, 'test' ), - os.path.join( cwd, 'lib', 'tool_shed', 'scripts', 'api' ) ] -new_path.extend( sys.path ) -sys.path = new_path +galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, os.path.pardir)) +sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), + os.path.join( galaxy_root, 'test' ), + os.path.join( galaxy_root, 'lib', 'tool_shed', 'scripts', 'api' ) ] from galaxy import eggs eggs.require( 'mercurial' ) @@ -455,8 +452,7 @@ def get_static_settings(): Return a dictionary of the settings necessary for a Galaxy application to be wrapped in the static middleware. This mainly consists of the file system locations of url-mapped static resources. """ - cwd = os.getcwd() - static_dir = os.path.join( cwd, 'static' ) + static_dir = os.path.join( galaxy_root, 'static' ) # TODO: these should be copied from galaxy.ini # TODO: static_enabled needed here? return dict( static_enabled=True, diff --git a/test/install_and_test_tool_shed_repositories/repositories_with_tools/functional_tests.py b/test/install_and_test_tool_shed_repositories/repositories_with_tools/functional_tests.py index c62e5bb71a8..e59af2f4452 100644 --- a/test/install_and_test_tool_shed_repositories/repositories_with_tools/functional_tests.py +++ b/test/install_and_test_tool_shed_repositories/repositories_with_tools/functional_tests.py @@ -16,15 +16,11 @@ import tempfile import threading import time -# Assume we are run from the galaxy root directory, add lib to the python path -cwd = os.getcwd() -sys.path.append( cwd ) -new_path = [ os.path.join( cwd, "scripts" ), - os.path.join( cwd, "lib" ), - os.path.join( cwd, 'test' ), - os.path.join( cwd, 'scripts', 'api' ) ] -new_path.extend( sys.path ) -sys.path = new_path +galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, os.path.pardir)) +sys.path[1:1] = [ os.path.join( galaxy_root, "scripts" ), + os.path.join( galaxy_root, "lib" ), + os.path.join( galaxy_root, 'test' ), + os.path.join( galaxy_root, 'scripts', 'api' ) ] from galaxy import eggs eggs.require( "nose" ) @@ -48,7 +44,7 @@ from galaxy.web import buildapp log = logging.getLogger( 'install_and_test_repositories_with_tools' ) assert sys.version_info[ :2 ] >= ( 2, 6 ) -test_home_directory = os.path.join( cwd, 'test', 'install_and_test_tool_shed_repositories', 'repositories_with_tools' ) +test_home_directory = os.path.join( galaxy_root, 'test', 'install_and_test_tool_shed_repositories', 'repositories_with_tools' ) # Here's the directory where everything happens. Temporary directories are created within this directory to contain # the database, new repositories, etc. diff --git a/test/install_and_test_tool_shed_repositories/tool_dependency_definitions/functional_tests.py b/test/install_and_test_tool_shed_repositories/tool_dependency_definitions/functional_tests.py index 4bcc80361d7..f5aa03974c9 100644 --- a/test/install_and_test_tool_shed_repositories/tool_dependency_definitions/functional_tests.py +++ b/test/install_and_test_tool_shed_repositories/tool_dependency_definitions/functional_tests.py @@ -15,15 +15,11 @@ import tempfile import threading import time -# Assume we are run from the galaxy root directory, add lib to the python path -cwd = os.getcwd() -sys.path.append( cwd ) -new_path = [ os.path.join( cwd, "scripts" ), - os.path.join( cwd, "lib" ), - os.path.join( cwd, 'test' ), - os.path.join( cwd, 'scripts', 'api' ) ] -new_path.extend( sys.path ) -sys.path = new_path +galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, os.path.pardir)) +sys.path[1:1] = [ os.path.join( galaxy_root, "scripts" ), + os.path.join( galaxy_root, "lib" ), + os.path.join( galaxy_root, 'test' ), + os.path.join( galaxy_root, 'scripts', 'api' ) ] from galaxy import eggs eggs.require( "Paste" ) @@ -43,7 +39,7 @@ from galaxy.web import buildapp log = logging.getLogger( 'install_and_test_tool_dependency_definitions' ) assert sys.version_info[ :2 ] >= ( 2, 6 ) -test_home_directory = os.path.join( cwd, 'test', 'install_and_test_tool_shed_repositories', 'tool_dependency_definitions' ) +test_home_directory = os.path.join( galaxy_root, 'test', 'install_and_test_tool_shed_repositories', 'tool_dependency_definitions' ) # Here's the directory where everything happens. Temporary directories are created within this directory to contain # the database, new repositories, etc. diff --git a/test/manual/workflows_scaling.py b/test/manual/workflows_scaling.py index 51d946ce3bd..e71e45605c3 100644 --- a/test/manual/workflows_scaling.py +++ b/test/manual/workflows_scaling.py @@ -6,20 +6,14 @@ import sys from threading import Thread from uuid import uuid4 -script_dir = os.path.dirname(__file__) -galaxy_root = os.path.join(script_dir, os.path.pardir, os.path.pardir) -new_path = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] -new_path.extend( sys.path[1:] ) -sys.path = new_path +galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) +sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] try: from argparse import ArgumentParser except ImportError: ArgumentParser = None -from api import yaml_to_workflow -from api import helpers - try: from galaxy import eggs eggs.require("requests") @@ -29,6 +23,8 @@ except ImportError: import requests from bioblend import galaxy +from api import helpers, yaml_to_workflow + LONG_TIMEOUT = 1000000000 DESCRIPTION = "Script to exercise the workflow engine." diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 429e18c5286..a585f84b905 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -14,21 +14,18 @@ import threading import time import urllib -# Assume we are run from the galaxy root directory, add lib to the python path -cwd = os.getcwd() -tool_shed_home_directory = os.path.join( cwd, 'test', 'tool_shed' ) +galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) +tool_shed_home_directory = os.path.join( galaxy_root, 'test', 'tool_shed' ) default_tool_shed_test_file_dir = os.path.join( tool_shed_home_directory, 'test_data' ) # Here's the directory where everything happens. Temporary directories are created within this directory to contain # the hgweb.config file, the database, new repositories, etc. Since the tool shed browses repository contents via HTTP, # the full path to the temporary directroy wher eht repositories are located cannot contain invalid url characters. tool_shed_test_tmp_dir = os.path.join( tool_shed_home_directory, 'tmp' ) os.environ[ 'TOOL_SHED_TEST_TMP_DIR' ] = tool_shed_test_tmp_dir -new_path = [ os.path.join( cwd, "lib" ), os.path.join( cwd, "test" ) ] -new_path.extend( sys.path[1:] ) -sys.path = new_path +# Need to remove this directory from sys.path +sys.path[0:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] from galaxy import eggs - eggs.require( "nose" ) eggs.require( "NoseHTML" ) eggs.require( "NoseTestDiff" ) @@ -53,8 +50,8 @@ from galaxy.app import UniverseApplication as GalaxyUniverseApplication from galaxy.util import asbool from galaxy.web import buildapp as galaxybuildapp -from functional import database_contexts from base import nose_util +from functional import database_contexts log = logging.getLogger( "tool_shed_functional_tests.py" ) @@ -82,8 +79,7 @@ def get_static_settings(): This mainly consists of the filesystem locations of url-mapped static resources. """ - cwd = os.getcwd() - static_dir = os.path.join( cwd, 'static' ) + static_dir = os.path.join( galaxy_root, 'static' ) # TODO: these should be copied from galaxy.ini return dict( # TODO: static_enabled needed here? @@ -426,10 +422,6 @@ def main(): else: raise Exception( "Test HTTP server did not return '200 OK' after 10 tries" ) log.info( "Embedded galaxy web server started" ) - # We don't add the tests to the path until everything is up and running - new_path = [ os.path.join( cwd, 'test' ) ] - new_path.extend( sys.path[1:] ) - sys.path = new_path # ---- Find tests --------------------------------------------------------- if tool_shed_test_proxy_port: log.info( "Functional tests will be run against %s:%s" % ( tool_shed_test_host, tool_shed_test_proxy_port ) ) diff --git a/test/unit/unittest_utils/utility.py b/test/unit/unittest_utils/utility.py index 391f67fde5e..3341ee3879b 100644 --- a/test/unit/unittest_utils/utility.py +++ b/test/unit/unittest_utils/utility.py @@ -14,12 +14,12 @@ else: # ============================================================================= def get_unittest_utils_path(): - return os.path.normpath( os.path.join( os.getcwd(), os.path.dirname( __file__ ) ) ) + return os.path.abspath( os.path.dirname( __file__ ) ) def get_galaxy_root(): # precondition: this file must be at /test/unit/unittest_utils/utility.py - return os.path.normpath( os.path.join( get_unittest_utils_path(), '../../../' ) ) + return os.path.normpath( os.path.join( get_unittest_utils_path(), os.pardir, os.pardir, os.pardir ) ) def get_galaxy_libpath(): @@ -42,8 +42,7 @@ def clean_multiline_string( multiline_string, sep='\n' ): # ============================================================================= -sys.path.insert( 0, get_galaxy_libpath() ) -sys.path.insert( 1, get_unittest_utils_path() ) +sys.path[1:1] = [ get_galaxy_libpath(), get_unittest_utils_path() ] __all__ = [