Comments (6)
Maybe make stash a package. stash.py
would contain the main shell functionality, and utils.py
some commonly used helper functions. __init__.py
could also import objects from the submodules that are intended for external use, that way a script can import stash
and immediately have access to all public functions, classes, attributes, etc.
The downside to this is that it adds an extra dependency to commands that could otherwise run standalone as well. Perhaps stash could automatically collapse all "long" paths when writing to the output (configurable of course in case it should cause problems) so the commands don't need to do tilde collapsing on their own every time they write a path.
from stash.
PS - there's a collapseuser
function in whateversh. It uses os.path.relpath
to collapse, which should make it reliable in almost all cases, and it correctly handles the split data/application home folder in iOS 8 and Pythonista < 1.6.
def collapseuser(path):
"""Reverse of os.path.expanduser: return path relative to ~, if
such representation is meaningful. If path is not ~ or a
subdirectory, the absolute path will be returned.
"""
path = os.path.abspath(unicode(path))
home = os.path.expanduser("~")
if os.path.exists(os.path.expanduser("~/Pythonista.app")):
althome = os.path.dirname(os.path.realpath(os.path.expanduser("~/Pythonista.app")))
else:
althome = home
if path.startswith(home):
collapsed = os.path.relpath(path, home)
elif path.startswith(althome):
collapsed = os.path.relpath(path, althome)
else:
collapsed = path
##print(path, home, althome, collapsed)
return "~" if collapsed == "." else os.path.join("~", collapsed)
from stash.
@dgelessus Thanks for the advices. I am also still thinking about the best approach to do this.
I am kinda reluctant to make it an inherent part of StaSh. My personal feel is that the shell really is not in the position to change outputs generated by external scripts. The shell manages screen display issues like scroll and refresh, but the actual contents should only be managed by external scripts. So I thought about creating a sub-folder (similar concept as the bin
sub-folder) to store these utility functions that could be used by external scripts. I do agree, like you said, it creates dependancies between bin scripts and the shell.
Your collapseuser
function looks great and is what I am after. I'd like to use it as part of utils
. Thanks!
from stash.
Added a lib
folder under the main StaSh directory. @dgelessus collapseuser
is added as the first helper function (used by version.py
). Thanks!
from stash.
I plan to make some changes on how lib
folder works:
Python files under lib
folder that have names start with lib
will be imported by StaSh at startup time. The imported module will be added to the _stash
object as an attribute. For example, a libcore.py
containing the collapseuser
function is located at the lib
folder. It will be imported and assigned as _stash.libcore
. So an command script can use the function as _stash.libcore.collapseuser('PATH')
.
The reason of the changes are:
- I'd like the command script to have a single dependency point that is
_stash
lib
no longer has to be insys.path
. This avoid potential module name clashes and remove the need to use leading underscore in file names.
from stash.
The changes now are committed 0322f3b
Both version.py
and pwd.py
now use the new interface.
from stash.
Related Issues (20)
- please delete and reinstall pythonista 3.4 to get stash clean install HOT 3
- Pythonista 3.4 Error pip install mysql.connector
- Running ``setup.py`` directly is now deprecated HOT 1
- Error on launch stash on pythonista PY:3.10 HOT 2
- Only first line in .stashrc or first command in a single-line multiple commands separated by ; is executed. HOT 1
- pip install fyiban error
- Pythonista crash during start launch_stash.py HOT 9
- When typing in 'pip install', 'install' autocapitalizes
- Unable to install pyzmq with pip - TypeError("unsupported operand type(s) for +: 'OmniClass' and 'list'") HOT 3
- Cannot develop extensions using external files
- ssh-keygen raises the error: module 'time' has no attribute 'clock'
- stash doesn't work because of "subprocesses not supported on ios" HOT 1
- Is there a way to customize the font size and colors, on my small screen font is super small HOT 1
- NumPy does not work HOT 1
- I want to play Python on my iPad HOT 1
- autofill in stash prevents typing properly.
- Pandas v1.4.4 is bundled in Pythonista HOT 1
- Check the value of $BIN_PATH HOT 8
- XMLRPC error on pip search
- staSH isn't getting module dependancies
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stash.