Skip to content

Python 3 support - #77

Merged
dnadeau-lanl merged 55 commits into
spacepy:masterfrom
jtniehof:py3k
Apr 5, 2021
Merged

dnadeau-lanl merged 55 commits into
spacepy:masterfrom
jtniehof:py3k

Conversation

@jtniehof

@jtniehof jtniehof commented Apr 5, 2021 •

Copy link
Copy Markdown
Member

This PR provides Python 3 support and fixes a couple of small issues that were found along the way, mostly with scripts. Python 2 is still supported (same code).

The "port" consisted of:

  • Get the unit tests all working in 3 (and still in 2). In some cases tests failed not because the code was bad, but because the ordering of things was different in Python 3, for cases where ordering was not guaranteed. Relates to Guarantee ordering of input files #69 and probably some issues @dnadeau-lanl was having.
  • Process all PSP/ISOIS 2018 data using the new dbprocessing, in both Python 2 and 3. Outputs were compared, no changes.
  • Every single script in the scripts directory was checked with 2to3 (although the output was not blindly accepted), then run and patched up if the output wasn't the same in 2 and 3. For a lot of these, there were issues where Python 3 shuts down the interpreter in a different order. If a DButils instance is still instantiated at shutdown, its __del__ method may be called after sqlalchemy is shut down, and so the CloseDB method fails. So many scripts were updated to explicitly delete the DButils instance if it didn't go out of scope before the end of the script.

PR Checklist

  • Pull request has descriptive title
  • Pull request gives overview of changes
  • New code has inline comments where necessary
  • Any new modules, functions or classes have docstrings consistent with dbprocessing style
  • (N/A) Major new functionality has appropriate Sphinx documentation
  • Added an entry to release notes if fixing a major bug or providing a major new feature
  • New features and bug fixes should have unit tests
  • (N/A) Relevant issues are linked in the description (use Closes # if this PR closes the issue, or some other reference, such as See # if it is related in some other way)

jtniehof added 30 commits April 5, 2021 10:57
 * Attaching DButils bound methods to the Processqueue table instance meant
   Processqueue kept a reference to DButils, and DButils had a reference
   to that instance, thus circular reference and DButils.__del__ was
   never called, and database session not closed. Only showed as an
   error in Python 3, but always there.
 * The Processqueue object was never used outside of DButils, and these
   methods only work in conjunction with DButils, so making them explicit
   DButils methods instead of pseudo-methods of Processqueue is reasonable.
 * long are change to int; this is probably actually a better match, since
   the database types were probably not Python longs (which are not the
   same as C longs)
 * Several return types are forced to list instead of iterable. These maybe
   would be managable by making sure the caller accepts an iterable instead
   of assuming a list, but the API has been using lists pretty consistently,
   and that also helps with (e.g.) the database query being completed and
   all data returned.
 * Output needs to be a list anyhow. There are other places in the code
   claiming map is faster but that needs to be evaluated (particularly
   on Python 3) and it's usually not the case with a lambda.
 * Removes all the metaclass programming at the cost of ()
 * Not tested on Python 3, just doing a scrub.
  * Explicitly close a handler on file change
  * Explicitly specify an encoding for the handler; this seems to avoid
    issues with logging from DButils.__del_ failing on interpreter exit
 * Nested exception handling results in messy traceback in Python 3
jtniehof added 19 commits April 5, 2021 10:58
 * getAllFilenames may have been updated since this script was updated,
   since it seemed to be expecting something where the filename
   was the first entry, without the full path, and what it was getting
   was the full path by itself. So it always tried to delete "/"
 * Leaving the dbutils instance to be cleaned up at interpreter exit
   means the __del__ method can't cleanly close db, so close before that.
 * Similarly, don't exit() if nothing to reprocess, continue and display
   "0 files to reprocess".
 * Was saying product, but actually done by instrument
 * None is no longer comparable
@jtniehof
jtniehof force-pushed the py3k branch 2 times, most recently from fd897ce to 3b9db83 Compare April 5, 2021 15:59
jtniehof added 3 commits April 5, 2021 12:14
 * Also grab latest Python (2 and 3), not specific version
 * Remove Inspector.EphemeralCallable reference, as it's gone
 * Fix format of a note in ProcessqueueRawadd; it was always bad but
   probably the docstring wasn't being built.
@jtniehof
jtniehof marked this pull request as ready for review April 5, 2021 16:28
@jtniehof
jtniehof requested a review from dnadeau-lanl April 5, 2021 16:28
@dnadeau-lanl
dnadeau-lanl merged commit 29b6678 into spacepy:master Apr 5, 2021
@jtniehof
jtniehof deleted the py3k branch April 5, 2021 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants