The Unified and Autonomous Development Platform
chore: More python job suggestion improvements
Robin Shenc2d9f9dbf43f
diff --git a/server-plugin/server-plugin-buildspec-python/src/main/java/io/onedev/server/plugin/buildspec/python/PythonJobSuggestion.java b/server-plugin/server-plugin-buildspec-python/src/main/java/io/onedev/server/plugin/buildspec/python/PythonJobSuggestion.javaindex a4cfd735cc..0c6311d3c0 100644--- a/server-plugin/server-plugin-buildspec-python/src/main/java/io/onedev/server/plugin/buildspec/python/PythonJobSuggestion.java+++ b/server-plugin/server-plugin-buildspec-python/src/main/java/io/onedev/server/plugin/buildspec/python/PythonJobSuggestion.java@@ -77,7 +77,7 @@ public class PythonJobSuggestion implements JobSuggestion {private String getCoverageAndRuffCommand(boolean withPytest, String prefix) {String command;if (withPytest)- command = prefix + "coverage run -m pytest --junitxml=./pytest-result.xml\n";+ command = prefix + "pytest --cov --junitxml=./pytest-result.xml\n";elsecommand = prefix + "coverage run -m unittest\n";return command +@@ -85,13 +85,17 @@ public class PythonJobSuggestion implements JobSuggestion {prefix + "ruff check --exit-zero --output-format=json --output-file=ruff-result.json --exclude=.git";}+ private String getCoveragePackage(boolean withPytest) {+ return withPytest?"pytest-cov":"coverage";+ }+private CommandStep newPipTestAndLintStep(String dependencyInstallCommand, boolean withPytest) {CommandStep testAndLint = new CommandStep();var interpreter = new ShellInterpreter();testAndLint.setInterpreter(interpreter);testAndLint.setName("test and lint");testAndLint.setImage("python");- interpreter.setCommands(dependencyInstallCommand + "\n" + "pip install coverage ruff\n" + getCoverageAndRuffCommand(withPytest, ""));+ interpreter.setCommands(dependencyInstallCommand + "\n" + "pip install " + getCoveragePackage(withPytest) + " ruff\n" + getCoverageAndRuffCommand(withPytest, ""));return testAndLint;}@@ -104,20 +108,24 @@ public class PythonJobSuggestion implements JobSuggestion {}@Nullable- private String guessPyprojectOptionalTestGroup(Toml pyprojectToml) {+ private String guessPoetryOptionalTestGroup(Toml pyprojectToml) {if (pyprojectToml.getBoolean("tool.poetry.group.test.optional", false))return "test";- else if (pyprojectToml.getBoolean("tool.poetry.group.tests.optional", false))- return "tests";else if (pyprojectToml.getBoolean("tool.poetry.group.dev.optional", false))return "dev";- else if (pyprojectToml.getBoolean("tool.poetry.group.develop.optional", false))- return "develop";- else if (pyprojectToml.getBoolean("tool.poetry.group.development.optional", false))- return "development";elsereturn null;}++ @Nullable+ private String guessPyprojectOptionalTestGroup(Toml pyprojectToml) {+ if (pyprojectToml.getList("project.optional-dependencies.test") != null)+ return "test";+ else if (pyprojectToml.getList("project.optional-dependencies.dev") != null)+ return "dev";+ else+ return null;+ }@Nullableprivate String guessSetupPyOptionalTestGroup(String setupPy) {@@ -126,11 +134,8 @@ public class PythonJobSuggestion implements JobSuggestion {Matcher groupMatcher = SETUP_PY_EXTRAS_REQUIRE_GROUP_PATTERN.matcher(extrasRequireMatcher.group(1));while (groupMatcher.find()) {var group = groupMatcher.group(1);- if (group.equals("test") || group.equals("tests")- || group.equals("dev") || group.equals("develop")- || group.equals("development")) {+ if (group.equals("test") || group.equals("dev"))return group;- }}}return null;@@ -146,11 +151,8 @@ public class PythonJobSuggestion implements JobSuggestion {inExtrasRequire = false;} else if (inExtrasRequire) {var group = StringUtils.substringBefore(line, "=").trim();- if (group.equals("test") || group.equals("tests")- || group.equals("dev") || group.equals("develop")- || group.equals("development")) {+ if (group.equals("test") || group.equals("dev"))return group;- }}}return null;@@ -209,19 +211,21 @@ public class PythonJobSuggestion implements JobSuggestion {String installCommand = "poetry install";if (pyprojectToml != null) {- var optionalTestGroup = guessPyprojectOptionalTestGroup(pyprojectToml);+ var optionalTestGroup = guessPoetryOptionalTestGroup(pyprojectToml);if (optionalTestGroup != null)installCommand += " --with " + optionalTestGroup;}++ var withPytest = blob.getText().getContent().contains("pytest");+CommandStep testAndLint = new CommandStep();testAndLint.setName("test and lint");testAndLint.setImage("1dev/poetry:1.0.1");String commands = "" +"poetry config virtualenvs.create false\n" +installCommand + "\n" +- "poetry add coverage ruff\n";+ "poetry add " + getCoveragePackage(withPytest) + " ruff\n";- var withPytest = blob.getText().getContent().contains("pytest");testAndLint.getInterpreter().setCommands(commands + getCoverageAndRuffCommand(withPytest, "poetry run "));job.getSteps().add(testAndLint);if (withPytest)diff --git a/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/PythonJobSuggestionTest.java b/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/PythonJobSuggestionTest.javaindex 57de0bc920..207bf05c0c 100644--- a/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/PythonJobSuggestionTest.java+++ b/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/PythonJobSuggestionTest.java@@ -13,7 +13,6 @@ import org.junit.Test;import javax.annotation.Nullable;import java.io.IOException;-import static org.junit.Assert.assertFalse;import static org.junit.Assert.assertTrue;public class PythonJobSuggestionTest {@@ -24,7 +23,7 @@ public class PythonJobSuggestionTest {@Overridepublic Blob getBlob(BlobIdent blobIdent, boolean mustExist) {if (blobIdent.path.equals("poetry.lock"))- return new Blob(blobIdent, ObjectId.zeroId(), new byte[0]);+ return new Blob(blobIdent, ObjectId.zeroId(), "pytest".getBytes());else if (blobIdent.path.equals("pyproject.toml"))return new Blob(blobIdent, ObjectId.zeroId(), readTestResource("pyproject1.toml"));else@@ -32,7 +31,27 @@ public class PythonJobSuggestionTest {}};var jobs = new PythonJobSuggestion().suggestJobs(project, ObjectId.zeroId());- assertTrue(getTestAndLintStep(jobs.iterator().next()).getInterpreter().getCommands().contains("poetry install --with dev"));+ var testAndLinkCommands = getTestAndLintStep(jobs.iterator().next()).getInterpreter().getCommands();+ assertTrue(testAndLinkCommands.contains("poetry install --with dev") &&+ testAndLinkCommands.contains("poetry add pytest-cov") &&+ testAndLinkCommands.contains("poetry run pytest --cov"));++ project = new Project() {+ @Override+ public Blob getBlob(BlobIdent blobIdent, boolean mustExist) {+ if (blobIdent.path.equals("poetry.lock"))+ return new Blob(blobIdent, ObjectId.zeroId(), new byte[0]);+ else if (blobIdent.path.equals("pyproject.toml"))+ return new Blob(blobIdent, ObjectId.zeroId(), readTestResource("pyproject2.toml"));+ else+ return null;+ }+ };+ jobs = new PythonJobSuggestion().suggestJobs(project, ObjectId.zeroId());+ testAndLinkCommands = getTestAndLintStep(jobs.iterator().next()).getInterpreter().getCommands();+ assertTrue(!testAndLinkCommands.contains("poetry install --with") &&+ testAndLinkCommands.contains("poetry add coverage") &&+ testAndLinkCommands.contains("poetry run coverage"));}@Test@@ -47,13 +66,43 @@ public class PythonJobSuggestionTest {}};var jobs = new PythonJobSuggestion().suggestJobs(project, ObjectId.zeroId());- assertTrue(getTestAndLintStep(jobs.iterator().next()).getInterpreter().getCommands().contains("pip install -e .[dev]"));+ var commands = getTestAndLintStep(jobs.iterator().next()).getInterpreter().getCommands();+ assertTrue(!commands.contains("pip install -e .[dev]") &&+ commands.contains("pytest --cov") &&+ commands.contains("pytest-cov"));project = new Project() {@Overridepublic Blob getBlob(BlobIdent blobIdent, boolean mustExist) {if (blobIdent.path.equals("pyproject.toml"))return new Blob(blobIdent, ObjectId.zeroId(), readTestResource("pyproject2.toml"));+ else+ return null;+ }+ };+ jobs = new PythonJobSuggestion().suggestJobs(project, ObjectId.zeroId());+ commands = getTestAndLintStep(jobs.iterator().next()).getInterpreter().getCommands();+ assertTrue(!commands.contains("pip install -e .[") &&+ commands.contains("pip install coverage") &&+ commands.contains("coverage run -m unittest"));++ project = new Project() {+ @Override+ public Blob getBlob(BlobIdent blobIdent, boolean mustExist) {+ if (blobIdent.path.equals("pyproject.toml"))+ return new Blob(blobIdent, ObjectId.zeroId(), readTestResource("pyproject3.toml"));+ else+ return null;+ }+ };+ jobs = new PythonJobSuggestion().suggestJobs(project, ObjectId.zeroId());+ assertTrue(getTestAndLintStep(jobs.iterator().next()).getInterpreter().getCommands().contains("pip install -e .[test]"));++ project = new Project() {+ @Override+ public Blob getBlob(BlobIdent blobIdent, boolean mustExist) {+ if (blobIdent.path.equals("pyproject.toml"))+ return new Blob(blobIdent, ObjectId.zeroId(), readTestResource("pyproject1.toml"));else if (blobIdent.path.equals("setup.cfg"))return new Blob(blobIdent, ObjectId.zeroId(), readTestResource("setup.cfg"));elsediff --git a/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/pyproject2.toml b/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/pyproject2.tomlindex 372ea98b03..d65671d0d4 100644--- a/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/pyproject2.toml+++ b/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/pyproject2.toml@@ -51,10 +51,6 @@ mypy = ">=0.931"pexpect = ">=4.8.0"poethepoet = ">=0.12.3"pre-commit = ">=2.17.0"-pytest = ">=7.2.0"-pytest-cov = ">=3.0.0"-pytest-gitconfig = ">=0.6.0"-pytest-xdist = ">=2.5.0"types-backports = ">=0.1.3"types-colorama = ">=0.4"types-psutil = "*"@@ -76,10 +72,6 @@ optional = true[tool.poetry.group.build.dependencies]poetry-dynamic-versioning = { version = ">=1.1.0", markers = "python_version < '4'" }-[tool.poe.tasks.coverage]-cmd = "pytest --cov-report html --cov copier copier tests"-help = "generate an HTML report of the coverage"-[tool.poe.tasks.dev-setup]script = "devtasks:dev_setup"help = "set up local development environment"@@ -92,10 +84,6 @@ help = "start local docs server"script = "devtasks:lint"help = "check (and auto-fix) style with pre-commit"-[tool.poe.tasks.test]-cmd = "pytest --color=yes"-help = "run tests"-[tool.poe.tasks.types]cmd = "mypy ."help = "run the type (mypy) checker on the codebase"@@ -159,10 +147,6 @@ warn_return_any = falsemodule = ["tests.test_cli", "tests.test_prompt"]disable_error_code = ["no-untyped-def"]-[tool.pytest.ini_options]-addopts = "-n auto -ra"-markers = ["impure: needs network or is not 100% reproducible"]-[tool.commitizen]annotated_tag = truechangelog_incremental = truediff --git a/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/pyproject3.toml b/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/pyproject3.tomlnew file mode 100644index 0000000000..49bdc62bee--- /dev/null+++ b/server-plugin/server-plugin-buildspec-python/src/test/java/io/onedev/server/plugin/buildspec/python/pyproject3.toml@@ -0,0 +1,201 @@+[build-system]+# Minimum requirements for the build system to execute.+# See https://github.com/scipy/scipy/pull/12940 for the AIX issue.+requires = [+ "meson-python==0.13.1",+ "meson==1.2.1",+ "wheel",+ "Cython~=3.0.5", # Note: sync with setup.py, environment.yml and asv.conf.json+ # Force numpy higher than 2.0rc1, so that built wheels are compatible+ # with both numpy 1 and 2+ "numpy>=2.0.0rc1",+ "versioneer[toml]"+]++build-backend = "mesonpy"++[project]+name = 'pandas'+dynamic = [+ 'version'+]+description = 'Powerful data structures for data analysis, time series, and statistics'+readme = 'README.md'+authors = [+ { name = 'The Pandas Development Team', email='[email protected]' },+]+license = {file = 'LICENSE'}+requires-python = '>=3.10'+dependencies = [+ "numpy>=1.23.5; python_version<'3.12'",+ "numpy>=1.26.0; python_version>='3.12'",+ "python-dateutil>=2.8.2",+ "tzdata>=2022.7"+]+classifiers = [+ 'Development Status :: 5 - Production/Stable',+ 'Environment :: Console',+ 'Intended Audience :: Science/Research',+ 'License :: OSI Approved :: BSD License',+ 'Operating System :: OS Independent',+ 'Programming Language :: Cython',+ 'Programming Language :: Python',+ 'Programming Language :: Python :: 3',+ 'Programming Language :: Python :: 3 :: Only',+ 'Programming Language :: Python :: 3.10',+ 'Programming Language :: Python :: 3.11',+ 'Programming Language :: Python :: 3.12',+ 'Topic :: Scientific/Engineering'+]++[project.urls]+homepage = 'https://pandas.pydata.org'+documentation = 'https://pandas.pydata.org/docs/'+repository = 'https://github.com/pandas-dev/pandas'++[project.entry-points."pandas_plotting_backends"]+matplotlib = "pandas:plotting._matplotlib"++[project.optional-dependencies]+test = ['hypothesis>=6.84.0', 'pytest>=7.3.2', 'pytest-xdist>=3.4.0']+pyarrow = ['pyarrow>=10.0.1']+performance = ['bottleneck>=1.3.6', 'numba>=0.56.4', 'numexpr>=2.8.4']+computation = ['scipy>=1.10.0', 'xarray>=2022.12.0']+fss = ['fsspec>=2022.11.0']+aws = ['s3fs>=2022.11.0']+gcp = ['gcsfs>=2022.11.0']+excel = ['odfpy>=1.4.1', 'openpyxl>=3.1.0', 'python-calamine>=0.1.7', 'pyxlsb>=1.0.10', 'xlrd>=2.0.1', 'xlsxwriter>=3.0.5']+parquet = ['pyarrow>=10.0.1']+feather = ['pyarrow>=10.0.1']+hdf5 = [# blosc only available on conda (https://github.com/Blosc/python-blosc/issues/297)+ #'blosc>=1.20.1',+ 'tables>=3.8.0']+spss = ['pyreadstat>=1.2.0']+postgresql = ['SQLAlchemy>=2.0.0', 'psycopg2>=2.9.6', 'adbc-driver-postgresql>=0.10.0']+mysql = ['SQLAlchemy>=2.0.0', 'pymysql>=1.0.2']+sql-other = ['SQLAlchemy>=2.0.0', 'adbc-driver-postgresql>=0.10.0', 'adbc-driver-sqlite>=0.8.0']+html = ['beautifulsoup4>=4.11.2', 'html5lib>=1.1', 'lxml>=4.9.2']+xml = ['lxml>=4.9.2']+plot = ['matplotlib>=3.6.3']+output-formatting = ['jinja2>=3.1.2', 'tabulate>=0.9.0']+clipboard = ['PyQt5>=5.15.9', 'qtpy>=2.3.0']+compression = ['zstandard>=0.19.0']+timezone = ['pytz>=2023.4']+all = ['adbc-driver-postgresql>=0.10.0',+ 'adbc-driver-sqlite>=0.8.0',+ 'beautifulsoup4>=4.11.2',+ # blosc only available on conda (https://github.com/Blosc/python-blosc/issues/297)+ #'blosc>=1.21.3',+ 'bottleneck>=1.3.6',+ 'fastparquet>=2023.10.0',+ 'fsspec>=2022.11.0',+ 'gcsfs>=2022.11.0',+ 'html5lib>=1.1',+ 'hypothesis>=6.84.0',+ 'jinja2>=3.1.2',+ 'lxml>=4.9.2',+ 'matplotlib>=3.6.3',+ 'numba>=0.56.4',+ 'numexpr>=2.8.4',+ 'odfpy>=1.4.1',+ 'openpyxl>=3.1.0',+ 'psycopg2>=2.9.6',+ 'pyarrow>=10.0.1',+ 'pymysql>=1.0.2',+ 'PyQt5>=5.15.9',+ 'pyreadstat>=1.2.0',+ 'pytest>=7.3.2',+ 'pytest-xdist>=3.4.0',+ 'python-calamine>=0.1.7',+ 'pytz>=2023.4',+ 'pyxlsb>=1.0.10',+ 'qtpy>=2.3.0',+ 'scipy>=1.10.0',+ 's3fs>=2022.11.0',+ 'SQLAlchemy>=2.0.0',+ 'tables>=3.8.0',+ 'tabulate>=0.9.0',+ 'xarray>=2022.12.0',+ 'xlrd>=2.0.1',+ 'xlsxwriter>=3.0.5',+ 'zstandard>=0.19.0']++# TODO: Remove after setuptools support is dropped.+[tool.setuptools]+include-package-data = true++[tool.setuptools.packages.find]+include = ["pandas", "pandas.*"]+namespaces = false++[tool.setuptools.exclude-package-data]+"*" = ["*.c", "*.h"]++# See the docstring in versioneer.py for instructions. Note that you must+# re-run 'versioneer.py setup' after changing this section, and commit the+# resulting files.+[tool.versioneer]+VCS = "git"+style = "pep440"+versionfile_source = "pandas/_version.py"+versionfile_build = "pandas/_version.py"+tag_prefix = "v"+parentdir_prefix = "pandas-"++[tool.meson-python.args]+setup = ['--vsenv'] # For Windows++[tool.cibuildwheel]+skip = "cp36-* cp37-* cp38-* cp39-* pp* *_i686 *_ppc64le *_s390x"+build-verbosity = "3"+environment = {LDFLAGS="-Wl,--strip-all"}+test-requires = "hypothesis>=6.84.0 pytest>=7.3.2 pytest-xdist>=3.4.0"+test-command = """+ PANDAS_CI='1' python -c 'import pandas as pd; \+ pd.test(extra_args=["-m not clipboard and not single_cpu and not slow and not network and not db", "-n 2", "--no-strict-data-files"]); \+ pd.test(extra_args=["-m not clipboard and single_cpu and not slow and not network and not db", "--no-strict-data-files"]);' \+ """+free-threaded-support = true+before-build = "bash {package}/scripts/cibw_before_build.sh"+before-test = "bash {package}/scripts/cibw_before_test.sh"++[tool.cibuildwheel.windows]+before-build = "pip install delvewheel && bash {package}/scripts/cibw_before_build.sh"+repair-wheel-command = "delvewheel repair -w {dest_dir} {wheel}"++[[tool.cibuildwheel.overrides]]+select = "*-musllinux*"+before-test = "apk update && apk add musl-locales && bash {package}/scripts/cibw_before_test.sh"++[[tool.cibuildwheel.overrides]]+select = "*-win*"+# We test separately for Windows, since we use+# the windowsservercore docker image to check if any dlls are+# missing from the wheel+test-command = ""++[[tool.cibuildwheel.overrides]]+# Don't strip wheels on macOS.+# macOS doesn't support stripping wheels with linker+# https://github.com/MacPython/numpy-wheels/pull/87#issuecomment-624878264+select = "*-macosx*"+environment = {CFLAGS="-g0"}++[[tool.cibuildwheel.overrides]]+select = "*pyodide*"+test-requires = "pytest>=7.3.2 hypothesis>=6.84.0"+# Pyodide repairs wheels on its own, using auditwheel-emscripten+repair-wheel-command = ""+test-command = """+ PANDAS_CI='1' python -c 'import pandas as pd; \+ pd.test(extra_args=["-m not clipboard and not single_cpu and not slow and not network and not db", "--no-strict-data-files"]);' \+ """++[tool.ruff]+line-length = 88+target-version = "py310"+fix = true++[tool.ruff.lint]+unfixable = []+typing-modules = ["pandas._typing"]