Bundling win32lfn extension with Mercurial - python

I'm working on a Windows server application which uses Mercurial for folder synchronisation between servers (so that we only copy the changes each time). The installer includes a bundled hg folder including all the dlls etc for running Mercurial. This currently works well, however users have been reporting error with files with long paths.
There is an win32lfn extension which deals with this issue. I would like to add this to the Mercurial bundle in the installer.
If I copy the win32lfn.py file into the hg folder and add the relevent line to Mercurial.ini then run hg.eze, I get the message:
win32lfn: This extension requires the pywin32 extension
If I attempt to install Python for Windows Extensions (http://sourceforge.net/projects/pywin32/), the installer tells me I need to install Python 2.7 first. I can do this and get it working on my computer, however, I need to bundle this with my installer without requiring the user to install Python.
Mercurial comes with a Python bundled - how can I add the Python for Windows Extensions to this bundle? I have tried copying the dlls into the hg folder without success.
Can anyone direct me to a solution?

This is pretty fortuitous, I just made a commit to win32lfn removing the pywin32 dependency.

Related

Load .whl packages and dependencies dynamically from python executable during runtime

I am quite new on python environment and on pyinstaller, but I really need your help.
Context
I have a python app which loads plugins within code. Indeed, we provide new features for our users in the form of plugins, and we want them to be able to install and use those that interest them. We don't want to build a new executable file every new plugin.
We bundled our app in a executable with pyinstaller, a one folder, because it seems easier to add plugins.
pyinstaller --clean --paths=lib/python3.8/site-packages src/main.py
My plugins have sometimes external dependencies (lib, etc.), so foreach plugin here is my setup.py (with requirements, values from requirements.txt file) :
setup(name='package_name',version='0.0.1',include_package_data=True,install_requires=requirements,extras_require={'all': requirements})
My issue
I know how to import installed modules dynamically to my code:
module=__import__(module_name,globals(),locals(),[name],0)
This part works.
But I have difficulties to install completely and dynamically those plugins within my code.
The solution must work on a linux ans Windows machine.
What I tried
Let's imagine I want to import my test.whl plugin, which has a dependency with 'test2' package
Install the plugin with pip:
subprocess.run(["pip", "install", "--upgrade", package, "-t", my_one_folder_location])
Pro: if python and pip are installed on the Host machine it works
Cons : You need to have python and "pip" (not "pip3" etc) on the user computer and the path. You have to be careful to have the same python version than on the package, etc. Not a recommanded solution...
I also tried to use the python installed in the pyinstaller folder but did not succeed.
Import every plugins in a specific directory:
PyInstaller understands the “egg” distribution format often used for Python packages. If your script imports a module from an “egg”, PyInstaller adds the egg and its dependencies to the set of needed files.
I tried to put my .wheel packages in a folder "egg". Then my program detect the plugin, but it doesn't import my lib dependencies
__main__:Unexpected error: no module named 'test2'
I'm going around in circles and can't find any solutions: What is the best way to import my external .whl packages and all it's dependencies in a pyinstaller solution?

Create package with dependencies

Do you know how to create package from my python application to be installable on Windows without internet connection? I want, for example, to create tar.gz file with my python script and all dependencies. Then install such package on windows machine with python3.7 already installed. I tried setuptools but i don't see possibility to include dependencies. Can you help me?
Their are several Java tutorials on how to make installers that are offline. You have your python project and just use a preprogrammed Java installer to then put all of the 'goodies' inside of. Then you have an installer for windows. And its an executable.

python how to build an exe file like scrapy.exe, pip.exe, virtualenv.exe in windows system?

I've found that a lot of python libraries that install have xxx.exe files, such as scrapy.exe, pip.exe, virtualenv.exe, etc. in the Scripts directory. How do they do that?I can't find relevant information, please guide me, thank you very much. By the way, python is installed in the Windows system.
You can use PyInstaller. On Windows it can compile to a single .exe file.
PyInstaller bundles a Python application and all its dependencies into
a single package. The user can run the packaged app without installing
a Python interpreter or any modules. PyInstaller supports Python 2.7
and Python 3.4+, and correctly bundles the major Python packages such
as numpy, PyQt, Django, wxPython, and others.
https://pyinstaller.readthedocs.io/en/stable/
According to the docs you will need Build Tools for Visual Studio 2017 which can be downloaded directly from here
Alternatively, you could install Anaconda which comes packed with pre-compiled binaries.
i get my answer, it set entry_points ={'console_scripts':['xx'='yy']} in setup.py, when install or package, it can auto build .exe in Scripts directory.

Where is python.exe in a Windows tarball installation?

After installing Python 3.5.6 using a tarball (.gz file), I would like to run
C:\path\to\desired\venv\directory>c:\path\to\python\installation\Python-3.5.6\python -m venv venv
However, my Python-3.5.6 directory doesn't seem to include the necessary python.exe. After extracting Python from a tarball on Windows, what extra steps are required to produce the python executable?
Note: I already have Python 3.6 installed as the default.
That's not a "tarball installation". You downloaded the source code and extracted it manually into somewhere you shouldn't. This is roughly analogous to attempting to live in the blueprints of a house.
If for some reason you are determined to use 3.5.6, you will have to find an actual installer somewhere (there is no official one), or you will have to build it yourself. From PCbuild/readme.txt:
Quick Start Guide
Install Microsoft Visual Studio 2015, any edition.
Install Subversion, and make sure 'svn.exe' is on your PATH.
Run "build.bat -e" to build Python in 32-bit Release configuration.
(Optional, but recommended) Run the test suite with "rt.bat -q".
For more complete build instructions, see PCbuild/readme.txt.

How to install Trac Plugin and what is a python egg?

In Trac on Admin -> Plugins there is an option to install Plug-ins. Now this option expect you to upload an Python egg.
This would be all well but for the fact that all the Trac plug-ins I found are either plain .py files or zip files and are incompatible with the upload function (I tried it).
This leaves my with a bunch of questions:
Are there any Trac plug-ins which come as an Python egg?
What is an (Trac compatible) Python egg?
Is it difficult to repackage an .py file into a Trac compatible Python egg?
If not: how is it done?
Haven't used trac for a year, but what I remember is that most plugins are available trough subversion and already packed as an egg (which is kind of an installer in the python world, but I am not very familiar with the concept).
Most plugins are available at http://trac-hacks.org/ and the easiest way to install a plugin is
easy_install http://svn.domain.tdl/path/to/plugin/
the folder should contain a setup.py and a setup.cfg file.
easy_install checks the files out from svn and installs the plugin. You can find details here: http://trac.edgewall.org/wiki/TracPlugins
If the plugin makes database changes you have to call
trac-admin upgrade
from console.
http://trac.edgewall.org/wiki/TracAdmin
If I remember right, the install through the webinterface installs the plugin locally (for the instance) while easy_install installs it globally (for all running trac sites) and is the more common way to install a plugin.
Hint: After every plugin install you have to restart trac
Hint2: Most plugins don't tell you how to install and only give a link to the root of their svn. You only have to browse the svn folder and locate the folder containing the setup.py.
The rest is done with easy_install.
Example:
Plugin: http://trac-hacks.org/wiki/GoogleChartPlugin
Wiki pages tells you:
You can check out GoogleChartPlugin from here using Subversion, or browse the source with Trac.
where here links to http://trac-hacks.org/svn/googlechartplugin/
The svn contains two versions. Browse to http://trac-hacks.org/svn/googlechartplugin/0.11/trunk/ and copy the path.
Then do
easy_install http://trac-hacks.org/svn/googlechartplugin/0.11/trunk/
Answers to your questions in order.
Python eggs are binary packages which contain the code for the application and some metadata. They're not very different from debs or rpms in this sense. The egg itself is basically just a zip file which contains all the above mentioned files with specific names and layouts. For more information on eggs (the format and how to create them), please refer to http://www.ibm.com/developerworks/library/l-cppeak3.html. It's probably a little dated since the future (and present) of python packaging is a little hazy.
A trac plugin is a python program that uses the Trac plugin API to extend the functionality of trac. It can be packaged as an egg.
If your package is properly laid out and contains a setuptools/distribute setup.py file, then issuing the command python setup.py bdist_egg will create a .egg file for you. For details on this please refer to this(a little dated but complete) and this (more upto date but still in progress). The Trac Growl plugin mentions this on it's documentation page.
Please see above point.

Categories