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

Issue370 encoding cookie #371

Closed
wants to merge 24 commits into from

Conversation

tjguk
Copy link
Collaborator

@tjguk tjguk commented Mar 6, 2018

DO NOT MERGE

This is a PoC PR to test the approach advocated in #370

There are a number of unresolved issues, including:

(My answers in square brackets)

  • Do we inject a missing encoding cookie when we load? [Yes]
  • Do we honour/retain an existing encoding after loading? [No]
  • Does our [New] file become the single-line encoding cookie? [Not sure]
  • Do we add an explanatory comment to the end of the cookie line? [Yes]
  • What do we put on the error dialog?
  • What happens when we extract a hex file? [I've left it untouched for now; not sure]
  • What's the internal newline policy when manipulating the text [\n -- think it's worth specifying that somewhere; I note the newline='' from Maintain OS specific end-of-lines in code files. #133]

I've also added a "design note" under the new design folder in docs/. It's currently orphaned, but it's something I mooted a while ago and never got around to pursuing. If people like the idea, I'll add a design.rst to collect them together.

tjguk added 14 commits March 2, 2018 21:16
Refactor the file-saving mechanism so that it's consistent between, eg, save and autosave
Also slightly rework write_and_flush to reflect that it's being passed a file object, not a file descriptor

(In principle the os.fsync ought to need the fileobj to call its .fileno() method, but it seems to be silently converting under the covers. I've confirmed, on Windows at least, that the correct underlying system API [FlushBuffersFile] is being called against the correct file path).
@ntoll
Copy link
Member

ntoll commented Mar 6, 2018

This pull request introduces 1 alert when merging cd2b1ca into 8236b4b - view on lgtm.com

new alerts:

  • 1 for Encoding error

Comment posted by lgtm.com

@carlosperate
Copy link
Member

Haven't got a chance yet to look into the code or the CI failures, but if you are printing or displaying any type of unicode on AppVeyor is likely you'll have to add before running the tests:

- cmd: chcp 65001

@tjguk
Copy link
Collaborator Author

tjguk commented Mar 7, 2018

Thanks, @carlosperate . I'd leave it for now; I'm still working through issues. I pushed it just so others could see the approach / progress.

@tjguk tjguk mentioned this pull request Mar 7, 2018
mu/__init__.py Outdated

# Configure locale and language
# Define where the translation assets are to be found.
localedir = os.path.join('mu', 'locale')
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be the same as what is currently (in master) in app.py:

localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'locale'))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks; fixed

@ntoll
Copy link
Member

ntoll commented Mar 9, 2018

Wow... this is great work. Please do say when it's ready for review etc... :-)

@tjguk
Copy link
Collaborator Author

tjguk commented Mar 9, 2018

So obviously this PR has sprawled somewhat. I've yet to devise tests (or to fix those which now fail because of the injection of the encoding cookie). I've raised a couple separate issues to highlight issues which I've attempted to address in the course of the PR

Issue #380 -- standardising on \n for newlines internally to Mu while honouring the original data
Issue #379 -- refactoring gettext support so that logic.py can be imported on its own

I still have unresolved questions from above, and I'm conscious that this has turned into a set of changes which are likely to have widespread impact, as they address loading & saving of files. I haven't, for example, considered the effect on embedded boards where we're packaging and sending code down the wire.

My next step will be to add and fixup testing so we have a clean starting point for discussion, but please feel free to comment and/or challenge the approaches I've taken here. @carlosperate I'd like to hear from you especially on the line-ending change as I wasn't 100% sure of of the motivation behind your previous PR which used newline=""

@tjguk
Copy link
Collaborator Author

tjguk commented Mar 9, 2018

So testing just got a bit more complicated. Because I'm opening the file twice, once in binary, once in text mode, the current mock_open framework can't cope. (Took me about 20 mins to work out why my open(..., "rb") was not returning bytes!

I remember discussing before the question of mocking, tho' I can't find the conversation anywhere. For now, I'm going to try for a filesystem-based test for a couple of tests, leaving the mocks in place for the Qt stuff. If that is gives a cleaner result, I'll move to leave it in. Let's see..

@tjguk
Copy link
Collaborator Author

tjguk commented Mar 16, 2018

This got mired in push races and merge conflicts, so I'm replacing it by several, smaller PRs including #389 and #390 with more to come.

@tjguk tjguk closed this Mar 16, 2018
@tjguk tjguk mentioned this pull request Mar 20, 2018
@tjguk tjguk deleted the issue370-encoding-cookie branch December 11, 2020 08:18
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.

3 participants