Skip to content

Commit

Permalink
Merge pull request #38068 from mantidproject/0-wild-imports
Browse files Browse the repository at this point in the history
Use ruff to check for wild imports
  • Loading branch information
thomashampson authored Oct 11, 2024
2 parents 52ebfb9 + 2104ee4 commit 86aeb2f
Show file tree
Hide file tree
Showing 104 changed files with 829 additions and 565 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MANTID_ALGORITHMS_DLL GeneratePythonFitScript : public API::Algorithm {
std::size_t getNumberOfDomainsInFunction(Mantid::API::IFunction_sptr const &function) const;

std::string generateFitScript(std::string const &fittingType) const;
std::string generateVariableSetupCode() const;
std::string generateVariableSetupCode(std::string const &filename) const;
std::string generateSimultaneousFitCode() const;
std::string generateFunctionString() const;

Expand Down
15 changes: 9 additions & 6 deletions Framework/Algorithms/src/GeneratePythonFitScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,15 @@ std::size_t GeneratePythonFitScript::getNumberOfDomainsInFunction(IFunction_sptr

std::string GeneratePythonFitScript::generateFitScript(std::string const &fittingType) const {
std::string generatedScript;
generatedScript += generateVariableSetupCode();
generatedScript += "\n";
if (fittingType == "Sequential")
if (fittingType == "Sequential") {
generatedScript += generateVariableSetupCode("GeneratePythonFitScript_SequentialVariableSetup.py.in");
generatedScript += "\n";
generatedScript += getFileContents("GeneratePythonFitScript_SequentialFit.py.in");
else if (fittingType == "Simultaneous")
} else if (fittingType == "Simultaneous") {
generatedScript += generateVariableSetupCode("GeneratePythonFitScript_SimultaneousVariableSetup.py.in");
generatedScript += "\n";
generatedScript += generateSimultaneousFitCode();
}

bool plotOutput = getProperty("PlotOutput");
if (plotOutput) {
Expand All @@ -239,8 +242,8 @@ std::string GeneratePythonFitScript::generateFitScript(std::string const &fittin
return generatedScript;
}

std::string GeneratePythonFitScript::generateVariableSetupCode() const {
std::string code = getFileContents("GeneratePythonFitScript_VariableSetup.py.in");
std::string GeneratePythonFitScript::generateVariableSetupCode(std::string const &filename) const {
std::string code = getFileContents(filename);

std::vector<std::string> const inputWorkspaces = getProperty("InputWorkspaces");
std::vector<std::size_t> const workspaceIndices = getProperty("WorkspaceIndices");
Expand Down
32 changes: 18 additions & 14 deletions Framework/Algorithms/test/NormaliseByDetectorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "MantidFrameworkTestHelpers/ScopedFileHelper.h"
#include "MantidFrameworkTestHelpers/WorkspaceCreationHelper.h"

#include <sstream>

using namespace Mantid;
using namespace Mantid::Algorithms;
using namespace Mantid::API;
Expand Down Expand Up @@ -552,22 +554,24 @@ class NormaliseByDetectorTestPerformance : public CxxTest::TestSuite {

// Create a parameter file, with a root equation that will apply to all
// detectors.
const std::string parameterFileContents = boost::str(boost::format("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\
<parameter-file instrument = \"%1%\" date = \"2012-01-31T00:00:00\">\n\
<component-link name=\"%1%\">\n\
<parameter name=\"LinearBackground:A0\" type=\"fitting\">\n\
<formula eq=\"1\" result-unit=\"Wavelength\"/>\n\
<fixed />\n\
</parameter>\n\
<parameter name=\"LinearBackground:A1\" type=\"fitting\">\n\
<formula eq=\"2\" result-unit=\"Wavelength\"/>\n\
<fixed />\n\
</parameter>\n\
</component-link>\n\
</parameter-file>\n") % instrumentName);
std::ostringstream parameterFileStream;
parameterFileStream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
<< "<parameter-file instrument = \"" << instrumentName
<< "\" date = \"2012-01-31T00:00:00\">\n"
<< " <component-link name=\"" << instrumentName << "\">\n"
<< " <parameter name=\"LinearBackground:A0\" type=\"fitting\">\n"
<< " <formula eq=\"1\" result-unit=\"Wavelength\"/>\n"
<< " <fixed />\n"
<< " </parameter>\n"
<< " <parameter name=\"LinearBackground:A1\" type=\"fitting\">\n"
<< " <formula eq=\"2\" result-unit=\"Wavelength\"/>\n"
<< " <fixed />\n"
<< " </parameter>\n"
<< " </component-link>\n"
<< "</parameter-file>\n";

// Create a temporary Instrument Parameter file.
ScopedFile file(parameterFileContents, instrumentName + "_Parameters.xml");
ScopedFile file(parameterFileStream.str(), instrumentName + "_Parameters.xml");

// Apply parameter file to workspace.
apply_instrument_parameter_file_to_workspace(ws, file);
Expand Down
3 changes: 2 additions & 1 deletion Framework/Algorithms/test/NormaliseToUnityTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import unittest
from mantid.simpleapi import *
from mantid.api import mtd
from mantid.simpleapi import CreateWorkspace, DeleteWorkspace, NormaliseToUnity


class NormaliseToUnityTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataObjects/scripts/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# This line has to be first for some reason.
# from enthought.mayavi import mlab

from pylab import *
from pylab import figure, legend, plot, title, savefig, show, xlabel, ylabel
import pickle
from scipy import stats

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=too-many-branches,too-many-locals, invalid-name
from mantid.simpleapi import *
from mantid.kernel import *
from mantid.api import *
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm, WorkspaceProperty
from mantid.kernel import Direction
from mantid.simpleapi import logger, CreateWorkspace

from scipy.io import netcdf
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=too-many-branches,too-many-locals, invalid-name
from mantid.simpleapi import *
from mantid.kernel import *
from mantid.api import *
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm, WorkspaceProperty
from mantid.kernel import Direction
from mantid.simpleapi import logger, CreateWorkspace

from scipy.io import netcdf
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from mantid.api import * # PythonAlgorithm, registerAlgorithm, WorkspaceProperty
from mantid.simpleapi import *
from mantid.kernel import *
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm
from mantid.simpleapi import CreateWorkspace, DeleteWorkspace, Plus, Rebin, RenameWorkspaces, Load

# pylint: disable=no-init, too-many-arguments

Expand Down
4 changes: 2 additions & 2 deletions Framework/PythonInterface/plugins/algorithms/CalculateFlux.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from mantid.api import PythonAlgorithm, MatrixWorkspaceProperty, InstrumentValidator
from mantid.api import AlgorithmFactory, PythonAlgorithm, MatrixWorkspaceProperty, InstrumentValidator
from mantid.kernel import Direction, FloatBoundedValidator
from mantid.simpleapi import *
from mantid.simpleapi import CloneWorkspace, FindDetectorsInShape, GroupDetectors, Rebin
import numpy as np


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name
from mantid.simpleapi import *
from mantid.api import *
from mantid.kernel import *
from mantid.api import mtd, AlgorithmFactory, MatrixWorkspaceProperty, PythonAlgorithm
from mantid.kernel import Direction, MaterialBuilder, StringListValidator, StringMandatoryValidator
from mantid.simpleapi import ConvertToPointData, CreateWorkspace, Rebin, SetSampleMaterial
import math
import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name,bare-except,too-many-arguments,multiple-statements
from mantid.api import *
from mantid.kernel import *
from mantid.api import AlgorithmFactory, PythonAlgorithm
from mantid.kernel import ConfigService, Direction
import os


Expand Down
4 changes: 2 additions & 2 deletions Framework/PythonInterface/plugins/algorithms/ClipPeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# NScD Oak Ridge National Laboratory, European Spallation Source
# & Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from mantid.api import PythonAlgorithm, WorkspaceProperty
from mantid.simpleapi import *
from mantid.api import AlgorithmFactory, PythonAlgorithm, WorkspaceProperty
from mantid.simpleapi import CloneWorkspace
from mantid.kernel import Direction, IntBoundedValidator

import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# pylint: disable=no-init,invalid-name,too-many-instance-attributes
import mantid
import mantid.simpleapi as api
from mantid.api import *
from mantid.kernel import *
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm
import os


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scipy import constants
from mantid.kernel import CompositeValidator, Direction, FloatBoundedValidator
from mantid.api import AlgorithmFactory, CommonBinsValidator, HistogramValidator, MatrixWorkspaceProperty, PythonAlgorithm
from mantid.simpleapi import *
from mantid.simpleapi import CloneWorkspace, Rebin, Rebin2D, ScaleX, Transpose


class UnitError(ValueError):
Expand Down
6 changes: 3 additions & 3 deletions Framework/PythonInterface/plugins/algorithms/ConjoinFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name
from mantid.api import *
from mantid.kernel import *
from mantid.simpleapi import *
from mantid.api import mtd, AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm, WorkspaceProperty
from mantid.kernel import config, logger, Direction, IntArrayBoundedValidator, IntArrayProperty
from mantid.simpleapi import ConjoinWorkspaces, DeleteWorkspace, LoadGSS
import os


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name
from mantid.api import *
from mantid.kernel import *
from mantid.simpleapi import *
from mantid.api import mtd, AlgorithmFactory, PythonAlgorithm, TextAxis, WorkspaceGroup, WorkspaceProperty
from mantid.kernel import logger, Direction, StringListValidator, StringMandatoryValidator
from mantid.simpleapi import ConjoinWorkspaces, DeleteWorkspace, ExtractSingleSpectrum, RenameWorkspace


class ConjoinSpectra(PythonAlgorithm):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name,bare-except,too-many-arguments
from mantid.api import *
from mantid.kernel import *
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm
from mantid.kernel import ConfigService, Direction, StringArrayProperty
import mantid
import os

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=no-init,invalid-name
import mantid.simpleapi as api
from mantid.api import *
from mantid.kernel import *

_OUTPUTLEVEL = "NOOUTPUT"
from mantid.api import (
AlgorithmFactory,
AnalysisDataService,
FileAction,
FileProperty,
ITableWorkspaceProperty,
PythonAlgorithm,
WorkspaceFactory,
)
from mantid.kernel import Direction, FloatBoundedValidator, IntArrayBoundedValidator, IntArrayProperty


class CreateLeBailFitInput(PythonAlgorithm):
"""Create the input TableWorkspaces for LeBail Fitting"""

def category(self):
""" """
return "Diffraction\\Fitting;Utility\\Workspaces"

def seeAlso(self):
return ["LeBailFit"]

def name(self):
""" """
return "CreateLeBailFitInput"

def summary(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
# pylint: disable=no-init,too-many-locals,too-many-instance-attributes,too-many-arguments,invalid-name
import math
import numpy as np
from mantid.simpleapi import *
from mantid.simpleapi import (
AddSampleLogMultiple,
CreateWorkspace,
DeleteWorkspace,
ExtractSingleSpectrum,
GroupWorkspaces,
SplineInterpolation,
)
from mantid.api import (
mtd,
PythonAlgorithm,
AlgorithmFactory,
PropertyMode,
Expand Down
13 changes: 11 additions & 2 deletions Framework/PythonInterface/plugins/algorithms/EnggCalibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from mantid.kernel import *
from mantid.api import *
from mantid.api import (
AlgorithmFactory,
FileAction,
FileProperty,
ITableWorkspaceProperty,
MatrixWorkspaceProperty,
Progress,
PropertyMode,
PythonAlgorithm,
)
from mantid.kernel import Direction, FloatArrayProperty, StringListValidator
import mantid.simpleapi as mantid


Expand Down
13 changes: 11 additions & 2 deletions Framework/PythonInterface/plugins/algorithms/EnggCalibrateFull.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
# SPDX - License - Identifier: GPL - 3.0 +
import math

from mantid.kernel import *
from mantid.api import *
from mantid.api import (
AlgorithmFactory,
FileAction,
FileProperty,
ITableWorkspaceProperty,
MatrixWorkspaceProperty,
Progress,
PropertyMode,
PythonAlgorithm,
)
from mantid.kernel import Direction, FloatArrayProperty, StringListValidator, V3D
from mantid.simpleapi import SaveAscii, logger
import EnggUtils

Expand Down
19 changes: 14 additions & 5 deletions Framework/PythonInterface/plugins/algorithms/EnggFitPeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
# SPDX - License - Identifier: GPL - 3.0 +
import math

from mantid.kernel import *
from mantid.api import *
from mantid.simpleapi import *
from mantid.api import (
AlgorithmFactory,
FileAction,
FileProperty,
FunctionFactory,
ITableWorkspaceProperty,
MatrixWorkspaceProperty,
Progress,
PythonAlgorithm,
)
from mantid.kernel import Direction, FloatArrayProperty
from mantid.simpleapi import ConvertUnits, CreateEmptyTableWorkspace, CreateWorkspace, FindPeaks, Fit


class EnggFitPeaks(PythonAlgorithm):
Expand Down Expand Up @@ -536,7 +545,7 @@ def _find_peak_center_in_params(self, fitted_params):
return fitted_params["X0"]
else:
raise ValueError(
"Inconsistency found. I do not know how to deal with centers of peaks " "of types other than {0}".format(PEAK_TYPE)
"Inconsistency found. I do not know how to deal with centers of peaks " "of types other than {0}".format(self.PEAK_TYPE)
)

def _find_peak_intensity_in_params(self, fitted_params):
Expand All @@ -550,7 +559,7 @@ def _find_peak_intensity_in_params(self, fitted_params):
return fitted_params["I"]
else:
raise ValueError(
"Inconsistency found. I do not know how to deal with intensities of " "peaks of types other than {0}".format(PEAK_TYPE)
"Inconsistency found. I do not know how to deal with intensities of " "peaks of types other than {0}".format(self.PEAK_TYPE)
)

def _b2bexp_is_acceptable(self, fitted_params):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from mantid.kernel import *
from mantid.api import *
from mantid.simpleapi import *
from mantid.api import AlgorithmFactory, ITableWorkspaceProperty, PythonAlgorithm
from mantid.kernel import Direction
from mantid.simpleapi import ConvertTableToMatrixWorkspace, Fit


class EnggFitTOFFromPeaks(PythonAlgorithm):
Expand Down
Loading

0 comments on commit 86aeb2f

Please sign in to comment.