Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update_cmds fixes for py3 #139

Merged
merged 3 commits into from
Nov 27, 2019
Merged

Update_cmds fixes for py3 #139

merged 3 commits into from
Nov 27, 2019

Conversation

taldcroft
Copy link
Member

@taldcroft taldcroft commented Sep 8, 2019

Fixes for kadi update_cmds to run correctly on Py3. Also includes minor flake8 fixes. Just one non-trivial fix related to the diffing and a bytes/unicode issue. (str() of a bytestring gives b'blah' not blah.)

Testing

On HEAD (kady) in ska3/flight

ska  # LEGACY ska
cd ~/tmp/kadi-test
python /proj/sot/ska/share/update_cmds.py --start=2015:001 --stop=2015:030
# Creates local cmds.h5 and cmds.pkl for the date range using the Ska2-flight kadi.

On local machine (MacOS) in py3-compat branch

ska3  # Activate ska3 environment
cd ~/git/kadi
git checkout py3-compat
cp ~/git/ska_testr/packages/kadi/write_events_cmds.py write_cmds.py
  • Edit write_cmds.py to comment out writing the events and fix a Py3-compatibility
    problem (os.path cannot take None in Py3)
rm cmds.*
./update_cmds.py --start=2015:001 --stop=2015:030 --mp-dir ~/ska/data/mpcrit1/mplogs
python write_cmds.py  --start=2014:001 --stop=2016:001
# Creates cmds.txt which is a plain-text version of the commands

mkdir cmds-ska2
cd cmds-ska2
scp 'kady:tmp/kadi-test/cmds.*' ./
python ../write_cmds.py --start=2014:001 --stop=2016:001

diff cmds.txt ../cmds.txt
# Compare cmds from local branch to ska2-flight version
#  ** NO DIFF **

@taldcroft taldcroft force-pushed the py3-compat branch 2 times, most recently from 921746d to a51f3eb Compare September 22, 2019 16:48
if 'params' in cmd:
params = new_cmd['params']
for key, val in cmd['params'].items():
key = str(key)
if isinstance(val, six.string_types):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous logic was that val might be a Py2 str or unicode, and it was necessary to coerce to str. See the dump above of an example of the data structure. In Py3 none of this needed and instead we just try using the numpy item() method to coerce to pure-Python.

@taldcroft taldcroft requested a review from javierggt September 22, 2019 17:20
@taldcroft taldcroft changed the title WIP: update_cmds fixes for py3 Update_cmds fixes for py3 Sep 22, 2019
@taldcroft
Copy link
Member Author

This is tested (and the testing documented) to my satisfaction, so merging. Not clear yet if this will go as a release or if we should bundle #143 (which is a much bigger change and requires django 2.2).

@taldcroft taldcroft merged commit e5d630b into master Nov 27, 2019
@taldcroft taldcroft deleted the py3-compat branch December 1, 2019 18:50
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.

1 participant