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

Package into a single file #67

Open
alexmojaki opened this issue Mar 31, 2021 · 12 comments · May be fixed by #70
Open

Package into a single file #67

alexmojaki opened this issue Mar 31, 2021 · 12 comments · May be fixed by #70

Comments

@alexmojaki
Copy link
Collaborator

@gruns - I am sure I am in a very tiny minority, but I would be interested in a single-file icecream.py.

My reason for wanting a single file is related to the reason I don't just go ahead and use ycecream.py (since I actually am not particularly interested in the color features). I would love to be able to use icecream with an obscure and esoteric implementation of Python that is stuck at 2.7 and does not have pip or any other easy installers.

Originally posted by @jkyeung in #58 (comment)

@alexmojaki alexmojaki changed the title Package into single file Package into a single file Mar 31, 2021
@alexmojaki
Copy link
Collaborator Author

Implementing this would likely use https://github.com/mwilliamson/stickytape

Similar request in a different project, which explains some of the reasoning as well as generic instructions for installing from github without pip: cool-RR/PySnooper#18

an obscure and esoteric implementation of Python that is stuck at 2.7 and does not have pip or any other easy installers.

I'm very curious about how a CPython fork can't use pip. @jkyeung, what happens if you run python get-pip.py?

If that doesn't work, what if you download/clone this repo and run python setup.py, like in the other issue above?

If none of that works, I'd suggest https://github.com/zestyping/q again until this is implemented, which may not be soon.

@jkyeung
Copy link

jkyeung commented Apr 1, 2021

an obscure and esoteric implementation of Python that is stuck at 2.7 and does not have pip or any other easy installers.

I'm very curious about how a CPython fork can't use pip. @jkyeung, what happens if you run python get-pip.py?

ImportError: No module named distutils.util

If that doesn't work, what if you download/clone this repo and run python setup.py, like in the other issue above?

ImportError: No module named setuptools

And no, these are not due to path errors. They are just not on the system. The person who built this Python either ran into too much difficulty when working on certain pieces, given the specifics of the platform; or just didn't get around to it, and didn't feel a strong enough need for his own purposes.

If none of that works, I'd suggest https://github.com/zestyping/q again until this is implemented, which may not be soon.

Well, thanks for pointing it out. It does seem to work, but it is nowhere near as easy to use as icecream (at least judging by the examples shown in icecream's README). I mean, I was drawn to icecream because it looks like a great way to do print-debugging. q seems like a nifty way to get simple logging (to me, there is a big gulf between the two; perhaps this is exacerbated by the specifics of the platform I am looking to use this on).

@salabim
Copy link

salabim commented Apr 1, 2021

I am trying to backport ycecream to Python 2.7, but it's a lot of work and I am not sure whether it will be successful.
Stay tuned on the ycecream GitHub channel.

@alexmojaki alexmojaki linked a pull request Apr 1, 2021 that will close this issue
@alexmojaki
Copy link
Collaborator Author

alexmojaki commented Apr 1, 2021

ImportError: No module named distutils.util

The funny thing is that I often get that error when setting up a normal Python installation, and I have to install distutils from elsewhere. I don't know why, it's really weird, Python packaging in general is a mess. That said, you might still be able to install it.

@jkyeung try downloading https://raw.githubusercontent.com/gruns/icecream/stickytape/single_file/single_file_icecream.py and see if that works for you. You can use from single_file_icecream import ic.

@jkyeung
Copy link

jkyeung commented Apr 2, 2021

@jkyeung try downloading https://raw.githubusercontent.com/gruns/icecream/stickytape/single_file/single_file_icecream.py and see if that works for you. You can use from single_file_icecream import ic.

Unfortunately it doesn't:

Traceback (most recent call last):
  File "test_ic_001.py", line 3, in <module>
    from single_file_icecream import ic
  File "C:\Users\jkyeu\Documents\Python\test\single_file_icecream.py", line 85, in <module>
    from icecream import *
  File "c:\users\jkyeu\appdata\local\temp\tmpykoboe\icecream\__init__.py", line 15, in <module>
  File "c:\users\jkyeu\appdata\local\temp\tmpykoboe\icecream\icecream.py", line 31, in <module>
  File "c:\users\jkyeu\appdata\local\temp\tmpykoboe\pygments\formatters\__init__.py", line 143, in __getattr__
  File "c:\users\jkyeu\appdata\local\temp\tmpykoboe\pygments\formatters\__init__.py", line 39, in _load_formatters
  File "c:\users\jkyeu\appdata\local\temp\tmpykoboe\pygments\formatters\terminal256.py", line 29, in <module>
  File "c:\users\jkyeu\appdata\local\temp\tmpykoboe\pygments\formatter.py", line 15, in <module>
    file formats, are supported as well as physical devices. The provided
ImportError: cannot import name get_style_by_name

That's using CPython 2.7.14 on Windows 10. I got the same thing with iSeriesPython.

I tried not deleting the temporary directory, just to make things more human-readable, and got this:

Traceback (most recent call last):
  File "test_ic_001.py", line 3, in <module>
    from single_file_icecream_mod import ic
  File "C:\Users\jkyeu\Documents\Python\test\single_file_icecream_mod.py", line 86, in <module>
    from icecream import *
  File "c:\users\jkyeu\appdata\local\temp\tmpebnkxa\icecream\__init__.py", line 15, in <module>
    from .icecream import *  # noqa
  File "c:\users\jkyeu\appdata\local\temp\tmpebnkxa\icecream\icecream.py", line 31, in <module>
    from pygments.formatters import Terminal256Formatter
  File "c:\users\jkyeu\appdata\local\temp\tmpebnkxa\pygments\formatters\__init__.py", line 143, in __getattr__
    _load_formatters(info[0])
  File "c:\users\jkyeu\appdata\local\temp\tmpebnkxa\pygments\formatters\__init__.py", line 39, in _load_formatters
    mod = __import__(module_name, None, None, ['__all__'])
  File "c:\users\jkyeu\appdata\local\temp\tmpebnkxa\pygments\formatters\terminal256.py", line 29, in <module>
    from pygments.formatter import Formatter
  File "c:\users\jkyeu\appdata\local\temp\tmpebnkxa\pygments\formatter.py", line 15, in <module>
    from pygments.styles import get_style_by_name
ImportError: cannot import name get_style_by_name

My understanding of the Python import system is too weak to say why it fails there.

I will say that installing icecream via pip works fine for CPython 2.7 on Windows, so I tried just copying over the various pip-installed directories from Windows to the IBM i... and it seems to have worked!

But it's basically unusable when running interactively with iSeriesPython (the codes used for coloring show up as extra gibberish characters, completely overwhelming the actual content). It's a little better for batch mode use, but still not great.

Interactive mode snippet:

 [38;5;247mic [39m [38;5;245m| [39m [38;5;245m  [39m [38;5;247mtest_ic_001 [3
9m [38;5;245m. [39m [38;5;247mpy [39m [38;5;245m: [39m [38;5;36m7 [39m [38;5;
245m  [39m [38;5;100min [39m [38;5;245m  [39m [38;5;247mfoo [39m [38;5;245m( 
[39m [38;5;245m) [39m [38;5;245m  [39m [38;5;247mat [39m [38;5;245m  [39m [38
;5;36m04 [39m [38;5;245m: [39m [38;5;36m11 [39m [38;5;245m: [39m [38;5;36m08.
294 [39m

Batch mode snippet:

ic         
|          
test_ic_001
.          
py         
:          
7          
in         
foo        
(          
)          
at         
04         
:          
01         
:          
07.303     
ic         
|          

Now you see why I wasn't interested in the colorization. Is there any way to turn it off?

@alexmojaki
Copy link
Collaborator Author

I will say that installing icecream via pip works fine for CPython 2.7 on Windows, so I tried just copying over the various pip-installed directories from Windows to the IBM i... and it seems to have worked!

Nice! Sounds like different Python versions need different packages.

What are interactive and batch mode?

Now you see why I wasn't interested in the colorization. Is there any way to turn it off?

from icecream import ic, stderrPrint
ic.configureOutput(outputFunction=stderrPrint)
# or
ic.configureOutput(outputFunction=print)

This should definitely be clarified in the README, at least so that searching the page for 'col' finds something.

@salabim
Copy link

salabim commented Apr 2, 2021

Ycvecream is now available under Python 2.7.
No dependencies and the full functionality! Give it a try.

@alexmojaki
Copy link
Collaborator Author

I've updated the PR to make separate packages for each python version, try https://raw.githubusercontent.com/gruns/icecream/stickytape/single_file/icecream_py27.py

@jkyeung
Copy link

jkyeung commented Apr 3, 2021

I've updated the PR to make separate packages for each python version, try https://raw.githubusercontent.com/gruns/icecream/stickytape/single_file/icecream_py27.py

Looks like it works! Thank you!

I have to say, the stickytape approach feels... heavy. Startup time is pretty gruesome, and deleting the temporary directory feels like a shame after all that work building it, only to have to build it again next time.

I realize my situation is weird (I do have permission to install stuff, yet cannot use pip and the like). Perhaps the stickytape-generated file has value for folks who really aren't allowed to install stuff. (Though for them, I think ycecream is a very attractive alternative to icecream.) For me, if I do wind up using icecream regularly from iSeriesPython, I'll just use copy-installed versions of the dependencies.

What are interactive and batch mode?

Interactive mode is what everyone is used to. You type a command and it runs immediately, potentially with real-time user interaction. Batch mode is from the mainframe days (it would not be a gross mischaracterization to say IBM i is descended from IBM mainframes), where you submit a job to a queue and the job runs whenever the computer gets around to it. There is no user interaction in batch mode. In batch mode, stdout and stderr default to being redirected to (separate) printed output.

And, not that anyone asked, but IBM i does have an AIX compatibility environment, which was underdeveloped in the past but now has a working gcc and near-stock builds of CPython 2.7 and CPython 3.6, each with pip. I haven't tried, but I have no doubt icecream would install and run in the usual fashion with those. The coloring probably even works, if you use an SSH client (such as PuTTY) to log in to that environment.

@alexmojaki
Copy link
Collaborator Author

I have to say, the stickytape approach feels... heavy. Startup time is pretty gruesome, and deleting the temporary directory feels like a shame after all that work building it, only to have to build it again next time.

I agree, I was surprised to discover that 's how it works. Seems like it should just be an install script that you run once.

How long is your startup time? For me it's about 0.12 seconds.

@salabim
Copy link

salabim commented Apr 3, 2021

Aren't you confusing single source file package with a no dependency package?
If you just want a single source file package, that's pretty simple to realize: just combine the builtins.py, coloring.py and icecream.py in one file. That's five minutes work and you won't loose anything. That could become the new distribution.

If you have such an all-in-one file, users can just put that one file in their current directory and they have all functionality. The only thing they have to do is pip installing once the required packages. Future versions don't require any pip installing.

For me that would be a very acceptable solution.

@alexmojaki
Copy link
Collaborator Author

No, pip installing the dependencies is the main problem. Future versions of the dependencies are also important, maybe even more important than future versions of icecream itself. And your suggestion doesn't really save the user much trouble over just downloading the icecream directory.

I think we've already reached an acceptable solution. The only problems are that it's apparently slow on some machines and the release process could be automated a bit more. And while this problem interested me for a bit, I don't want to go much further.

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 a pull request may close this issue.

3 participants