Code Monkey home page Code Monkey logo

Comments (27)

ksamuel avatar ksamuel commented on April 27, 2024 9

Hello @jakubroztocil,

As we discussed weeks ago, here is a PoC for a Windows installer attached and the procedure I used to generate it: https://drop.chapril.org/download/889aae1e4ee17fe9/#BBLdWchiazXCxNkma9lqQQ

The link will expire in 5 days, or 20 DL. I can't attach it on Github as it's bigger than 20Mo.

Dependencies

Generate the standalone executable

  1. Create a venv with a recent version of python and pip install httpie nuitka
  2. Create a python module running the httpie cmd entry point. E.G: from httpie.__main__ import main; main(). See run_http.py.
  3. In the venv, ask nuikta to compile it: nuitka run_http.py --standalone.

In the last step, nuitka will prompt you for downloading dependencies (an import resolver and a compiler), say yes, and wait for some time while it does its magic.

This will result in a run_http.dist directory containing compiled dependencies and an executable named run_http.exe. This directory can be copied on any modern Windows setup and used without the need to install anything, not even the Python VM, which is provided. Running run_http.exe will run the http command from httpie.

To make sure we won't confuse the users, I advice for renaming run_http.exe into http.exe after the fact. run_http.exe is named this way because we compiled run_http.py, but we can't call the script http.py, this would result in import errors since this module exists in the stdlib.

You can zip and provide this directory as a portable version of httpie, which is very useful to have on a USB stick.

Generate an installer

  1. Install the large string build of NSIS, it will allow a maximum string length of 8192 bytes which is better when you deal with potentially long file system paths.
  2. Install the env var plugin, which let us manipulate the system PATH to add http.exe parent directory.
  3. Write a NSI script. I provided the one I used as an example, named httpie.nsi. You will find some comments, but for a better understanding, you can use NSIS Quick Setup which is a UI generating scripts.
  4. Use either NSIS UI or cmd to run the .nsi file and get the installer as a result. VSCode also has a nice plugin to do that for you. Careful, any utf8 file you manipulate (E.G: the licence file) must have a BOM to be used as such.

The result is an installer that will serve a piece of httpie to your happy Windows machine. You'll find it as install_httpie.exe in the zip too. You can try it on an official pristine Windows dev VM to see that it does provide the http command, and a way to uninstall it.

Where to go from there:

  • Optimize the compilation phase so that you don't include the entire stdlib.
  • Automate the whole thing.
  • Put an icon in there.
  • Sign the binary.
  • More robust PATH handling.
  • Entry point should be a cmd.exe call, with httpie loaded in the PATH, not httpie directly.
  • Handle updates.
  • Create an e2e test in your CI infra.
  • Upload to windows store ?

from httpie.

jkbrzt avatar jkbrzt commented on April 27, 2024 8

Someone on Twitter has also mentioned Chocolatey, which looks like a decent package manager for Windows. That should allow you to install HTTPie using this simple command:

cinst httpie -source python

from httpie.

mahmoudhossam avatar mahmoudhossam commented on April 27, 2024 6

@mercury2269 This is not the sort of thing I'm talking about here, people should get Httpie up and running without even having to install python.

Many people aren't python people and installing pip on windows is a hassle nobody should go through, not even python developers.

from httpie.

Witchilich avatar Witchilich commented on April 27, 2024 4

Would love to install it through Scoop with scoop install httpie or choco install httpie. It's okay if Python is a dependency.
This is a Python script and I guess Python is a requirement.

from httpie.

jftuga avatar jftuga commented on April 27, 2024 4

I was able to successfully build a stand-alone http.exe binary inside of the mcr.microsoft.com/windows/servercore:ltsc2019 Docker container with Python 3.7.6 and PyInstaller 3.6. Docker Desktop 2.1.0.5 was used.

These are the commands...

Outside the Docker container:

mkdir c:\temp\outside
docker run -t -i --mount type=bind,src=c:\temp\outside,dst=c:\inside -w c:\ mcr.microsoft.com/windows/servercore:ltsc2019

You are now inside the Docker container:

curl -L https://aka.ms/nugetclidl -o nuget.exe
set PATH=%PATH%;c:\python\tools;c:\python\tools\scripts;c:\GitForWindows\tools\cmd
nuget install GitForWindows -ExcludeVersion
set PYVER=3.7.6
nuget install python -ExcludeVersion -Version %PYVER% -OutputDirectory .
python -m pip install --no-warn-script-location PyInstaller
python -m pip install pywin32
git clone https://github.com/jakubroztocil/httpie.git
cd httpie
python -m pip install -r requirements-dev.txt
python setup.py build
cd build\lib\httpie
echo sys.exit(main())>> core.py
pyinstaller -F --noupx -n http.exe core.py
cd dist
copy http.exe c:\inside
exit

You are now outside of the Docker container:

dir c:\temp\outside\http.exe

The resulting http.exe has a size of 11,605,534.

Could someone please confirm this procedure? Thanks.

EDIT:

A pre-built http.exe binary can be downloaded from here:

https://github.com/jftuga/HTTPie-Windows

Please read the Warnings section before using this.

from httpie.

jftuga avatar jftuga commented on April 27, 2024 4

@sergeevabc

https://github.com/jftuga/HTTPie-Windows

Please read the Warnings section before using this.

from httpie.

lucasteles avatar lucasteles commented on April 27, 2024 2

A Scoop alternative would be great

from httpie.

bambooCZ avatar bambooCZ commented on April 27, 2024 2

This is major problem for me as well. I am looking for an app like HTTPie, but portable exe. I need to debug reachability in clients LAN, but in production. Corporate environment. I definitelly won't install choco or python or pip ... you name it. I could use a single EXE, test it out and delete the EXE.

I guess I will have to build my own using Electron: unizp, test, delete - that's it. No system-wide hassle.

from httpie.

cprivitere avatar cprivitere commented on April 27, 2024 2

A Scoop alternative would be great

choco is kind of dead at this point, so winget (or scoop if winget is not palatable for some reason) would be nice for both cli and desktop.

from httpie.

andraaspar avatar andraaspar commented on April 27, 2024 2

Winget please: https://learn.microsoft.com/en-us/windows/package-manager/winget/

from httpie.

mercury2269 avatar mercury2269 commented on April 27, 2024

Scott Hanselman has a step by step guide on how to install it on windows

http://www.hanselman.com/blog/InstallingHTTPIEHTTPForHumansOnWindowsGreatForASPNETWebAPIAndRESTfulJSONServices.aspx

from httpie.

mahmoudhossam avatar mahmoudhossam commented on April 27, 2024

But that would require the user to have it installed, wouldn't a standalone installer be better?

Edit: I'll try to make a windows installer using py2exe and Inno Setup

from httpie.

nchammas avatar nchammas commented on April 27, 2024

Another option for packaging httpie as a standalone package that includes Python is PyInstaller. I haven't used it myself, but the project is very active.

You could probably even automate the process of generating a Windows package as part of httpie's CI using AppVeyor.

from httpie.

jkbrzt avatar jkbrzt commented on April 27, 2024

https://github.com/chocolatey/choco/wiki

from httpie.

AdrianoCahete avatar AdrianoCahete commented on April 27, 2024

I created a PowerShell script to install hpttpie and already pushed a PR, feel free to use this script to install on a windows machine.

from httpie.

sergeevabc avatar sergeevabc commented on April 27, 2024

Still no stand-alone .exe for Windows like aria2c.exe, curl.exe, wget.exe?

from httpie.

jonaseriksson84 avatar jonaseriksson84 commented on April 27, 2024

Yeah, installing httpie on a Windows machine without Internet access is a real pain, would also love a package like this. Unfortunately my personal skill aren't quite enought to create it myself yet...

from httpie.

sergeevabc avatar sergeevabc commented on April 27, 2024

Just noticed that issue asking for Windows package was created in 2012, whereas we are in 2017 now.

from httpie.

digitalcoyote avatar digitalcoyote commented on April 27, 2024

I'd be willing to create/maintain a package for Chocolatey. Let me know if this is still desired.

from httpie.

sergeevabc avatar sergeevabc commented on April 27, 2024

@jftuga, would you care to share your http.exe with mere Windows users without compiler stuff?

from httpie.

sergeevabc avatar sergeevabc commented on April 27, 2024

@jftuga, works as expected, at least basic actions. Thank you, sir.

from httpie.

Witchilich avatar Witchilich commented on April 27, 2024

Anyone checked the Scoop-Python bucket ? Its by the maintainer of nonportable bucket.

scoop bucket add python https://github.com/TheRandomLabs/Scoop-Python.git
scoop install httpie-py

There is a migrate-python-packages script that has to be run after every Python version update(every update for global install, major version update for user install).

from httpie.

NathanSweet avatar NathanSweet commented on April 27, 2024

FWIW, I came here looking for a Windows executable, don't want to install pip. Used the one linked above even though it isn't latest.

from httpie.

jkbrzt avatar jkbrzt commented on April 27, 2024

This is great. Thanks, @ksamuel! We’ll look into exploring this approach. 🧪

from httpie.

Almad avatar Almad commented on April 27, 2024

Note: there is also an unofficial choco build of HTTPie that we could automate and also use in this build.

I wonder what's the usage of choco vs windows store for CLI tools on Win. Research needed.

from httpie.

ksamuel avatar ksamuel commented on April 27, 2024

Updated the zip link, the last one expired but @jakubroztocil needed it: https://drop.chapril.org/download/3519a0235828b6d2/#Mwzt7QE4O1FnlDDIrUXjjg

It's still gonna expire in 5 days :)

from httpie.

sschneider avatar sschneider commented on April 27, 2024

@jkbrzt is there anything new regarding the approach of @ksamuel?
I am really interested to use the tool, but I prefer a portable approach without footprint of other things.

from httpie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.