Skip to content

On a Mac, check if xcode installed before requiring watchdog#91

Merged
jrhone merged 6 commits intostreamlit:developfrom
jrhone:xcode_watchdog
Sep 17, 2019
Merged

On a Mac, check if xcode installed before requiring watchdog#91
jrhone merged 6 commits intostreamlit:developfrom
jrhone:xcode_watchdog

Conversation

@jrhone
Copy link
Copy Markdown
Contributor

@jrhone jrhone commented Sep 11, 2019

Issue #66

  • Modify setup.py so we check whether xcode tools are available before making watchdog a dependency (only if the current system is a Mac, of course)
  • In LocalSourcesWatcher.py, when we fall back to the polling solution, print a message telling the user to install the watchdog module
  • Add config option to turn that message off: global.disableWatchdogWarning

@jrhone jrhone requested review from arraydude, kantuni, monchier, tconkling and tvst and removed request for arraydude, kantuni, monchier, tconkling and tvst September 11, 2019 12:02
@jrhone jrhone changed the title On a Mac, check if xcode installed before requiring watchdog WIP: On a Mac, check if xcode installed before requiring watchdog Sep 11, 2019
@jrhone jrhone changed the title WIP: On a Mac, check if xcode installed before requiring watchdog On a Mac, check if xcode installed before requiring watchdog Sep 11, 2019
'global.disableWatchdogWarning',
description='''
If False, will show a warning if the watchdog module is not available
on the user's system and we fall back to the polling file watcher.
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.

To avoid double negatives, change to:

By default, Streamlit checks if the Python watchdog module is available and, if not, prints a warning asking for you to install it. The watchdog module is not required, but highly recommended. It improves Streamlit's ability to detect changes to files in your filesystem.

If you'd like to turn off this warning, set this to True.

u'client.caching',
u'client.displayEnabled',
u'global.developmentMode',
u'global.disableWatchdogWarning',
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 guess this is not easy to test, huh? Any ideas what we could do here?

Copy link
Copy Markdown
Contributor Author

@jrhone jrhone Sep 13, 2019

Choose a reason for hiding this comment

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

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.

That would work, but you'd have to also:

  1. Remove LocalSourcesWatcher from sys.modules before running the test, so the module gets imported at test time (in case it had previously been imported by another test)
  2. Mock a bunch of things, like the function that tells you whether you're on a Mac

lib/setup.py Outdated
# Check whether xcode tools are available before making watchdog a
# dependency (only if the current system is a Mac).
if (platform.system() == 'Darwin' and
subprocess.call('xcode-select --version', shell=True) != 0):
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.

Copy link
Copy Markdown
Contributor Author

@jrhone jrhone Sep 13, 2019

Choose a reason for hiding this comment

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

shell=True is insecure if you're executing user generated input, as far as I understand. It also wasn't working without it, unless I was doing something incorrectly.

Warning Executing shell commands that incorporate unsanitized input from an untrusted source makes a program vulnerable to shell injection, a serious security flaw which can result in arbitrary command execution. For this reason, the use of shell=True is strongly discouraged in cases where the command string is constructed from external input:

https://docs.python.org/2/library/subprocess.html#frequently-used-arguments

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 think you can use shell=False by changing the first argument to ('xcode-select', '--version')

'global.disableWatchdogWarning',
description='''
If False, will show a warning if the watchdog module is not available
on the user's system and we fall back to the polling file watcher.
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.

Does this option causes to fall back on the 'polling'? I think it does not, maybe we could reword this?

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.

reworded with Thiago's suggestion


from streamlit.logger import get_logger
LOGGER = get_logger(__name__)
$ xcode-select --install
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.

Will this be shown on Linux as well if the option is true and the watchdog is not installed? Is the watchdog always installed on Linux?

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.

Watchdog is in the requirements and will be installed when the user installs Streamlit. I suppose they could uninstall watchdog afterwards and this message would be displayed.

lib/setup.py Outdated
# Check whether xcode tools are available before making watchdog a
# dependency (only if the current system is a Mac).
if (platform.system() == 'Darwin' and
subprocess.call('xcode-select --version', shell=True) != 0):
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 think you can use shell=False by changing the first argument to ('xcode-select', '--version')

u'client.caching',
u'client.displayEnabled',
u'global.developmentMode',
u'global.disableWatchdogWarning',
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.

That would work, but you'd have to also:

  1. Remove LocalSourcesWatcher from sys.modules before running the test, so the module gets imported at test time (in case it had previously been imported by another test)
  2. Mock a bunch of things, like the function that tells you whether you're on a Mac


# Check whether xcode tools are available before making watchdog a
# dependency (only if the current system is a Mac).
if (platform.system() == 'Darwin' and
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.

Maybe we should pull this into util.py, since it seems we'll need to do this check in a few different places.

@jrhone jrhone merged commit f38a7c5 into streamlit:develop Sep 17, 2019
tconkling added a commit to tconkling/streamlit that referenced this pull request Sep 23, 2019
* develop: (54 commits)
  Removing uber demo from streamlit repo (streamlit#159)
  Release 0.46.0 (streamlit#170)
  Magic fixes (streamlit#138)
  [docs] Add analytics; redirect /secret/docs; fix compilation problem (streamlit#149)
  Fix bug for startup under windows (streamlit#144)
  Responsive layout (streamlit#104)
  Add basic PR template
  Better method signatures (streamlit#88)
  Publish docs to both /docs and /secret/docs, until we deprecate /secret/docs in January. (streamlit#141)
  Rename/report2app (streamlit#126)
  Test running streamlit commands "bare" (streamlit#133)
  Updates to LP and sidebar. (streamlit#134)
  tests for z-index of date input popover in sidebar (streamlit#131)
  cypress test for escaping html in markdown (streamlit#125)
  On a Mac, check if xcode installed before requiring watchdog (streamlit#91)
  [Docs] Fix st.slider API in tutorial (streamlit#98)
  Sidebar exceptions (streamlit#107)
  Fixing unbound local variable (streamlit#110)
  Support hashing dataframes with unhashable objects. Gracefully f… (streamlit#118)
  Fix hashing if the object has a name but the name is not a string. (streamlit#117)
  ...
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