How to use non-packaged Python code from GitHub - python

I'm trying to use the code from this repository. The problem is that it isn't a package (I think?) because it can't be found on PyPI and there's no setup.py file (so I can't use pip install git+<repo link>). How would I then be able to use this code in my project?
I've already read this question, which also involved not having a setup.py file, but the answer seems unsatisfactory to me. I'm under the impression that it wouldn't allow my project to be run on someone else's pc without them also manually installing the code from the aforementioned repo.
I've also thought about just downloading the code and adding a setup.py myself, but I think that would produce the same problem.
I'm clearly a little unclear on this subject and I can't find any explanation/solution anywhere else.

That repository doesn't seem to be properly packaged for library use at all.
I'd recommend forking it, making the changes you need to make it usable (moving the files into a package, adding a setup.py) and then using that as a git+https:// style requirement.

Related

Include a PIP module in my project so that user doesn't have to download it

Edit: I am self taught, I don't know the right terms.
This question is probably a duplicate but I am not able to find it. I need to include a python pip package in my application say numpy. I don't want the user to pip install -r requirements.txt I want to include the module when the user downloads the application.
you don't have to include pip when you build the app, because when you build the app, all depencies will be included in the app resources, i am not sure which app you are building, but in general, all depencies will be converted to pyc packages when building the app and compiled
It's a whole world to explore, honestly ) you need to explore the subjects of deployment and distribution; those will depend on target operating systems... I would suggest investigating Docker, which allows you to package the OS (some Unix), runtime and dependencies into one "thing".
Vendoring
The only way I can think of besides pip to do this with pure source code would be to vendor the code you need. This means downloading the source code of the package (like numpy) and including it in your project.
This comes with many potential issues including:
licensing issues
issues with installation if there are cpython files that need to be compiled
Having to manually update the files when new releases come out
increased download size for your source code
etc.
I would not recommend doing this unless there is a hard technical requirement for it, because it's a real hassle to deal with. If there is something in particular besides having to run the extra command as to a reason why you want to avoid pip it might help to better address this question.
Binary distribution
Also depending on the app you could look into something like pyinstaller to make a single .exe or binary file out of your app so they don't even need python or your dependencies, but be warned this has it's own set of complexities to look out for like having to build for every target platform (Windows, Mac and Linux).

What's the recommended way of renaming a project in pypi?

I want people that know of the old name to be directed to the new name.
For the pypi website, it's easy to upload a package with a README linking to the new package.
I'm not sure what's the best way to handle people using pip to install it. I assume it might be possible to show an error on pip install old_name, looking around it seems to be possible using cmdclass in setup.py and maybe throwing an exception in the right place but the documentation around it is scarce to put it mildly.
So I was wondering if anyone is aware of proper built-in systems for this, or common practices to handle this sort of thing.
Declare the new package a dependency of the old. See for example how scikit-learn does it: the old package sklearn declares in its setup.py:
install_requires=['scikit-learn'],
Thus everyone who does pip install sklearn automatically gets scikit-learn.
pypi-rename worked perfectly for me. It automates the process of making a README and redirecting users to the new package.
https://github.com/simonw/pypi-rename

Where do you clone Python module git repositories?

I'm interested in contributing to a GitHub Python module repo, but I'm not entirely sure where to clone it. This is a simple module, just an __init__.py and some .py files. No other files need to be installed or changed outside of the module's folder.
I would like to be able to clone the repository directly in my site-packages folder. When I want to use the library as is, I would switch to the master branch. If I want to develop a new feature, can branch off of devel. If I want to try out a new feature someone else implemented, I can switch to that particular branch. I can even keep it in the development branch, to get the latest, albeit possibly unstable, features. All this without having to change the import statement to point to a different location in any of my scripts. This option, even though is seems to do all the things I want it to do, seems a bit wrong for some reason. Also, I'm not sure what this would do to pip when calling python -m pip list --outdated. I have a feeling it won't know what the current version is.
Another option would be to clone it to some other folder and keep only the pip-installed variant in the site-packages folder. That way I would have a properly installed library in site-packages and I could try out new features by creating a script inside the repo folder. This doesn't seem nearly as flexible as the option above, but it doesn't mess with the site-packages folder.
Which is the best way to go about this? How do you clone repositories when you both want to work on them and use them with the latest features?
I think this is more a question about packaging and open source than Python itself, but I'll try to help you out.
If you want to host your package on Pip, you should go here, and there you'll see how to upload and tag appropriately your package for usage.
If you want to add some functionality to some open source library, what you could do is to try to submit a Pull Request to that library, so everybody can use it. Rules for PR are specific for each project, you you should ask the maintainer.
If your modification doesn't get merged into master, but you still want to use it without changing import statements, you could fork that repo, and publish your own modifications on, for instance, Github.
In that case, you could install you modifications like this:
pip install git+https://github.com/username/amazing-project.git
So in that way, your library will come from your own repo.
If you're going for the third option, I strongly recommend you using virtualenv, where you can create different virtual environments with different packages, dependencies and so on, without messing up with your Python installation. A nice guide is available here.

Why is conda build appending py27_0 to my package name if I'm building under python 3.6.1?

I'm trying to make a conda recipe for ProjectQ. Something weird is going on during the build process under both linux and osx. I can build and install the package by hand (i.e. using 'python setup.py install' from the cloned git repo directory). However, when I make a recipe that does exactly the same thing, it fails. On both linux and osx.
My build recipe is here. What is particularly weird is that even though I specify python 3.6.* under the build requirements in the meta.yaml file, the conda-build procedure names the package "projectq-v0.3.0-py27_0", and when it installs the package, it tries to do so in one of the python 2.7 directories, which is what I assume makes it fail.
So clearly I'm doing something dumb, but I can't for the life of me figure out what. Can anyone see anything I've done wrong? Thanks in advance.
I figured this out. Thanks to everyone who took the time to look over my question. There was truly no way that anyone could have figured this out for me, since it was rather specific to the package I was installing. I'm going to try to summarize what I've learned in case someone else runs into anything different.
First, as I noted in one of the comments, if you're specifying a specific version requirement under the build, you had better specify the same version requirement under run. Initially I had "python 3.6.*" specified under build, but just "python" under run. This caused the package to be named something ending with "-py27_0", since the package name, understandably, depends upon what's required to run it, not to build it.
The really tricky thing was to understand that there were additional requirements specified in the setup.py script that were being installed automatically when I ran "python setup.py install" by hand, but were not being run when I tried to build under conda. Once I added these requirements to the meta.yaml recipe, everything builds and tests fine.
So, the lessons are to be consistent with your conda requirements between build and run, and make sure you have all of the requirements listed, including bonus requirements that may be specified in the setup.py file.
Thanks again to all who looked at this.

What are simple instructions for creating a Python package structure and egg?

I just completed my first (minor) Python project, and my boss wants me to package it nicely so that it can be distributed and called from other programs easily. He suggested I look into eggs. I've been googling and reading, but I'm just getting confused. Most of the sites I'm looking at explain how to use Python eggs that were already created, or how to create an egg from a setup.py file (which I don't yet have). All I have now is an Eclipse pydev project with about 4 modules and a settings/configuration file. In easy steps, how do I go about structuring it into folders/packages and compiling it into an egg? And once it's an egg, what do I have to know about deploying/building/using it? I'm really starting from scratch here, so don't assume I know anything; simple step-by-step instructions would be really helpful...
These are some of the sites that I've been looking at so far:
http://peak.telecommunity.com/DevCenter/PythonEggs
http://www.packtpub.com/article/writing-a-package-in-python
http://www.ibm.com/developerworks/library/l-cppeak3.html#N10232
I've also browsed a few SO questions but haven't really found what I need.
Thanks!
All you need is read this: The Hitchhiker's Guide to Packaging
or install PasteScript using pip or easy_install, then
paster create your_package_name
and you'll get a template for your python package
You should hold to the standard packaging of distutils. Quoting James Bennett:
Please, for the love of Guido, stop using setuptools and easy_install, and use distutils and pip instead.
Starting from there, a quite standard distribution looks like:
module/
README
setup.py # follow http://docs.python.org/distutils/setupscript.html
tests/
You should be able to find what you need in one of the following, depending on what version of Python you're using:
http://docs.python.org/distutils/
http://docs.python.org/py3k/distutils/index.html

Categories