Skip to content

Commit

Permalink
Merge pull request #17991 from nsoranzo/warn_unused_ignores
Browse files Browse the repository at this point in the history
Enable ``warn_unused_ignores`` mypy option
  • Loading branch information
mvdbeek authored Apr 16, 2024
2 parents d5458b0 + 053ca51 commit 0a68b5d
Show file tree
Hide file tree
Showing 97 changed files with 344 additions and 335 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

from pkgutil import extend_path

__path__ = extend_path(__path__, __name__) # type: ignore[has-type]
__path__ = extend_path(__path__, __name__)
2 changes: 1 addition & 1 deletion lib/galaxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def __init__(self, **kwargs) -> None:
self.watchers = self._register_singleton(ConfigWatchers)
self._configure_toolbox()
# Load Data Manager
self.data_managers = self._register_singleton(DataManagers) # type: ignore[type-abstract]
self.data_managers = self._register_singleton(DataManagers)
# Load the update repository manager.
self.update_repository_manager = self._register_singleton(
UpdateRepositoryManager, UpdateRepositoryManager(self)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/app_unittest_utils/toolbox_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def setUp(self):
install_model = mapping.init("sqlite:///:memory:", create_tables=True)
self.app.tool_cache = ToolCache()
self.app.install_model = install_model
self.app.reindex_tool_search = self.__reindex # type: ignore[assignment]
self.app.reindex_tool_search = self.__reindex # type: ignore[method-assign]
itp_config = os.path.join(self.test_directory, "integrated_tool_panel.xml")
self.app.config.integrated_tool_panel_config = itp_config
self.app.watchers = ConfigWatchers(self.app)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/authnz/custos_authnz.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
try:
import pkce
except ImportError:
pkce = None # type: ignore[assignment]
pkce = None # type: ignore[assignment, unused-ignore]

log = logging.getLogger(__name__)
STATE_COOKIE_NAME = "galaxy-oidc-state"
Expand Down
10 changes: 7 additions & 3 deletions lib/galaxy/authnz/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
string_as_bool,
unicodify,
)
from galaxy.util.resources import files
from galaxy.util.resources import (
as_file,
resource_path,
)
from .custos_authnz import (
CustosAuthFactory,
KEYCLOAK_BACKENDS,
Expand All @@ -35,7 +38,7 @@
Strategy,
)

OIDC_BACKEND_SCHEMA = files("galaxy.authnz.xsd") / "oidc_backends_config.xsd"
OIDC_BACKEND_SCHEMA = resource_path(__package__, "xsd/oidc_backends_config.xsd")

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -108,7 +111,8 @@ def _parse_oidc_backends_config(self, config_file):
self.oidc_backends_config = {}
self.oidc_backends_implementation = {}
try:
tree = parse_xml(config_file, schemafname=OIDC_BACKEND_SCHEMA)
with as_file(OIDC_BACKEND_SCHEMA) as oidc_backend_schema_path:
tree = parse_xml(config_file, schemafname=oidc_backend_schema_path)
root = tree.getroot()
if root.tag != "OIDC":
raise etree.ParseError(
Expand Down
17 changes: 9 additions & 8 deletions lib/galaxy/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
read_properties_from_file,
running_from_source,
)
from galaxy.util.resources import (
as_file,
resource_path,
)
from galaxy.util.themes import flatten_theme
from ..version import (
VERSION_MAJOR,
Expand All @@ -60,18 +64,13 @@
if TYPE_CHECKING:
from galaxy.model import User

if sys.version_info >= (3, 9):
from importlib.resources import files
else:
from importlib_resources import files

log = logging.getLogger(__name__)

DEFAULT_LOCALE_FORMAT = "%a %b %e %H:%M:%S %Y"
ISO_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"

GALAXY_APP_NAME = "galaxy"
GALAXY_SCHEMAS_PATH = files("galaxy.config") / "schemas"
GALAXY_SCHEMAS_PATH = resource_path(__package__, "schemas")
GALAXY_CONFIG_SCHEMA_PATH = GALAXY_SCHEMAS_PATH / "config_schema.yml"
REPORTS_CONFIG_SCHEMA_PATH = GALAXY_SCHEMAS_PATH / "reports_config_schema.yml"
TOOL_SHED_CONFIG_SCHEMA_PATH = GALAXY_SCHEMAS_PATH / "tool_shed_config_schema.yml"
Expand Down Expand Up @@ -193,7 +192,7 @@ def configure_logging(config, facts=None):
logging.config.dictConfig(logging_conf)


def find_root(kwargs):
def find_root(kwargs) -> str:
return os.path.abspath(kwargs.get("root_dir", "."))


Expand Down Expand Up @@ -238,6 +237,7 @@ class BaseAppConfiguration(HasDynamicProperties):
add_sample_file_to_defaults: Set[str] = set() # for these options, add sample config files to their defaults
listify_options: Set[str] = set() # values for these options are processed as lists of values
object_store_store_by: str
shed_tools_dir: str

def __init__(self, **kwargs):
self._preprocess_kwargs(kwargs)
Expand Down Expand Up @@ -835,7 +835,8 @@ def _process_config(self, kwargs: Dict[str, Any]) -> None:
self.cookie_path = kwargs.get("cookie_path")
if not running_from_source and kwargs.get("tool_path") is None:
try:
self.tool_path = str(files("galaxy.tools") / "bundled")
with as_file(resource_path("galaxy.tools", "bundled")) as path:
self.tool_path = os.fspath(path)
except ModuleNotFoundError:
# Might not be a full galaxy installation
self.tool_path = self._in_root_dir(self.tool_path)
Expand Down
9 changes: 5 additions & 4 deletions lib/galaxy/config/config_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
nice_config_parser,
NicerConfigParser,
)
from galaxy.util.resources import Traversable
from galaxy.util.yaml_util import (
ordered_dump,
ordered_load,
Expand All @@ -72,7 +73,7 @@ class App(NamedTuple):
default_port: str
expected_app_factories: List[str]
destination: str
schema_path: str
schema_path: Traversable

@property
def app_name(self) -> str:
Expand Down Expand Up @@ -219,21 +220,21 @@ class OptionValue(NamedTuple):
"8080",
["galaxy.web.buildapp:app_factory"],
"config/galaxy.yml",
str(GALAXY_CONFIG_SCHEMA_PATH),
GALAXY_CONFIG_SCHEMA_PATH,
)
SHED_APP = App(
["tool_shed_wsgi.ini", "config/tool_shed.ini"],
"9009",
["tool_shed.webapp.buildapp:app_factory"],
"config/tool_shed.yml",
str(TOOL_SHED_CONFIG_SCHEMA_PATH),
TOOL_SHED_CONFIG_SCHEMA_PATH,
)
REPORTS_APP = App(
["reports_wsgi.ini", "config/reports.ini"],
"9001",
["galaxy.webapps.reports.buildapp:app_factory"],
"config/reports.yml",
str(REPORTS_CONFIG_SCHEMA_PATH),
REPORTS_CONFIG_SCHEMA_PATH,
)
APPS = {"galaxy": GALAXY_APP, "tool_shed": SHED_APP, "reports": REPORTS_APP}

Expand Down
7 changes: 4 additions & 3 deletions lib/galaxy/config/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from galaxy.exceptions import ConfigurationError
from galaxy.util.resources import Traversable
from galaxy.util.yaml_util import ordered_load

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -35,15 +36,15 @@ def get_app_option(self, name):


class AppSchema(Schema):
def __init__(self, schema_path, app_name):
def __init__(self, schema_path: Traversable, app_name: str):
self.raw_schema = self._read_schema(schema_path)
self.description = self.raw_schema.get("desc", None)
app_schema = self.raw_schema["mapping"][app_name]["mapping"]
self._preprocess(app_schema)
super().__init__(app_schema)

def _read_schema(self, path):
with open(path) as f:
def _read_schema(self, path: Traversable):
with path.open() as f:
return ordered_load(f)

def _preprocess(self, app_schema):
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/datatypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4367,7 +4367,7 @@ class HexrdImagesNpz(Npz):
>>> fname = get_test_fname('hexrd.images.npz')
>>> HexrdImagesNpz().sniff(fname)
True
>>> fname = get_test_fname('eta_ome.npz')
>>> fname = get_test_fname('hexrd.eta_ome.npz')
>>> HexrdImagesNpz().sniff(fname)
False
"""
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/datatypes/constructive_solid_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def display_peek(self, dataset: DatasetProtocol) -> str:
return f"Ply file ({nice_size(dataset.get_size())})"


class PlyAscii(Ply, data.Text): # type: ignore[misc]
class PlyAscii(Ply, data.Text):
"""
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('test.plyascii')
Expand All @@ -160,7 +160,7 @@ def __init__(self, **kwd):
data.Text.__init__(self, **kwd)


class PlyBinary(Ply, Binary): # type: ignore[misc]
class PlyBinary(Ply, Binary):
file_ext = "plybinary"
subtype = "binary"

Expand Down Expand Up @@ -477,7 +477,7 @@ def display_peek(self, dataset: DatasetProtocol) -> str:
return f"Vtk file ({nice_size(dataset.get_size())})"


class VtkAscii(Vtk, data.Text): # type: ignore[misc]
class VtkAscii(Vtk, data.Text):
"""
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('test.vtkascii')
Expand All @@ -495,7 +495,7 @@ def __init__(self, **kwd):
data.Text.__init__(self, **kwd)


class VtkBinary(Vtk, Binary): # type: ignore[misc]
class VtkBinary(Vtk, Binary):
"""
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('test.vtkbinary')
Expand Down
2 changes: 0 additions & 2 deletions lib/galaxy/datatypes/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ class Mp4(Video):
>>> from galaxy.datatypes.sniff import sniff_with_cls
>>> sniff_with_cls(Mp4, 'video_1.mp4')
True
>>> sniff_with_cls(Mp4, 'audio_1.mp4')
False
"""

file_ext = "mp4"
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/datatypes/sniff.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@

def get_test_fname(fname):
"""Returns test data filename"""
path, name = os.path.split(__file__)
path = os.path.dirname(__file__)
full_path = os.path.join(path, "test", fname)
assert os.path.isfile(full_path), f"{full_path} is not a file"
return full_path


Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/jobs/runners/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ def parse_destination_params(self, params):
check_required = []
parsed_params = {}
for k, spec in self.DESTINATION_PARAMS_SPEC.items():
value = params.get(k, spec.get("default")) # type: ignore[attr-defined]
if spec.get("required") and not value: # type: ignore[attr-defined]
value = params.get(k, spec.get("default"))
if spec.get("required") and not value:
check_required.append(k)
mapper = spec.get("map") # type: ignore[attr-defined]
mapper = spec.get("map")
parsed_params[k] = mapper(value) # type: ignore[operator]
if check_required:
raise AWSBatchRunnerException(
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/jobs/runners/util/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
except ImportError:
"""Don't make psutil a strict requirement, but use if available."""
Process = None # type: ignore
Process = None


def kill_pid(pid: int, use_psutil: bool = True):
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/history_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _contained_id_map(self, id_list):
component_class = self.contained_class
stmt = (
select(component_class)
.where(component_class.id.in_(id_list)) # type: ignore[attr-defined]
.where(component_class.id.in_(id_list))
.options(undefer(component_class._metadata))
.options(joinedload(component_class.dataset).joinedload(model.Dataset.actions))
.options(joinedload(component_class.tags)) # type: ignore[attr-defined]
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def by_api_key(self, api_key: str, sa_session=None):

def by_oidc_access_token(self, access_token: str):
if hasattr(self.app, "authnz_manager") and self.app.authnz_manager:
user = self.app.authnz_manager.match_access_token_to_user(self.app.model.session, access_token) # type: ignore[attr-defined]
user = self.app.authnz_manager.match_access_token_to_user(self.app.model.session, access_token)
return user
else:
return None
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def build_invocations_query(
for inv in trans.sa_session.scalars(stmt)
if self.check_security(trans, inv, check_ownership=True, check_accessible=False)
]
return invocations, total_matches # type:ignore[return-value]
return invocations, total_matches


MissingToolsT = List[Tuple[str, str, Optional[str], str]]
Expand Down
Loading

0 comments on commit 0a68b5d

Please sign in to comment.