Skip to content

Simplify pyrepl.ts and kill base.ts#884

Merged
antocuni merged 55 commits into
mainfrom
antocuni/kill-base-ts
Oct 27, 2022
Merged

Simplify pyrepl.ts and kill base.ts#884
antocuni merged 55 commits into
mainfrom
antocuni/kill-base-ts

Conversation

@antocuni

@antocuni antocuni commented Oct 24, 2022

Copy link
Copy Markdown
Contributor

Yet another of my refactorings. This PR does two things which are related but also clearly separated, and probably it would have been better to make two different ones, but too late now.

I suggest reviewers to review the two parts separately, it is probably easier to understand what I did:

  1. Merge&simplify base.ts and pyreply.ts in the first 25 commits (from 9c225b2 to 0c661f5)

BaseEvalElement was used only by pyrepl now. By merging them I could simplify a lot the logic and kill a lot of code. In the process, I also improved and extented the py-repl integration tests, to ensure that I didn't break anything.

  1. Reorder the code in pyrepl.ts in the next 29 commits (from 0a9e19d to the end)

this part of the PR doesn't change much of the concrete logic: it's just a sequence of renaming variables, moving code around, group code into functions, killing code which is no longer needed (you might also want to look at the commits one by one, every of them is self-contained and passed the tests). But the end result is much better and nicer to read, IMHO.

Other highlights:

  • py-repl now uses the new logic in pyexec.ts to run the code
  • after PR Add display impl, rm outputManage, print and console.log default to browser console #749 py-repl no longer displayed the result of the last evaluated expression (e.g. if you typed 42 and run it, it displayed nothing). This PR re-introduces this behavior, which is what you would expect by a REPL.
  • I improved the pytest --dev option: now it implies --no-fake-server so that sourcemaps works automatically
  • many many tests but the autogenerate functionality is untested. It should probably be improved/refactored by another PR
  • I improved the names of the CSS classes to be more consistent

A possibly controversial change:

  • I killed pyrepl.test.ts: the old tests didn't check anything useful, just that some of the attributes existed on the instance, but after the refactoring I killed most of them and they were impossible to test in that way. I claim that this style of unit test doesn't really add much value if you have good integration tests (which now we have) and trying to revive them was not worth the hassle. This is the relevant commit: 8e8ed9c

We want to run the most basic tests first: so first we check that we can
print(), and only later we test the behavior of display(), which is much more
complex.

Also, add a test to ensure that we can load&execute code which was typed
inside the <py-repl>

This simplifies the rest of the tests because we can put the code directly in
the tag instead of having to use .type() all the times
Comment thread pyscriptjs/src/components/pyrepl.ts
Comment thread pyscriptjs/src/components/pyrepl.ts
editorLabel.setAttribute('style', labelStyle);
editorLabel.htmlFor = 'code-editor';
boxDiv.append(editorLabel);
boxDiv.appendChild(editorDiv);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So, this means we always create the output div, even if we have an explicit output attribute?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I did it intentionally because it simplify handling the case in which output=... points to a non-existent ID:

if (el === null) {
const err = `py-repl ERROR: cannot find the output element #${outputID} in the DOM`
this.outDiv.innerText = err;
return undefined;
}

I think that an empty div should not cause problems, does it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think it does and I'm probably too picky here. It just leaves an unused empty tag which I don't think is a big deal.

@fpliger

fpliger commented Oct 25, 2022

Copy link
Copy Markdown
Contributor

I know this PR is WIP but thought I'd leave early feedback. Great work ;)

@antocuni antocuni changed the title WIP: Merge&simplify base.ts and pyrepl.ts Simplify pyrepl.ts and kill base.ts Oct 26, 2022
@antocuni antocuni marked this pull request as ready for review October 26, 2022 08:53
@antocuni

Copy link
Copy Markdown
Contributor Author

I know this PR is WIP but thought I'd leave early feedback. Great work ;)

actually when you reviewed it it was almost ready, so you saw basically everything. But see the top message now, it's probably worth to look at two sets of commits separately.

@@ -8,61 +8,78 @@ class TestPyRepl(PyScriptTest):
def test_repl_loads(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This entire file looks good to me 👍
Should I review the rest too?

@antocuni antocuni Oct 26, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This entire file looks good to me

🎉

Should I review the rest too?

reviews are always welcome :)

@tedpatrick

Copy link
Copy Markdown
Contributor

solid

Comment thread pyscriptjs/src/components/pyrepl.ts Outdated

@fpliger fpliger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 🚀 🚀 🚀

Co-authored-by: woxtu <woxtup@gmail.com>
@antocuni antocuni merged commit 214e395 into main Oct 27, 2022
@antocuni antocuni deleted the antocuni/kill-base-ts branch October 27, 2022 08:10
antocuni added a commit that referenced this pull request Oct 31, 2022
antocuni added a commit that referenced this pull request Oct 31, 2022
What is not tested is broken man_facepalming
Test&fix <py-repl auto-generate=true> which was broken by PR #884
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants