@@ -19,12 +19,11 @@ def get_version(*file_paths):
1919 Extract the version string from the file at the given relative path fragments.
2020 """
2121 filename = os .path .join (os .path .dirname (__file__ ), * file_paths )
22- version_file = open (filename , encoding = 'utf-8' ).read ()
23- version_match = re .search (r"^__version__ = ['\"]([^'\"]*)['\"]" ,
24- version_file , re .M )
22+ version_file = open (filename , encoding = "utf-8" ).read ()
23+ version_match = re .search (r"^__version__ = ['\"]([^'\"]*)['\"]" , version_file , re .M )
2524 if version_match :
2625 return version_match .group (1 )
27- raise RuntimeError (' Unable to find version string.' )
26+ raise RuntimeError (" Unable to find version string." )
2827
2928
3029def load_requirements (* requirements_paths ):
@@ -49,14 +48,14 @@ def check_name_consistent(package):
4948 with extras we don't constrain it without mentioning the extras (since
5049 that too would interfere with matching constraints.)
5150 """
52- canonical = package .lower ().replace ('_' , '-' ).split ('[' )[0 ]
51+ canonical = package .lower ().replace ("_" , "-" ).split ("[" )[0 ]
5352 seen_spelling = by_canonical_name .get (canonical )
5453 if seen_spelling is None :
5554 by_canonical_name [canonical ] = package
5655 elif seen_spelling != package :
5756 raise RuntimeError (
5857 f'Encountered both "{ seen_spelling } " and "{ package } " in requirements '
59- ' and constraints files; please use just one or the other.'
58+ " and constraints files; please use just one or the other."
6059 )
6160
6261 requirements = {}
@@ -70,7 +69,9 @@ def check_name_consistent(package):
7069 % (re_package_name_base_chars , re_package_name_base_chars )
7170 )
7271
73- def add_version_constraint_or_raise (current_line , current_requirements , add_if_not_present ):
72+ def add_version_constraint_or_raise (
73+ current_line , current_requirements , add_if_not_present
74+ ):
7475 regex_match = requirement_line_regex .match (current_line )
7576 if regex_match :
7677 package = regex_match .group (1 )
@@ -79,11 +80,16 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n
7980 existing_version_constraints = current_requirements .get (package , None )
8081 # It's fine to add constraints to an unconstrained package,
8182 # but raise an error if there are already constraints in place.
82- if existing_version_constraints and existing_version_constraints != version_constraints :
83- raise BaseException (f'Multiple constraint definitions found for { package } :'
84- f' "{ existing_version_constraints } " and "{ version_constraints } ".'
85- f'Combine constraints into one location with { package } '
86- f'{ existing_version_constraints } ,{ version_constraints } .' )
83+ if (
84+ existing_version_constraints
85+ and existing_version_constraints != version_constraints
86+ ):
87+ raise BaseException (
88+ f"Multiple constraint definitions found for { package } :"
89+ f' "{ existing_version_constraints } " and "{ version_constraints } ".'
90+ f"Combine constraints into one location with { package } "
91+ f"{ existing_version_constraints } ,{ version_constraints } ."
92+ )
8793 if add_if_not_present or package in current_requirements :
8894 current_requirements [package ] = version_constraints
8995
@@ -94,8 +100,12 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n
94100 for line in reqs :
95101 if is_requirement (line ):
96102 add_version_constraint_or_raise (line , requirements , True )
97- if line and line .startswith ('-c' ) and not line .startswith ('-c http' ):
98- constraint_files .add (os .path .dirname (path ) + '/' + line .split ('#' )[0 ].replace ('-c' , '' ).strip ())
103+ if line and line .startswith ("-c" ) and not line .startswith ("-c http" ):
104+ constraint_files .add (
105+ os .path .dirname (path )
106+ + "/"
107+ + line .split ("#" )[0 ].replace ("-c" , "" ).strip ()
108+ )
99109
100110 # process constraint files: add constraints to existing requirements
101111 for constraint_file in constraint_files :
@@ -105,7 +115,9 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n
105115 add_version_constraint_or_raise (line , requirements , False )
106116
107117 # process back into list of pkg><=constraints strings
108- constrained_requirements = [f'{ pkg } { version or "" } ' for (pkg , version ) in sorted (requirements .items ())]
118+ constrained_requirements = [
119+ f"{ pkg } { version or '' } " for (pkg , version ) in sorted (requirements .items ())
120+ ]
109121 return constrained_requirements
110122
111123
@@ -119,48 +131,53 @@ def is_requirement(line):
119131 """
120132 # UPDATED VIA SEMGREP - if you need to remove/modify this method remove this line and add a comment specifying why
121133
122- return line and line .strip () and not line .startswith (('-r' , '#' , '-e' , 'git+' , '-c' ))
134+ return (
135+ line and line .strip () and not line .startswith (("-r" , "#" , "-e" , "git+" , "-c" ))
136+ )
123137
124138
125- VERSION = get_version (' edx_api_doc_tools' , ' __init__.py' )
139+ VERSION = get_version (" edx_api_doc_tools" , " __init__.py" )
126140
127- if sys .argv [- 1 ] == ' tag' :
141+ if sys .argv [- 1 ] == " tag" :
128142 print ("Tagging the version on github:" )
129143 os .system ("git tag -a %s -m 'version %s'" % (VERSION , VERSION ))
130144 os .system ("git push --tags" )
131145 sys .exit ()
132146
133- README = open (os .path .join (os .path .dirname (__file__ ), 'README.rst' ), encoding = 'utf-8' ).read ()
134- CHANGELOG = open (os .path .join (os .path .dirname (__file__ ), 'CHANGELOG.rst' ), encoding = 'utf-8' ).read ()
147+ README = open (
148+ os .path .join (os .path .dirname (__file__ ), "README.rst" ), encoding = "utf-8"
149+ ).read ()
150+ CHANGELOG = open (
151+ os .path .join (os .path .dirname (__file__ ), "CHANGELOG.rst" ), encoding = "utf-8"
152+ ).read ()
135153
136154setup (
137- name = ' edx-api-doc-tools' ,
155+ name = " edx-api-doc-tools" ,
138156 version = VERSION ,
139157 description = "Tools for writing and generating API documentation for edX REST APIs" ,
140- long_description = README + ' \n \n ' + CHANGELOG ,
158+ long_description = README + " \n \n " + CHANGELOG ,
141159 long_description_content_type = "text/x-rst" ,
142- author = ' Open edX Project' ,
143- author_email = ' oscm@openedx.org' ,
144- url = ' https://github.com/openedx/api-doc-tools' ,
160+ author = " Open edX Project" ,
161+ author_email = " oscm@openedx.org" ,
162+ url = " https://github.com/openedx/api-doc-tools" ,
145163 packages = [
146- ' edx_api_doc_tools' ,
164+ " edx_api_doc_tools" ,
147165 ],
148166 include_package_data = True ,
149- install_requires = load_requirements (' requirements/base.in' ),
167+ install_requires = load_requirements (" requirements/base.in" ),
150168 license = "Apache Software License 2.0" ,
151169 zip_safe = False ,
152- keywords = ' Django edx' ,
170+ keywords = " Django edx" ,
153171 classifiers = [
154- 'Development Status :: 3 - Alpha' ,
155- 'Framework :: Django' ,
156- 'Framework :: Django :: 4.2' ,
157- 'Framework :: Django :: 5.2' ,
158- 'Intended Audience :: Developers' ,
159- 'License :: OSI Approved :: Apache Software License' ,
160- 'Natural Language :: English' ,
161- 'Programming Language :: Python :: 3' ,
162- 'Programming Language :: Python :: 3.8' ,
163- 'Programming Language :: Python :: 3.11' ,
164- 'Programming Language :: Python :: 3.12' ,
172+ "Development Status :: 3 - Alpha" ,
173+ "Framework :: Django" ,
174+ "Framework :: Django :: 4.2" ,
175+ "Framework :: Django :: 5.2" ,
176+ "Intended Audience :: Developers" ,
177+ "License :: OSI Approved :: Apache Software License" ,
178+ "Natural Language :: English" ,
179+ "Programming Language :: Python :: 3" ,
180+ "Programming Language :: Python :: 3.11" ,
181+ "Programming Language :: Python :: 3.12" ,
165182 ],
166183)
0 commit comments