From 994d2461f490b5a181fd9931cc0b8d3404c3d86b Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Wed, 28 Aug 2024 08:38:41 +0100 Subject: [PATCH 1/4] Switch pre-commit to ruff --- .pre-commit-config.yaml | 36 ++++++------------------------------ pyproject.toml | 12 ++++++++---- setup.cfg | 17 ----------------- 3 files changed, 14 insertions(+), 51 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 760d20c5..da964b28 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,4 @@ repos: -# Syntax validation and some basic sanity checks - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: @@ -9,33 +8,10 @@ repos: - id: check-json - id: check-yaml -# Automatically sort imports -- repo: https://github.com/PyCQA/isort - rev: 5.13.2 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.2 hooks: - - id: isort - args: [ - # '-a', 'from __future__ import annotations', # 3.7-3.11 - '--rm', 'from __future__ import absolute_import', # -3.0 - '--rm', 'from __future__ import division', # -3.0 - # '--rm', 'from __future__ import generator_stop', # -3.7 - '--rm', 'from __future__ import generators', # -2.3 - '--rm', 'from __future__ import nested_scopes', # -2.2 - '--rm', 'from __future__ import print_function', # -3.0 - '--rm', 'from __future__ import unicode_literals', # -3.0 - '--rm', 'from __future__ import with_statement', # -2.6 - ] - -# Automatic source code formatting -- repo: https://github.com/psf/black - rev: 24.8.0 - hooks: - - id: black - args: [--safe, --quiet] - -# Linting -- repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 - hooks: - - id: flake8 - additional_dependencies: ['flake8-comprehensions==3.8.0'] + - id: ruff + args: [--fix, --exit-non-zero-on-fix, --show-fixes] + - id: ruff-format + types: [file] diff --git a/pyproject.toml b/pyproject.toml index 2f193199..c7065d57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,8 @@ -[tool.isort] -#sections="FUTURE,STDLIB,THIRDPARTY,CCTBX,FIRSTPARTY,LOCALFOLDER" -known_firstparty="ispyb" -profile="black" +[tool.ruff.lint.isort] +known-first-party = ["ispyb"] + +[tool.ruff.lint] +select = ["E", "F", "W", "C4", "I"] +unfixable = ["F841"] +# E501 line too long (if formatter cannot split, we don't worry) +ignore = ["E501"] diff --git a/setup.cfg b/setup.cfg index 9523b3c4..e4df2b88 100644 --- a/setup.cfg +++ b/setup.cfg @@ -52,20 +52,3 @@ libtbx.precommit = [options.packages.find] where = src - -[flake8] -# Black disagrees with flake8 on a few points. Ignore those. -ignore = E203, E266, E501, W503 -# E203 whitespace before ':' -# E266 too many leading '#' for block comment -# E501 line too long -# W503 line break before binary operator - -max-line-length = 88 - -select = - E401,E711,E712,E713,E714,E721,E722,E901, - F401,F402,F403,F405,F541,F631,F632,F633,F811,F812,F821,F822,F841,F901, - W191,W291,W292,W293,W602,W603,W604,W605,W606, - # flake8-comprehensions, https://github.com/adamchainz/flake8-comprehensions - C4, From 71cbed5d26e03c9a3b4e31fd25d48ad412441eef Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Wed, 28 Aug 2024 08:39:05 +0100 Subject: [PATCH 2/4] Apply new pre-commit --- bin/legacy/em_put_particle.py | 1 - bin/legacy/em_put_sample.py | 1 - bin/legacy/put_dcgroup.py | 1 - bin/legacy/put_program.py | 1 - 4 files changed, 4 deletions(-) diff --git a/bin/legacy/em_put_particle.py b/bin/legacy/em_put_particle.py index 101f40d4..7fdc8ed5 100755 --- a/bin/legacy/em_put_particle.py +++ b/bin/legacy/em_put_particle.py @@ -11,7 +11,6 @@ import sys if __name__ == "__main__": - from ispyb_api.dbconnection import dbconnection from ispyb_api.em import em diff --git a/bin/legacy/em_put_sample.py b/bin/legacy/em_put_sample.py index d2611b28..6b203449 100755 --- a/bin/legacy/em_put_sample.py +++ b/bin/legacy/em_put_sample.py @@ -11,7 +11,6 @@ import sys if __name__ == "__main__": - from ispyb_api.core import core from ispyb_api.dbconnection import dbconnection diff --git a/bin/legacy/put_dcgroup.py b/bin/legacy/put_dcgroup.py index d00997c3..107ceec3 100755 --- a/bin/legacy/put_dcgroup.py +++ b/bin/legacy/put_dcgroup.py @@ -11,7 +11,6 @@ import sys if __name__ == "__main__": - from datetime import datetime from ispyb_api.core import core diff --git a/bin/legacy/put_program.py b/bin/legacy/put_program.py index a785c6c8..65a48c0b 100755 --- a/bin/legacy/put_program.py +++ b/bin/legacy/put_program.py @@ -18,7 +18,6 @@ # 1 = success if __name__ == "__main__": - from datetime import datetime from ispyb_api.dbconnection import dbconnection From d111efca85b9c19f12d6630f23e737ba621d1c2b Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Wed, 28 Aug 2024 08:52:30 +0100 Subject: [PATCH 3/4] Migrate to pyproject.toml --- .bumpversion.cfg | 6 +++--- pyproject.toml | 48 ++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 54 ------------------------------------------------ setup.py | 4 ---- 4 files changed, 51 insertions(+), 61 deletions(-) delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d4ed45f4..ffb8f5ca 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -3,9 +3,9 @@ current_version = 10.2.3 commit = True tag = True -[bumpversion:file:setup.cfg] -search = version = {current_version} -replace = version = {new_version} +[bumpversion:file:pyproject.toml] +search = version = "{current_version}" +replace = version = "{new_version}" [bumpversion:file:src/ispyb/__init__.py] search = __version__ = "{current_version}" diff --git a/pyproject.toml b/pyproject.toml index c7065d57..5b3cc716 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,51 @@ +[build-system] +requires = ["setuptools>=61.2"] +build-backend = "setuptools.build_meta" + +[project] +name = "ispyb" +version = "10.2.3" +description = "Python package to access ISPyB database" +authors = [ + { name = "Diamond Light Source", email = "scientificsoftware@diamond.ac.uk" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Operating System :: OS Independent", + "Topic :: Software Development :: Libraries :: Python Modules", +] +keywords = ["ISPyB", "database"] +requires-python = ">=3.7" +readme = "README.md" +license = { text = "Apache License 2.0" } +dependencies = ["mysql-connector-python>=8.0.32", "sqlalchemy<2", "tabulate"] + +[project.urls] +Documentation = "https://ispyb.readthedocs.io" +GitHub = "https://github.com/DiamondLightSource/ispyb-api" +Bug-Tracker = "https://github.com/DiamondLightSource/ispyb-api/issues" + +[project.entry-points."libtbx.dispatcher.script"] +"ispyb.job" = "ispyb.job" +"ispyb.last_data_collections_on" = "ispyb.last_data_collections_on" + +[project.entry-points."libtbx.precommit"] +ispyb = "ispyb" + +[project.scripts] +"ispyb.job" = "ispyb.cli.job:main" +"ispyb.last_data_collections_on" = "ispyb.cli.last_data_collections_on:main" + +[tool.setuptools] +script-files = ["bin/dimple2ispyb.py", "bin/mxdatareduction2ispyb.py"] + [tool.ruff.lint.isort] known-first-party = ["ispyb"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index e4df2b88..00000000 --- a/setup.cfg +++ /dev/null @@ -1,54 +0,0 @@ -[metadata] -name = ispyb -version = 10.2.3 -description = Python package to access ISPyB database -description_file = README.md -long_description = This package provides a Python interface to ISPyB. It can access the ISPyB database directly or (in future versions) run on top of the official ISPyB webservices API. -author = Diamond Light Source -author_email = scientificsoftware@diamond.ac.uk -license = Apache License, Version 2.0 -classifiers = - Development Status :: 5 - Production/Stable - License :: OSI Approved :: Apache Software License - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Operating System :: OS Independent - Topic :: Software Development :: Libraries :: Python Modules -keywords = - ISPyB - database -project_urls = - Documentation = https://ispyb.readthedocs.io - GitHub = https://github.com/DiamondLightSource/ispyb-api - Bug-Tracker = https://github.com/DiamondLightSource/ispyb-api/issues - -[options] -include_package_data = True -install_requires = - mysql-connector-python>=8.0.32 - sqlalchemy<2 - tabulate -packages = find: -package_dir = - =src -python_requires = >=3.7 -scripts = - bin/dimple2ispyb.py - bin/mxdatareduction2ispyb.py - -[options.entry_points] -console_scripts = - ispyb.job = ispyb.cli.job:main - ispyb.last_data_collections_on = ispyb.cli.last_data_collections_on:main -libtbx.dispatcher.script = - ispyb.job = ispyb.job - ispyb.last_data_collections_on = ispyb.last_data_collections_on -libtbx.precommit = - ispyb = ispyb - -[options.packages.find] -where = src diff --git a/setup.py b/setup.py deleted file mode 100644 index 1abbd068..00000000 --- a/setup.py +++ /dev/null @@ -1,4 +0,0 @@ -import setuptools - -if __name__ == "__main__": - setuptools.setup() From 64c6f2559a741e65949e02d9b84c31536ba6eb9b Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Wed, 28 Aug 2024 08:59:29 +0100 Subject: [PATCH 4/4] Switch to bump-my-version --- .bumpversion.cfg | 12 ------------ RELEASE.md | 4 ++-- pyproject.toml | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 14 deletions(-) delete mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index ffb8f5ca..00000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,12 +0,0 @@ -[bumpversion] -current_version = 10.2.3 -commit = True -tag = True - -[bumpversion:file:pyproject.toml] -search = version = "{current_version}" -replace = version = "{new_version}" - -[bumpversion:file:src/ispyb/__init__.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" diff --git a/RELEASE.md b/RELEASE.md index b67db947..5966f0a8 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -2,10 +2,10 @@ First, ensure that you have updated `HISTORY.rst` with the changes for the new release and committed the changes. -To prepare an ISPyB API release you need to install the package [bump2version](https://pypi.org/project/bump2version/): +To prepare an ISPyB API release you need to install the package [bump-my-version](https://github.com/callowayproject/bump-my-version): ```bash -pip install bump2version +pip install bump-my-version ``` and then, in the repository directory, run one of the following diff --git a/pyproject.toml b/pyproject.toml index 5b3cc716..1a6cbbac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,3 +54,19 @@ select = ["E", "F", "W", "C4", "I"] unfixable = ["F841"] # E501 line too long (if formatter cannot split, we don't worry) ignore = ["E501"] + +[tool.bumpversion] +current_version = "10.2.3" +commit = true +tag = true + + +[[tool.bumpversion.files]] +filename = "pyproject.toml" +search = 'version = "{current_version}"' +replace = 'version = "{new_version}"' + +[[tool.bumpversion.files]] +filename = "src/ispyb/__init__.py" +search = '__version__ = "{current_version}"' +replace = '__version__ = "{new_version}"'