Skip to content

Commit

Permalink
[PYTHON] Resolved the manual installation issues
Browse files Browse the repository at this point in the history
[PYTHON] Added websocket-client as direct dependency
[PYTHON] Added six as direct dependency
[PYTHON] Added LICENSES
[GLOBAL] Updated Docs
[GLOBAL] Updated README
  • Loading branch information
faggionluca committed Apr 10, 2021
1 parent 7faf860 commit 8acb56b
Show file tree
Hide file tree
Showing 31 changed files with 5,536 additions and 137 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

This plugin enable the import of Megascan Assets using the Custom Socket Export feature of [Quixel Bridge](https://quixel.com/bridge)

# New version notes
> **The manual installation starting from version v0.3.0-beta and later are NO LONGER REQUIRED** so you should be able to use the plugin just by installing it with no additional actions.
## Quick start guide

For a complete guide on all the options of the plugin refere to the [How to use documentation](https://painter-megascan-link.readthedocs.io/en/latest/user_guide_usage.html).
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'megascan_link_python/websocket']

# Mock modules
# List imports to mock
Expand Down
59 changes: 0 additions & 59 deletions doc/user_guide_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,62 +54,3 @@ If you want to install it by hand simply place respectively:
.. warning::
**The plugins packages work together so both plugins should be enabled on Substance Painter!**
```

## (LINUX) Install Notes

```eval_rst
.. warning::
Linux users should set the sudo command to execute without password for the python executable of Substance Painter by
editing the sudoers file (``sudo visudo``) adding this line below ``root ALL=(ALL) ALL``
``username ALL=(ALL) NOPASSWD: /opt/Allegorithmic/Substance_Painter/resources/pythonsdk/bin/python3``
where username is the user that want to install this plugin.
```

I'm not a expert linux user so if are one and want to contribute to make the linux dependencies installation easier and better please take a look
at the [dependencies installation function][dependecies_linux] for the linux platform.

Ideally for linux users would be better to ask for the sudo password and pass it to the dependencies install command using [``subprocess.Popen``][popen_doc] or even better not
asking at all for a password (but i think that, on linux, this is probably not possible)

## (MacOS) Install notes

```eval_rst
.. warning::
MacOS users should set the sudo command to execute without password for the python executable of Substance Painter by
editing the sudoers file (``sudo visudo``) adding this line below ``%admin ALL=(ALL) ALL``
``username ALL=(ALL) NOPASSWD: /Applications/Substance\ Painter.app/Contents/Resources/pythonsdk/bin/python3``
**NOTE the backward slash for escaping the space between Substance and Painter**
where username is the user that want to install this plugin.
```

And again here like :ref:`(LINUX) Install Notes` if you want to improve the resource installation feel free to do so! head over the [dependencies installation function][dependecies_linux] for the code reference.

## Manual Dependencies Installation
In the case you can't manage to get the automatic dependencies installation working, you can install them yourself

- **Windows installation steps**
> - run a terminal as an **administrator**, press the start button write `cmd` right click `Command Prompt` and select `Run as an administrator`
> - navigate to the Substance Painter Python installation folder
`cd %pathtoSubtancePainter%\resources\pythonsdk`
> - install the dependencies with the command `python.exe -m pip install websocket-client`
> - verify the installation with the command `python.exe -m pip freeze`, in the output should be present this line `websocket-client=0.x.x`
- **Linux installation steps**
> - open a terminal and navigate to `/opt/Allegorithmic/Substance_Painter/resources/pythonsdk/bin`
> - install the dependencies with the command `sudo python3 -m pip install websocket-client`
> - verify the installation with the command `sudo python3 -m pip freeze`, in the output should be present this line `websocket-client=0.x.x`
- **MacOS installation steps**
> - open a terminal and navigate to `/Applications/Substance Painter.app/Contents/Resources/pythonsdk/bin`
> - install the dependencies with the command `sudo python3 -m pip install websocket-client`
> - verify the installation with the command `sudo python3 -m pip freeze`, in the output should be present this line `websocket-client=0.x.x`
[quixelbridge]: https://quixel.com/bridge
[sbspainter]: https://www.substance3d.com/products/substance-painter/
[dependecies_linux]: https://github.com/Raider-Arts/painter-megascan-link/blob/master/megascan_link_python/__init__.py#L60
[popen_doc]: https://docs.python.org/3/library/subprocess.html#subprocess.Popen
82 changes: 7 additions & 75 deletions megascan_link_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,74 +37,6 @@ def showErrorDialog():
dialog = dialogs.DependencyErrorDialog(mainWindow, "https://painter-megascan-link.readthedocs.io/en/latest/user_guide_install.html#manual-dependencies-installation")
dialog.show()


def checkDependencies() -> bool:
"""Check if dependencies are installed if not tries to install them
This function is platform dependent
.. warning::
**WARNING FOR LINUX USERS**, they should set the sudo command to execute without password for the python executable of Substance Painter by
editing the sudoers file (``sudo visudo``) adding this line below ``root ALL=(ALL) ALL``
``username ALL=(ALL) NOPASSWD: /opt/Allegorithmic/Substance_Painter/resources/pythonsdk/bin/python3``
where username is the user that want to install this plugin.
refer to the :ref:`(LINUX) Install Notes` user guide for more details.
** WARNING FOR MAC USERS**, they should do the same but the string is
``username ALL=(ALL) NOPASSWD: /Applications/Substance\ Painter.app/Contents/Resources/pythonsdk/bin/python3``
**NOTE the backward slash for escaping the space between Substance and Painter**
refer to the :ref:`(MACOS) Install Notes` user guide for more details.
:return: True if dependecies are present or successfully installed, False otherwise
:rtype: bool
"""
try:
import websocket as pd
log.LoggerLink.Log("Dependecies already satisfied")
except ImportError:
print("Adding dependecies")
pyInterpreter = None
target = None
cmdCall = []
if platform.system() == "Windows":
pyInterpreter = Path(os.__file__).parent.parent / "python.exe"
cmdCall = [str(pyInterpreter)]
elif platform.system() == "Linux" or platform.system() == "Darwin" :
# =================================================
# WARNING FOR LINUX USERS, they should set the sudo commandd to execute without password for the python executable of Substance Painter
# editing the visudo file adding this line below root ALL=(ALL) ALL
# username ALL=(ALL) NOPASSWD: /opt/Allegorithmic/Substance_Painter/resources/pythonsdk/bin/python3
# where username is the user that want to install this plugin
#
# WARNING FOR MAC USERS, they should do the same but the string is
# username ALL=(ALL) NOPASSWD: /Applications/Substance\ Painter.app/Contents/Resources/pythonsdk/bin/python3
# NOTE the backward slash for escaping the space between Substance and Painter

pyInterpreter = Path(os.__file__).parent.parent.parent / "bin" / "python3"
cmdCall = ["sudo", str(pyInterpreter)]
else:
log.LoggerLink.Log("Current Platform {} is not supported".format(platform.system()), log.logging.ERROR)
return False
try:
cmdCall += ["-m", "pip", "install", "websocket-client"]
subprocess.check_call(cmdCall)
except Exception as e:
log.LoggerLink.Log("Error during pip command: {}".format(e), log.logging.ERROR)
finally:
try:
log.LoggerLink.Log("Check installed dependecies")
import websocket as pd
log.LoggerLink.Log("Dependencies are installed correctly")
return True
except ImportError:
log.LoggerLink.Log("Dependecies error! cannot start plugin", log.logging.ERROR)
showErrorDialog()
return False

class Data(object):
"""Dataclass used to store references to items so they dont get garbage collected
"""
Expand Down Expand Up @@ -149,13 +81,13 @@ def start_plugin():
iniconf["Bake"] = {"enabled": 'false', "resolution": '[12,12]', "maxreardistance": '0.5', "maxfrontaldistance": '0.6', 'average': 'true', 'relative': 'true', 'ignorebackface': 'true', 'antialiasing': 'Subsampling 2x2'}
config.ConfigSettings.setUpInitialConfig(iniconf)

if checkDependencies():
createToolBar()
# =================================================
# start the socket
Data.socket = sockets.SocketThread(mainWindow)
Data.socket.start()
log.LoggerLink.Log("Megascan Link Python correctly initialized")
# if checkDependencies():
createToolBar()
# =================================================
# start the socket
Data.socket = sockets.SocketThread(mainWindow)
Data.socket.start()
log.LoggerLink.Log("Megascan Link Python correctly initialized")


def close_plugin():
Expand Down
18 changes: 18 additions & 0 deletions megascan_link_python/websocket/LICENSE_SIX
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright (c) 2010-2020 Benjamin Peterson

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit 8acb56b

Please sign in to comment.