3
3
# SPDX - License - Identifier: GPL-3.0-or-later
4
4
from __future__ import annotations
5
5
6
- import fnmatch
7
6
import importlib
8
- import os
9
7
import platform
10
8
import subprocess
11
9
from distutils .core import Command
17
15
18
16
from setuptools import find_packages , setup
19
17
20
- THIS_PATH = os .path .dirname (__file__ )
21
-
22
- versions = SourceFileLoader ('versions' , 'mantidimaging/__init__.py' ).load_module ()
18
+ THIS_PATH = Path (__file__ ).parent
19
+ versions = SourceFileLoader ('versions' , str (THIS_PATH / 'mantidimaging' / '__init__.py' )).load_module ()
23
20
24
21
25
22
class GenerateReleaseNotes (Command ):
@@ -33,7 +30,8 @@ def finalize_options(self):
33
30
pass
34
31
35
32
def run (self ):
36
- spec = importlib .util .spec_from_file_location ('release_notes' , 'docs/ext/release_notes.py' )
33
+ spec = importlib .util .spec_from_file_location ('release_notes' ,
34
+ str (THIS_PATH / 'docs' / 'ext' / 'release_notes.py' ))
37
35
release_notes = importlib .util .module_from_spec (spec )
38
36
spec .loader .exec_module (release_notes )
39
37
@@ -59,20 +57,16 @@ def finalize_options(self):
59
57
pass
60
58
61
59
@staticmethod
62
- def compile_single_file (ui_filename ):
60
+ def compile_single_file (ui_filename : Path ):
63
61
from PyQt5 import uic
64
62
65
- py_filename = os . path . splitext ( ui_filename )[ 0 ] + ".py"
66
- with open (py_filename , "w" ) as py_file :
67
- uic .compileUi (ui_filename , py_file )
63
+ py_filename = ui_filename . with_suffix ( ".py" )
64
+ with py_filename . open ("w" ) as py_file :
65
+ uic .compileUi (str ( ui_filename ) , py_file )
68
66
69
67
@staticmethod
70
- def find_ui_files ():
71
- matches = []
72
- for root , _ , filenames in os .walk ("./mantidimaging/" ):
73
- for filename in fnmatch .filter (filenames , "*.ui" ):
74
- matches .append (os .path .join (root , filename ))
75
- return matches
68
+ def find_ui_files () -> list [Path ]:
69
+ return list (Path ("./mantidimaging" ).rglob ("*.ui" ))
76
70
77
71
def run (self ):
78
72
ui_files = self .find_ui_files ()
@@ -98,13 +92,12 @@ def finalize_options(self):
98
92
if self .conda is None :
99
93
raise ValueError ("Could not find conda or mamba" )
100
94
101
- def count_indent (self , line ) :
95
+ def count_indent (self , line : str ) -> int :
102
96
leading_spaces = len (line ) - len (line .lstrip (" " ))
103
97
return leading_spaces // 2
104
98
105
- def get_package_depends (self ):
106
- # Parse the metafile manually, do avoid needing a nonstandard library
107
- meta_file = Path (__file__ ).parent / "conda" / "meta.yaml"
99
+ def get_package_depends (self ) -> list [str ]:
100
+ meta_file = THIS_PATH / "conda" / "meta.yaml"
108
101
with meta_file .open () as meta_file_fh :
109
102
section = []
110
103
parsed_values = defaultdict (list )
@@ -122,9 +115,10 @@ def get_package_depends(self):
122
115
parsed_values ["." .join (section )].append (line .strip (" -\n " ))
123
116
return parsed_values ["requirements.run" ]
124
117
125
- def make_environment_file (self , extra_deps ) :
126
- dev_env_file = Path ( __file__ ). parent / "environment-dev.yml"
118
+ def make_environment_file (self , extra_deps : list [ str ]) -> str :
119
+ dev_env_file = THIS_PATH / "environment-dev.yml"
127
120
output_env_file = tempfile .NamedTemporaryFile ("wt" , delete = False , suffix = ".yaml" )
121
+
128
122
in_dependencies_section = False
129
123
with dev_env_file .open () as dev_env_file_fh :
130
124
for line in dev_env_file_fh :
@@ -142,17 +136,21 @@ def make_environment_file(self, extra_deps):
142
136
143
137
def run (self ):
144
138
existing_envs_output = subprocess .check_output ([self .conda , "env" , "list" ], encoding = "utf8" )
145
- if any (line .startswith ("mantidimaging-dev " ) for line in existing_envs_output .split ( " \n " )):
139
+ if any (line .startswith ("mantidimaging-dev " ) for line in existing_envs_output .splitlines ( )):
146
140
print ("Removing existing mantidimaging-dev environment" )
147
- command_conda_env_remove = [self .conda , "env" , "remove" , "-n" , "mantidimaging-dev" ]
148
- subprocess .check_call (command_conda_env_remove )
141
+ subprocess .check_call ([self .conda , "env" , "remove" , "-n" , "mantidimaging-dev" ])
149
142
extra_deps = self .get_package_depends ()
150
143
env_file_path = self .make_environment_file (extra_deps )
151
144
print ("Creating conda environment for development" )
152
- command_conda_env = [self .conda , "env" , "create" , "-f" , env_file_path ]
153
- subprocess . check_call ( command_conda_env )
154
- os . remove ( env_file_path )
145
+ subprocess . check_call ( [self .conda , "env" , "create" , "-f" , env_file_path ])
146
+ Path ( env_file_path ). unlink ( )
147
+
155
148
149
+ try :
150
+ long_description = (THIS_PATH / "README.md" ).read_text (encoding = "utf-8" )
151
+ except FileNotFoundError :
152
+ long_description = ""
153
+ print ("Warning: README.md not found. Using default description for long_description" )
156
154
157
155
setup (
158
156
name = "mantidimaging" ,
@@ -169,7 +167,8 @@ def run(self):
169
167
url = "https://github.com/mantidproject/mantidimaging" ,
170
168
license = "GPL-3.0" ,
171
169
description = "Graphical toolkit for neutron imaging" ,
172
- long_description = open ("README.md" ).read (),
170
+ long_description = long_description ,
171
+ long_description_content_type = "text/markdown" ,
173
172
classifiers = [
174
173
"Programming Language :: Python :: 3.10" ,
175
174
"Natural Language :: English" ,
0 commit comments