Skip to content

Commit ef5cf23

Browse files
authored
Update python and pre-commits (#384)
* Replace black with ruff and add python version * Fix parser * Update CI too
1 parent c263404 commit ef5cf23

13 files changed

Lines changed: 34 additions & 45 deletions

File tree

.github/workflows/code.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
fail-fast: false
4747
matrix:
4848
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
49-
python: ["3.12"]
49+
python: ["3.12", "3.13"]
5050
install: ["-e .[dev]"]
5151
# Make one version be non-editable to test both paths of version code
5252
include:

.pre-commit-config.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
repos:
22

3-
# Automatic source code formatting
4-
- repo: https://github.com/psf/black
5-
rev: 24.1.1
6-
hooks:
7-
- id: black
8-
args: [--safe, --quiet]
9-
10-
113
# Linter
124
- repo: local
135
hooks:
146
- id: ruff
15-
name: Run ruff
16-
stages: [pre-commit]
7+
name: lint with ruff
8+
language: system
9+
entry: ruff check --force-exclude --fix
10+
types: [python]
11+
require_serial: true
12+
13+
- id: ruff-format
14+
name: format with ruff
1715
language: system
18-
entry: ruff check
16+
entry: ruff format --force-exclude
1917
types: [python]
18+
require_serial: true
2019

2120

2221
# Other syntax checks

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ classifiers = [
1313
"Natural Language :: English",
1414
"Programming Language :: Python :: 3.11",
1515
"Programming Language :: Python :: 3.12",
16+
"Programming Language :: Python :: 3.13",
1617
]
1718
keywords = ["nexus", "NXmx"]
1819
dependencies = [

src/nexgen/command_line/ED_mrc_to_nexus.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ def overwrite_from_command_line(
344344

345345

346346
def log_dict(logger: Logger, dictionary: dict, skip: list = None) -> None:
347-
348347
if skip is None:
349348
skip = [1]
350349

@@ -366,7 +365,6 @@ def log_dict(logger: Logger, dictionary: dict, skip: list = None) -> None:
366365

367366

368367
def main():
369-
370368
args = parse_input_arguments()
371369
metadata_template = Metadata(args.input_files)
372370
logger.info("Starting MRC to Nexus conversion.")
@@ -478,7 +476,6 @@ def main():
478476

479477

480478
def parse_input_arguments():
481-
482479
msg = "Convert electron diffraction data from an MRC format "
483480
msg += "to a NeXus format"
484481
parser = ArgumentParser(description=msg, add_help=True)

src/nexgen/command_line/ED_nexus.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
def write_from_SINGLA(args):
28-
2928
singla_nexus_writer(
3029
args.master_file,
3130
args.det_distance,
@@ -60,7 +59,7 @@ def write_from_SINGLA_from_config(args):
6059
)
6160
ED_coord_system["convention"] = params.coord_system.convention
6261
else:
63-
logger.info("The following convention will be applied:\n" f"{ED_coord_system}")
62+
logger.info(f"The following convention will be applied:\n{ED_coord_system}")
6463

6564
if params.coord_system.origin:
6665
logger.info(

src/nexgen/command_line/I19_2_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def nexgen_writer(args):
307307
help="Data entry key of dataset in raw .h5 file. Defaults to data.",
308308
)
309309
parser_nex.add_argument(
310-
"-bits" "--bit-depth",
310+
"-bits--bit-depth",
311311
type=int,
312312
choices=[8, 16, 32],
313313
default=32,

src/nexgen/command_line/nexus_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ def _parse_cli() -> argparse.ArgumentParser:
393393
help="Data entry key of dataset in raw .h5 file. Defaults to data.",
394394
)
395395
nxmx_parser.add_argument(
396-
"-bits" "--bit-depth",
396+
"-bits",
397+
"--bit-depth",
397398
type=int,
398399
choices=[8, 16, 32],
399400
default=32,

src/nexgen/nxs_copy/copy_nexus.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ def images_nexus(
4141
original_nexus = Path(original_nexus).expanduser().resolve()
4242
nxs_filename = get_nexus_filename(data_file[0], copy=True)
4343
copy_logger.debug(f"New NeXus file name: {nxs_filename}")
44-
with h5py.File(original_nexus, "r") as nxs_in, h5py.File(nxs_filename, "x") as nxs_out:
44+
with (
45+
h5py.File(original_nexus, "r") as nxs_in,
46+
h5py.File(nxs_filename, "x") as nxs_out,
47+
):
4548
if simple_copy is True:
4649
# Copy the whole tree
4750
get_nexus_tree(nxs_in, nxs_out, skip=False)
@@ -92,9 +95,10 @@ def pseudo_events_nexus(
9295
original_nexus = Path(original_nexus).expanduser().resolve()
9396
nxs_filename = get_nexus_filename(data_file[0], copy=True)
9497
copy_logger.debug(f"New NeXus file name: {nxs_filename}")
95-
with h5py.File(original_nexus, "r") as nxs_in, h5py.File(
96-
nxs_filename, "x"
97-
) as nxs_out:
98+
with (
99+
h5py.File(original_nexus, "r") as nxs_in,
100+
h5py.File(nxs_filename, "x") as nxs_out,
101+
):
98102
nxs_out.attrs["default"] = "entry"
99103
# Copy the whole tree except for nxdata
100104
nxentry = get_nexus_tree(nxs_in, nxs_out)

src/nexgen/nxs_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434
"TransformationType",
3535
"Facility",
3636
"CetaDetector",
37-
"TVIPSDetector"
37+
"TVIPSDetector",
3838
]

src/nexgen/nxs_write/write_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ def mask_and_flatfield_writer_for_event_data(
239239
)
240240
else:
241241
NXclassUtils_logger.warning(
242-
f"No {dset_name} file found in working directory."
243-
"Writing an ExternalLink."
242+
f"No {dset_name} file found in working directory.Writing an ExternalLink."
244243
)
245244
file_loc = Path(dset_data_file)
246245
image_key = "image" if "tristan" in detector_name.lower() else "/"

0 commit comments

Comments
 (0)