Skip to content

Conversation

@sfc-gh-tteixeira
Copy link
Contributor

@sfc-gh-tteixeira sfc-gh-tteixeira commented Dec 15, 2022

📚 Context

As part of my hackathon project, I'm planning on submitting some fully-ready PRs (not prototypes!) that hopefully can be merged without a lot of work from the eng team. This is one of them! If it's too much work to merge, or the feature is deemed a bad idea, I'm happy to drop the whole thing.

What this PR does:

  • Improves st.help() in the following ways:
    • Shows the actual variable or expression you passed to st.help. For example st.help(foo[0]["bar"]) prints foo[0]["bar"] in the header of the displayed block, so you know what that block is referring to.
    • Shows the type is a cleaner, more readable way
    • Shows the docstring in a scrolling box, to save space
    • Shows the members of the thing you're asking for help on
      • ...along with their current values or docstrings (depending on whether it's a function or not)
  • Improves st.write() in the following ways:
    • If you pass a class into st.write() you now get st.help(the_class)
    • If you pass an object that doesn't translate well into a string (i.e. things that would normally look like <foo object at 0x1234abcd>), calls st.help(the_object).

This makes st.help, st.write, and magic great for quickly inspecting objects, classes, and what-have-yous! More info in the spec.

  • What kind of change does this PR introduce?

    • Bugfix
    • Feature
    • Refactoring
    • Other, please describe:

🧠 Description of Changes

  • Add bullet points summarizing your changes here

    • This is a breaking API change
    • This is a visible (user-facing) change

😬 Before

This is what you used to get for this code:

class Animal:
    pass

class Dog(Animal):
    """A dog object.

    These kinds of classes are very useful in day-to-day programming,
    judging by my "Intro to OOP" book.
    """

    def __init__(self, color, breed):
        self.color = color
        self.breed = breed

    def bark(self, reason):
        """Make a pleasant sound."""
        pass

fido = Dog("brown", "poodle")


# Show help for an object instance.
st.help(fido)

# Show help for a class.
st.help(Dog)

# Show help for a module (useful to avoid consulting online docs!)
re

Screen Shot 2022-12-14 at 20 42 57

(etc)

😎 After

Screen Shot 2022-12-14 at 20 43 01

(etc)

🧪 Testing Done

  • Screenshots included
  • Added/Updated unit tests
  • Added/Updated e2e tests - Still need to do this! Will do before merge.

🌐 References

Does this depend on other work, documents, or tickets?

  • Issue: none

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Comment on lines +138 to +139
# with contextlib.suppress(ValueError):
# sig = str(inspect.signature(obj))

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
@jrieke
Copy link
Collaborator

jrieke commented Dec 20, 2022

Had a rough look through it and generally LGTM! Let's make a demo app in the feature-demos repo before we merge, so we can have a look what it looks like in live, and then I'll give my final LGTM.

(i.e. it works but doesn't show variable name)
@jrieke
Copy link
Collaborator

jrieke commented Jan 6, 2023

@sfc-gh-tteixeira What happens if I do st.write("This is Fido:", fido) in your example? Does it show 1) This is Fido: <__main__.Dog object at ...> or does it show 2) This is Fido: and then the help box below? I think in this case we should show (1) since I assume some people might do something like this to quickly check which value an object has. And if show the box instead, it kinda distorts their app. No super strong opinion though!

@sfc-gh-tteixeira
Copy link
Contributor Author

Let's make a demo app in the feature-demos repo before we merge, so we can have a look what it looks like in live, and then I'll give my final LGTM.

Turns out the feature-demos app doesn't work very well with this. That's beacuse part of the new st.help code won't work inside an exec block (because of this), i.e. the part that finds out variable names (in the red circle, in the screenshot below).

So I'm adding a warning to e2e/scripts/st_help.py to explain this, so people don't get confused when they run feature-demos.

207774416-9dc31748-c686-451a-9abc-07f387e5f975

@sfc-gh-tteixeira
Copy link
Contributor Author

Hey, @vdonato, maybe you can help me with this...

I can't run the e2e tests locally on my Mac, so update the screenshots. I'm getting this error:

circleci@947d527e5e8d:~/repo/frontend$ yarn cy:run --env updateSnapshots=true --spec ../e2e/specs/st_help.spec.js
yarn run v1.22.19
$ unset NODE_OPTIONS && cypress run --env updateSnapshots=true --spec ../e2e/specs/st_help.spec.js
It looks like this is your first time using Cypress: 6.9.1

  ✖  Verifying Cypress can run /home/circleci/.cache/Cypress/6.9.1/Cypress
    → Cypress Version: 6.9.1
Cypress failed to start.

This is usually caused by a missing library or dependency.

The error below should indicate which dependency is missing.

https://on.cypress.io/required-dependencies

If you are using Docker, we provide containers with all required dependencies installed.

----------

qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[396:0107/030403.391738:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[396:0107/030403.432713:ERROR:file_path_watcher_linux.cc(315)] inotify_init() failed: Function not implemented (38)
[396:0107/030403.505420:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 1 time(s)
[396:0107/030403.516134:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 2 time(s)
[396:0107/030403.518726:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 3 time(s)
[396:0107/030403.521989:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 4 time(s)
[396:0107/030403.524232:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 5 time(s)
[396:0107/030403.526404:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 6 time(s)
[396:0107/030403.530306:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 7 time(s)
[396:0107/030403.561996:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 8 time(s)
[396:0107/030403.564703:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 9 time(s)
[396:0107/030403.564815:FATAL:gpu_data_manager_impl_private.cc(445)] GPU process isn't usable. Goodbye.
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[436:0107/030408.032688:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[436:0107/030408.072780:ERROR:file_path_watcher_linux.cc(315)] inotify_init() failed: Function not implemented (38)
[436:0107/030408.134972:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 1 time(s)
[436:0107/030408.141924:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 2 time(s)
[436:0107/030408.144114:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 3 time(s)
[436:0107/030408.148424:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 4 time(s)
[436:0107/030408.201465:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 5 time(s)
[436:0107/030408.222011:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 6 time(s)
[436:0107/030408.222148:FATAL:gpu_data_manager_impl_private.cc(445)] GPU process isn't usable. Goodbye.
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped

----------

Platform: linux (Debian - 11.0)
Cypress Version: 6.9.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
circleci@947d527e5e8d:~/repo/frontend$ 

Screen Shot 2023-01-06 at 19 05 15


I'm running this in a Docker container with $ ./scripts/run_e2e_tests.py -u e2e/specs/<name_of_test>.spec.js as described here.

The logs above were captured by running cy:run directly inside of the container, just so I get pretty colors. But the error when I call run_e2e_tests.py is the exact same.

I tried updating the deps as mentioned at https://on.cypress.io/required-dependencies, but that doesn't do it either. Any idea what's up? Could this be an ARM thing?

@stale
Copy link

stale bot commented Jan 21, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 21, 2023
@stale stale bot removed the stale label Jan 24, 2023
@vdonato
Copy link
Collaborator

vdonato commented Jan 24, 2023

@sfc-gh-tteixeira whoops, sorry! The @mention from a few weeks back must have gotten lost in a sea of emails, so I didn't notice it until a later email notification for this PR.

I haven't updated snapshots locally via the Docker image for quite awhile at this point (I've mostly been deleting the snapshots to allow cypress running in CI to regenerate them for me), although I was under the impression that doing so still worked given that a few changes to the Dockerfile have been made relatively recently (CC @sfc-gh-kbregula and @sfc-gh-tszerszen as I believe they recently made some related changes). I'm not sure if folks still using the local docker test env are using M1 machines, though.

In either case, I think the path being taken in #6006 would likely be the preferred improvement here, anyway, given that attempting to replicate the exact environment used in CI to take snapshots locally has always been extremely fragile / oftentimes slower than using CI when updating tons of snapshots due to the lack of parallelization.

@sfc-gh-kbregula
Copy link
Contributor

I'm using Docker image on Mac OS x86, but building the image currently doesn't work because there is a problem with deleted options in pip tool.

To build the dockerfile, you need to add one patch locally.

diff --git a/Makefile b/Makefile
index 5b39d4606..a10b9bcb4 100644
--- a/Makefile
+++ b/Makefile
@@ -83,9 +83,9 @@ SHOULD_INSTALL_TENSORFLOW := $(shell python scripts/should_install_tensorflow.py
 py-test-install: lib/test-requirements.txt
        # As of Python 3.9, we're using pip's legacy-resolver when installing
        # test-requirements.txt, because otherwise pip takes literal hours to finish.
-       pip install -r lib/test-requirements.txt --use-deprecated=legacy-resolver
+       pip install -r lib/test-requirements.txt
 ifeq (${SHOULD_INSTALL_TENSORFLOW},true)
-       pip install -r lib/test-requirements-with-tensorflow.txt --use-deprecated=legacy-resolver
+       pip install -r lib/test-requirements-with-tensorflow.txt
 else
        @echo ""
        @echo "Your system does not support the official, pre-built tensorflow binaries."

And then follow the instructions:
https://github.com/streamlit/streamlit/wiki/Running-e2e-tests-and-updating-snapshots

tl;dr;

# Build or rebuild the test env image. This normally takes a long time.
$ make build-test-env
# The -u flag tells Cypress to update snapshots.
$ ./scripts/run_e2e_tests.py -u e2e/specs/<name_of_test>.spec.js

@sfc-gh-tteixeira
Copy link
Contributor Author

@vdonato @lukasmasuch : you're totally right. The Arrow thing was a red herring! It's just a warning 🤦

Fixed now.

Thanks for the help debugging!

@sfc-gh-tteixeira
Copy link
Contributor Author

@jrieke
Copy link
Collaborator

jrieke commented Feb 21, 2023

Demo app looks great! Can you write QA plan and have this QAed whenever you're ready? I'm OOO until Friday, so you can skip my approval and just send it off to Kasim directly :)

Comment on lines 18 to 22

// Formatted text
message DocString {

// The name of the object.
// The name the user gave to the variable holding this object.
string name = 1;
Copy link
Collaborator

@vdonato vdonato Mar 1, 2023

Choose a reason for hiding this comment

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

Whoops, my bad for not noticing this earlier, especially given that I have code ownership over these files specifically to enforce this 😅

We'll need to ensure that these proto changes are backwards compatible given that other stakeholders rely on them

We also want to be a bit more strict than normal proto backwards compatibility guidelines to also avoid changing field names to make things easier on folks when they're upgrading the OS lib version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. PTAL.

Copy link
Collaborator

@vdonato vdonato left a comment

Choose a reason for hiding this comment

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

new proto LGTM

Comment on lines +40 to +41
// The name the user gave to the variable holding this object.
string name = 6;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think we could probably just keep the current name field vs adding this one, but not a big deal either way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO the meaning changed enough that the right thing to do is to deprecate.

@sfc-gh-tteixeira sfc-gh-tteixeira merged commit f74a7a3 into streamlit:develop Mar 24, 2023
@sfc-gh-tteixeira sfc-gh-tteixeira deleted the st-help branch March 24, 2023 16:10
tconkling added a commit to tconkling/streamlit that referenced this pull request Mar 27, 2023
* develop:
  StreamlitEndpoints.buildMediaURL (streamlit#6366)
  Set a default for RuntimeConfig.cache_storage_manager (streamlit#6361)
  FullScreenWrapper: add a type declaration for react context usage (streamlit#6364)
  Improve st.help (and st.write's usage of st.help!) (streamlit#5857)
  Fix regression with query_params  (streamlit#6348)
  Have util.calc_md5 also take bytes (streamlit#6358)
  Improve deploy button (streamlit#6223)
  Return whether a secrets.toml file is successfully parsed (streamlit#6333)
  Add `.webp` to list of safe static file extensions (streamlit#6331)
  AppContext docstrings (streamlit#6353)
  fix: upgrade command-line-args from 5.0.2 to 5.2.1 (streamlit#6258)
  fix: upgrade flatbuffers from 1.11.0 to 1.12.0 (streamlit#6259)
  sendMessageToHost: no longer a global function (streamlit#6345)
  Tweak no-else-return config options (streamlit#6343)
  Allow users to set a secrets.toml file in their home directory (streamlit#6230)
  Add support for number and boolean types in categorical columns (streamlit#6248)
  Add support for period type in st.table and st.dataframe (streamlit#5429)
  Add ability to turn off anchors (streamlit#6158)
  Add sqlalchemy mypy types to test-requirements.txt (streamlit#6329)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants