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

A port of the nbb nrepl-server to basilisp #723

Merged
merged 12 commits into from
Dec 28, 2023

Conversation

ikappaki
Copy link
Contributor

@ikappaki ikappaki commented Oct 15, 2023

Hi,

could you please review patch to port nbb's build in nrepl-server to basilisp contrib. It addresses #412.

nbb has the same EPL-1.0 license as basilisp so I believe using its code as the base for this PR should not cause licensing issues.

The nbb bencode module which is a dependency was ported as well. Extensive tests were written for both.

The server has been tested to work with both CIDER and Calva in VS-Code.

The server can be invoked with baslisp nrepl-server:

$ poetry run basilisp nrepl-server -h
usage: basilisp.cmd nrepl-server [-h] [--host HOST] [--port PORT] [--port-filepath PORT_FILEPATH]

Start the nREPL server.

optional arguments:
  -h, --help            show this help message and exit
  --host HOST           the interface address to bind to, defaults to 127.0.0.1.
  --port PORT           the port to connect to, defaults to 0 (random available port).
  --port-filepath PORT_FILEPATH
                        the file path where the server port number is output to, defaults to ".nrepl-port".

Several fixes were required to make it work, which are included as separate commits in this PR prior to the main bencode and nrepl-server commits. They address the following issues

support for the basilisp.stacktrace/print-cause-trace is also added because it is requested by CIDER when an exception is thrown to show to the user, which is essential, it partially addresses #721.

In addition, two issues were observed while running the tests in CI

  • The 1.6.0 was released few days ago and complains for an additional type error in the generator, which is now ignored with this patch
Traceback (most recent call last):
#...
py311-mypy: commands[0]> mypy --config-file=C:\src\basilisp/pyproject.toml -p basilisp
src\basilisp\lang\compiler\generator.py:3530: error: Argument 1 to "fields" has incompatible type "type[IType]"; expected an attrs class  [misc]
src\basilisp\lang\compiler\generator.py:3530: note: Error code "misc" not covered by "type: ignore" comment
  • The nrepl-server tests which are using threads were failing due to trying to release an rlock which has been already released whose essence is captured in potential issue with readerwritelocks usage in basilisp core libs #722, and is fixed with this patch as described in the ticket by using with self._lock.gen_rlock() instead of a single instance of with self._rlock(). The error was
    File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/basilisp/lang/runtime.py", line 706, in find
    return v
   File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/readerwriterlock/rwlock.py", line 49, in __exit__
    self.release()
   File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/readerwriterlock/rwlock.py", line 344, in release
    if not self.v_locked: raise RELEASE_ERR_CLS(RELEASE_ERR_MSG)
 RuntimeError: release unlocked lock

I understand this could be a lot to go through and there likely to be multiple iterations while I update the code with your feedback, of which I'm looking forward to.

I have not written a nrepl-server section for the manual yet. I plan to do this after a successful review, and will also update the changelog.

Thanks

@ikappaki ikappaki force-pushed the contrib/nrepl-server branch 4 times, most recently from d9517cc to 2a5923e Compare October 18, 2023 20:14
@ikappaki ikappaki force-pushed the contrib/nrepl-server branch from bb72b76 to 3f35756 Compare December 6, 2023 23:06
@ikappaki
Copy link
Contributor Author

ikappaki commented Dec 6, 2023

Rebased from main to resolve conflicts and updated changelog with issue numbers.

@chrisrink10
Copy link
Member

This is definitely very cool and I'm excited to see how this works.

Would it be possible to start breaking off the smaller bug fixes as individual PRs so this PR is just the nrepl server? Most of them seem straightforward enough on their own.

My one reservation with using code from another project is that I assume we'll need to correctly attribute the source of that code to its original author(s) and I'm not 100% sure how to do that. Perhaps a copyright notice at the top of the file attributing that author and mentioning the license is the same as the main project.

chrisrink10 pushed a commit that referenced this pull request Dec 14, 2023
…727)

Hi can you please review patch to fix the problem of `ns` becoming
unavailable after executing `in-ns` in the context of the `eval`
operation. It addresses #718.

(part of breaking the individual bugfixes from #723)

thanks

Co-authored-by: ikappaki <[email protected]>
chrisrink10 pushed a commit that referenced this pull request Dec 14, 2023
Hi,

could you please review patch to fix issue with import name aliasing in
the context of an `eval` operation. It addresses #719.

(part of breaking the individual bugfixes from
#723)

Thanks.

Co-authored-by: ikappaki <[email protected]>
chrisrink10 added a commit that referenced this pull request Dec 14, 2023
Hi,

could you please consider patch to fix an issue with with `ns-resolve`
erroring out on macros. It addresses #720.

(part of breaking the individual bugfixes from
#723)

Thanks

---------

Co-authored-by: ikappaki <[email protected]>
Co-authored-by: Chris Rink <[email protected]>
chrisrink10 pushed a commit that referenced this pull request Dec 15, 2023
…730)

Hi,

could you please review patch to introduce a new namespace
`basilisp.stacktrace` and a `print-cause-trace`. It partly addresses
#721.

This is a requirement of the upcoming nbb nrepl-server port implemented
in #723. CIDER specifically requests this function when an exception is
thrown to display to the user, making it essential.

thanks

Co-authored-by: ikappaki <[email protected]>
chrisrink10 pushed a commit that referenced this pull request Dec 15, 2023
Hi,

could you please review patch to fix what it seems to be a potential
issue with how readwrite locks are used in basilisp. It addresses #722.

This was discovered while testing of the upcoming nrepl-server described
in #723. The nrepl-server tests which are using threads were failing due
to trying to release an rlock which has been already released, and is
fixed as described in #722 by using `with self._lock.gen_rlock()`
instead of a single instance of `with self._rlock()`. The error was
```
    File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/basilisp/lang/runtime.py", line 706, in find
    return v
   File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/readerwriterlock/rwlock.py", line 49, in __exit__
    self.release()
   File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/readerwriterlock/rwlock.py", line 344, in release
    if not self.v_locked: raise RELEASE_ERR_CLS(RELEASE_ERR_MSG)
 RuntimeError: release unlocked lock
```

Thanks

Co-authored-by: ikappaki <[email protected]>
@ikappaki ikappaki force-pushed the contrib/nrepl-server branch from 3f35756 to 28b0afe Compare December 15, 2023 00:37
@ikappaki
Copy link
Contributor Author

Would it be possible to start breaking off the smaller bug fixes as individual PRs so this PR is just the nrepl server? Most of them seem straightforward enough on their own.

done, merged to main and rebased this branch, ready for review.

My one reservation with using code from another project is that I assume we'll need to correctly attribute the source of that code to its original author(s) and I'm not 100% sure how to do that. Perhaps a copyright notice at the top of the file attributing that author and mentioning the license is the same as the main project.

Indeed we should, I've already chatted with the author about it and plan to bring them in to discuss about it once we pass the review and have a final product (include documentation).

Copy link
Member

@chrisrink10 chrisrink10 left a comment

Choose a reason for hiding this comment

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

I'm still working my way through this but I had a few comments and questions to start with.

Thanks again for putting this together! This is extremely cool and I'm so excited it's happening.

src/basilisp/contrib/bencode.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/bencode.lpy Show resolved Hide resolved
src/basilisp/contrib/bencode.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/bencode.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
@chrisrink10
Copy link
Member

It might be nice if we could split the bencode implementation off as a separate PR once we resolve the couple of comments I made there.

@chrisrink10
Copy link
Member

It might be nice if we could split the bencode implementation off as a separate PR once we resolve the couple of comments I made there.

Though I also realize this may make the discussions between us and the nbb folks more complicated, so maybe not.

@ikappaki
Copy link
Contributor Author

It might be nice if we could split the bencode implementation off as a separate PR once we resolve the couple of comments I made there.

Though I also realize this may make the discussions between us and the nbb folks more complicated, so maybe not.

I don't foresee any objections to assigning credits; I expect the discussion to focus more on deciding where to allocate them.

I consider the bencode package necessary solely for supporting the nrepl-server and not as a standalone general-use package, although it could be viewed differently. Personally, I prefer not to invest an extensive amount of time on it. Initially, I attempted to utilize https://pypi.org/project/bencode/, but unfortunately, it lacks an API to retrieve the undecoded portion of the stream, making it unsuitable for this specific nREPL server implementation.

Thanks

Copy link
Member

@chrisrink10 chrisrink10 left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. Finally took a first pass on the nrepl server itself.

src/basilisp/contrib/bencode.lpy Show resolved Hide resolved
src/basilisp/contrib/bencode.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Show resolved Hide resolved
@ikappaki ikappaki force-pushed the contrib/nrepl-server branch from 66363f9 to 6c702cb Compare December 22, 2023 12:00
@ikappaki
Copy link
Contributor Author

Hi, I've updated the documentation to include references to the nREPL server.

It also includes two autogen fixes

  1. the get_object_members fn was missing from the VarDocumenter, a dummy implementation was introduced
  2. The api generator failed to locate the files whose namespace included hypens (such as nrepl-server).

Thanks

@ikappaki ikappaki force-pushed the contrib/nrepl-server branch from 6c702cb to e579cd8 Compare December 22, 2023 12:09
@chrisrink10 chrisrink10 added this to the Release v0.1.0b0 milestone Dec 27, 2023
@ikappaki ikappaki force-pushed the contrib/nrepl-server branch from e579cd8 to 0041c75 Compare December 28, 2023 11:50
@ikappaki
Copy link
Contributor Author

(Updated to pick up latest changes from main and adjusted code accordingly)

src/basilisp/contrib/sphinx/autodoc.py Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/bencode.lpy Show resolved Hide resolved
@ikappaki ikappaki force-pushed the contrib/nrepl-server branch from 8e565e2 to 463da3b Compare December 28, 2023 15:58
@ikappaki
Copy link
Contributor Author

merged replacement bencode lib from main

Copy link
Member

@chrisrink10 chrisrink10 left a comment

Choose a reason for hiding this comment

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

I finally took a pass on the tests. Really nice, comprehensive suite. Thanks for doing that.

src/basilisp/contrib/bencode.lpy Outdated Show resolved Hide resolved
tests/basilisp/test_core_fns.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
src/basilisp/contrib/nrepl_server.lpy Outdated Show resolved Hide resolved
tests/basilisp/contrib/nrepl_server_test.lpy Outdated Show resolved Hide resolved
tests/basilisp/contrib/nrepl_server_test.lpy Show resolved Hide resolved
tests/basilisp/contrib/nrepl_server_test.lpy Show resolved Hide resolved
Copy link
Member

@chrisrink10 chrisrink10 left a comment

Choose a reason for hiding this comment

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

I have no further comments for now.

Is there anything else we need to do to discuss with nbb's authors on our use of their tooling or are our current attributions sufficient?

@ikappaki
Copy link
Contributor Author

I have no further comments for now.

Is there anything else we need to do to discuss with nbb's authors on our use of their tooling or are our current attributions sufficient?

Hi @borkdude, as mentioned briefly the other day, I've ported the nbb nREPL server (and together with @chrisrink10 the bencode library as a dependency) to basilisp. I'm seeking suggestions, if any, on how to appropriately attribute copyright and credits to both the nbb project and yourself. Besides adhering to the EPL 1.0 license for basilisp, acknowledging nbb in comments and documentation, and including a comment at the top of the files referencing the specific GitHub commit where the initial development originated, do you have any additional recommendations? Thanks

@borkdude
Copy link

Seems sufficient to me. I too borrowed the initial code from some other project. Standing on shoulders, etc :)

@ikappaki
Copy link
Contributor Author

Seems sufficient to me. I too borrowed the initial code from some other project. Standing on shoulders, etc :)

Thanks a lot for all your hard work!

@chrisrink10 chrisrink10 merged commit 6f3e5a3 into basilisp-lang:main Dec 28, 2023
9 checks passed
@chrisrink10 chrisrink10 mentioned this pull request Dec 29, 2023
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