summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/apigen.py24
-rwxr-xr-xtools/build_modref_templates.py4
-rwxr-xr-xtools/build_release2
-rwxr-xr-xtools/ex2rst4
-rwxr-xr-xtools/github_stats.py14
-rwxr-xr-xtools/gitwash_dumper.py4
-rwxr-xr-xtools/make_examples.py43
-rwxr-xr-xtools/release2
-rwxr-xr-xtools/sneeze.py50
-rwxr-xr-xtools/update_requirements.py36
10 files changed, 85 insertions, 98 deletions
diff --git a/tools/apigen.py b/tools/apigen.py
index afce9da..e72cebe 100644
--- a/tools/apigen.py
+++ b/tools/apigen.py
@@ -168,7 +168,7 @@ class ApiDocWriter(object):
functions, classes = self._parse_lines(f)
f.close()
return functions, classes
-
+
def _parse_lines(self, linesource):
''' Parse lines of text for functions and classes '''
functions = []
@@ -206,18 +206,18 @@ class ApiDocWriter(object):
# get the names of all classes and functions
functions, classes = self._parse_module(uri)
if not len(functions) and not len(classes):
- print 'WARNING: Empty -',uri # dbg
+ print('WARNING: Empty -',uri) # dbg
return ''
# Make a shorter version of the uri that omits the package name for
- # titles
+ # titles
uri_short = re.sub(r'^%s\.' % self.package_name,'',uri)
-
+
ad = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n'
chap_title = uri_short
- ad += (chap_title+'\n'+ self.rst_section_levels[1] * len(chap_title)
- + '\n\n')
+ ad += (chap_title+'\n' + self.rst_section_levels[1] *
+ len(chap_title) + '\n\n')
# Set the chapter title to read 'module' for all modules except for the
# main packages
@@ -290,7 +290,7 @@ class ApiDocWriter(object):
elif match_type == 'package':
patterns = self.package_skip_patterns
else:
- raise ValueError('Cannot interpret match type "%s"'
+ raise ValueError('Cannot interpret match type "%s"'
% match_type)
# Match to URI without package name
L = len(self.package_name)
@@ -306,7 +306,7 @@ class ApiDocWriter(object):
return True
def discover_modules(self):
- ''' Return module sequence discovered from ``self.package_name``
+ ''' Return module sequence discovered from ``self.package_name``
Parameters
@@ -327,7 +327,7 @@ class ApiDocWriter(object):
>>> dw.package_skip_patterns.append('\.util$')
>>> 'sphinx.util' in dw.discover_modules()
False
- >>>
+ >>>
'''
modules = [self.package_name]
# raw directory parsing
@@ -350,7 +350,7 @@ class ApiDocWriter(object):
self._survives_exclude(module_uri, 'module')):
modules.append(module_uri)
return sorted(modules)
-
+
def write_modules_api(self, modules,outdir):
# write the list
written_modules = []
@@ -375,7 +375,7 @@ class ApiDocWriter(object):
outdir : string
Directory name in which to store files
We create automatic filenames for each module
-
+
Returns
-------
None
@@ -389,7 +389,7 @@ class ApiDocWriter(object):
# compose list of modules
modules = self.discover_modules()
self.write_modules_api(modules,outdir)
-
+
def write_index(self, outdir, froot='gen', relative_to=None):
"""Make a reST API index file from written files
diff --git a/tools/build_modref_templates.py b/tools/build_modref_templates.py
index be584b6..284fd21 100755
--- a/tools/build_modref_templates.py
+++ b/tools/build_modref_templates.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""Script to auto-generate our API docs.
"""
# stdlib imports
@@ -16,4 +16,4 @@ if __name__ == '__main__':
]
docwriter.write_api_docs(outdir)
docwriter.write_index(outdir, 'gen', relative_to='api')
- print '%d files written' % len(docwriter.written_modules)
+ print('%d files written' % len(docwriter.written_modules))
diff --git a/tools/build_release b/tools/build_release
index 00c16ab..2bfd958 100755
--- a/tools/build_release
+++ b/tools/build_release
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""Nitime release build script.
"""
from toollib import *
diff --git a/tools/ex2rst b/tools/ex2rst
index 59207a3..8d55dab 100755
--- a/tools/ex2rst
+++ b/tools/ex2rst
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Note: this file is copied (possibly with minor modifications) from the
# sources of the PyMVPA project - http://pymvpa.org. It remains licensed as
@@ -99,7 +99,7 @@ def exfile2rst(filename):
proc_line = None
# handle doc start
if not indocs:
- # guarenteed to start with """
+ # guaranteed to start with """
if len(cleanline) > 3 \
and (cleanline.endswith('"""') \
or cleanline.endswith("'''")):
diff --git a/tools/github_stats.py b/tools/github_stats.py
index c214872..543971a 100755
--- a/tools/github_stats.py
+++ b/tools/github_stats.py
@@ -1,18 +1,19 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""Simple tools to query github.com and gather stats about issues.
"""
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
-from __future__ import print_function
+
import json
import re
import sys
+import codecs
from datetime import datetime, timedelta
-from urllib import urlopen
+from urllib.request import urlopen
#-----------------------------------------------------------------------------
# Globals
@@ -42,7 +43,8 @@ def get_paged_request(url):
results = []
while url:
print("fetching %s" % url, file=sys.stderr)
- f = urlopen(url)
+ reader = codecs.getreader("utf-8")
+ f = reader(urlopen(url))
results.extend(json.load(f))
links = parse_link_header(f.headers)
url = links.get('next')
@@ -76,7 +78,7 @@ def is_pull_request(issue):
return 'pull_request_url' in issue
-def issues_closed_since(period=timedelta(days=730), project="nipy/nitime", pulls=False):
+def issues_closed_since(period=timedelta(days=365), project="nipy/nitime", pulls=False):
"""Get all issues closed since a particular point in time. period
can either be a datetime object, or a timedelta object. In the
latter case, it is used as a time before the present."""
@@ -122,7 +124,7 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
days = int(sys.argv[1])
else:
- days = 730
+ days = 310
# turn off to play interactively without redownloading, use %run -i
if 1:
diff --git a/tools/gitwash_dumper.py b/tools/gitwash_dumper.py
index 000245a..b002f65 100755
--- a/tools/gitwash_dumper.py
+++ b/tools/gitwash_dumper.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
''' Checkout gitwash repo into directory and do search replace on name '''
import os
@@ -84,7 +84,7 @@ def copy_replace(replace_pairs,
for rep_glob in rep_globs:
fnames += fnmatch.filter(out_fnames, rep_glob)
if verbose:
- print '\n'.join(fnames)
+ print('\n'.join(fnames))
for fname in fnames:
filename_search_replace(replace_pairs, fname, False)
for in_exp, out_exp in renames:
diff --git a/tools/make_examples.py b/tools/make_examples.py
index 97ce75a..0f1ae05 100755
--- a/tools/make_examples.py
+++ b/tools/make_examples.py
@@ -1,11 +1,9 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""Run the py->rst conversion and run all examples.
This also creates the index.rst file appropriately, makes figures, etc.
"""
-#-----------------------------------------------------------------------------
# Library imports
-#-----------------------------------------------------------------------------
# Stdlib imports
import os
@@ -17,17 +15,16 @@ from glob import glob
# We must configure the mpl backend before making any further mpl imports
import matplotlib
-matplotlib.use('Agg')
import matplotlib.pyplot as plt
-
from matplotlib._pylab_helpers import Gcf
# Local tools
from toollib import *
-#-----------------------------------------------------------------------------
-# Globals
-#-----------------------------------------------------------------------------
+# Set MPL backend:
+matplotlib.use('Agg')
+
+# Globals:
examples_header = """
@@ -41,20 +38,22 @@ Examples
.. toctree::
:maxdepth: 2
-
-
+
+
"""
-#-----------------------------------------------------------------------------
-# Function defintions
-#-----------------------------------------------------------------------------
+# Function definitions::
# These global variables let show() be called by the scripts in the usual
# manner, but when generating examples, we override it to write the figures to
# files with a known name (derived from the script name) plus a counter
figure_basename = None
-# We must change the show command to save instead
+# We must change the show command to save instead
def show():
+ """
+ This over-rides matplotlibs `show` function to save instead of rendering to
+ the screen.
+ """
allfm = Gcf.get_all_fig_managers()
for fcount, fm in enumerate(allfm):
fm.canvas.figure.savefig('%s_%02i.png' %
@@ -63,9 +62,7 @@ def show():
_mpl_show = plt.show
plt.show = show
-#-----------------------------------------------------------------------------
-# Main script
-#-----------------------------------------------------------------------------
+# Main script::
# Work in examples directory
cd('examples')
@@ -79,9 +76,9 @@ sh('../../tools/ex2rst --project Nitime --outdir . .')
index = open('index.rst', 'w')
index.write(examples_header)
for name in [os.path.splitext(f)[0] for f in glob('*.rst')]:
- #Don't add the index in there to avoid sphinx errors and don't add the
- #note_about examples again (because it was added at the top):
- if name not in(['index','note_about_examples']):
+ # Don't add the index in there to avoid sphinx errors and don't add the
+ # note_about examples again (because it was added at the top):
+ if name not in(['index', 'note_about_examples']):
index.write(' %s\n' % name)
index.close()
# Execute each python script in the directory.
@@ -92,7 +89,9 @@ else:
os.mkdir('fig')
for script in glob('*.py'):
+ print(script)
figure_basename = pjoin('fig', os.path.splitext(script)[0])
- execfile(script)
+
+ with open(script) as f:
+ exec(f.read())
plt.close('all')
-
diff --git a/tools/release b/tools/release
index 26761a5..6d9d382 100755
--- a/tools/release
+++ b/tools/release
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""Nitime release script.
This should only be run at real release time.
diff --git a/tools/sneeze.py b/tools/sneeze.py
deleted file mode 100755
index c9cb6b9..0000000
--- a/tools/sneeze.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env python
-"""Script to run nose with coverage reporting without boilerplate params.
-
-Usage:
- sneeze test_coordinate_system.py
-
-Coverage will be reported on the module extracted from the test file
-name by removing the 'test_' prefix and '.py' suffix. In the above
-example, we'd get the coverage on the coordinate_system module. The
-test file is searched for an import statement containing the module
-name.
-
-The nose command would look like this:
-
-nosetests -sv --with-coverage --cover-package=nipy.core.reference.coordinate_system test_coordinate_system.py
-
-"""
-
-import re
-import os
-import sys
-import nose
-
-test_file = sys.argv[1]
-module = os.path.splitext(test_file)[0] # remove '.py' extension
-module = module.split('test_')[1] # remove 'test_' prefix
-regexp = "[\w\.]+%s"%module
-compexp = re.compile(regexp)
-
-cover_pkg = None
-fp = open(test_file, 'r')
-for line in fp:
- if line.startswith('from') or line.startswith('import'):
- pkg = re.search(regexp, line)
- if pkg:
- cover_pkg = pkg.group()
- break
-fp.close()
-
-if cover_pkg:
- cover_arg = '--cover-package=%s' % cover_pkg
- sys.argv += ['-sv', '--with-coverage', cover_arg]
- # Print out command for user feedback and debugging
- cmd = 'nosetests -sv --with-coverage %s %s' % (cover_arg, test_file)
- print cmd
- print
- nose.run()
-else:
- raise ValueError('Unable to find module %s imported in test file %s'
- % (module, test_file))
diff --git a/tools/update_requirements.py b/tools/update_requirements.py
new file mode 100755
index 0000000..92e9e83
--- /dev/null
+++ b/tools/update_requirements.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+import sys
+from pathlib import Path
+
+try:
+ import tomllib
+except ImportError:
+ import tomli as tomllib
+
+repo_root = Path(__file__).parent.parent
+pyproject_toml = repo_root / 'pyproject.toml'
+reqs = repo_root / 'requirements.txt'
+min_reqs = repo_root / 'min-requirements.txt'
+
+with open(pyproject_toml, 'rb') as fobj:
+ config = tomllib.load(fobj)
+ project = config['project']
+requirements = project['dependencies'] + project['optional-dependencies']['full']
+
+script_name = Path(__file__).relative_to(repo_root)
+
+lines = [
+ f'# Auto-generated by {script_name}',
+ '--only-binary numpy,scipy',
+ '--extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple',
+ '',
+]
+start = len(lines) - 1
+
+# Write requirements
+lines[start:-1] = requirements
+reqs.write_text('\n'.join(lines))
+
+# Write minimum requirements
+lines[start:-1] = [req.replace('>=', '==').replace('~=', '==') for req in requirements]
+min_reqs.write_text('\n'.join(lines))