I'm having an issue with running setup.py/pip in a chroot environment.
Here's the scoop:
Normal directory location:
/local/my_dir/project/src/qa/libs
Chroot-ed location
/src/qa/libs
Here's my setup.py file:
#!/usr/bin/env
from __future__ import (unicode_literals, print_function, division,
absolute_import)
from setuptools import find_packages, setup
test = [
'mock',
'pytest',
'pytest-cov',
]
setup(
name='libs',
version=0.1,
description='Some desc',
long_description=open('README').read(),
author='insert_author_here',
author_email='insert_email_here',
packages=find_packages(),
package_dir={},
include_package_data=True,
tests_require=test,
install_requires=[],
keywords=['qa', 'framework'],
extras_require={
'test': test,
}
)
When running python setup.py develop in the libs directory everything goes swimmingly during the install until the very end.
Installed /src/qa/libs
Processing dependencies for libs==0.1
Finished processing dependencies for libs==0.1 # <-- It hangs here
This doesn't happen when I'm not currently in chroot (required for the environment) and it seems like setuptools/distribute is getting stuck in a recursive filesystem looking for things to clean up. Any idea how to fix this?
Installing a requirements.txt file with pip doesn't have any problems like this, so I think it might be the structure of the setup.py file.
It turns out the hang occurred during during the bash script that created the virtualenv and installed this package. I figured this out by executing the script with the bash -x my_script command, which showed the actual executing command when the hang occurred.
The setup.py file correctly installs the package and exits successfully.
Related
I want to run a bash shell script before running setup is called in a setup.py:
from numpy.distutils.core import setup, Extension
from subprocess import call
err = call('sh dependencies.sh',shell=True)
if err:
raise Exception('The dependencies failed to compile.')
extensions = [...]
setup(name = 'Package',
packages=['Package'],
ext_modules=extensions)
When I run python -m pip install . -v, everything works. HOWEVER, the script dependencies.sh is run two times, compiling the dependencies two times. How do I do this properly? Thanks!
I built a python application (the "host" app) that defines a setuptools entry-point, so that it can be extended. Plugin-authors then have to add the following into their setup.py file:
setup(
# ...
entry_points = {
'myapp.plugins':
['plugin_1 = <foo.plugin.module>:<plugin-install-func>']
}
)
In order to test my setup, i have to
build a dummy wheel-package,
use pip to install it,
append new package's folder into sys.path and invoke pkg_resources.working_set.add_entry(package_dir)[*],
only then i can check the expected behavior (run TCs),
use pip to uninstall the package, and
finally remove installed package folder from sys.path,
And a separate package is needed for each test-case, if different functionality must be validated.
This whole testing-rig is rather verbose and clumsy.
Is there a more elegant way to write test-cases for setuptools entry-point plugins?
[*] Note: Installing a wheels or using pip* in develop mode with pip install -e <plugin-package> would not activate the plugin on the same interpreter on Linux; or at least not without appending afterwards the package folder in sys.path.
On Windows, the above problem exists only on develop mode.
I had a same problem and resolved by a dirty hack to build and 'pip install' the plugin package to test, into a tox's environment and run tests in that environment.
a test script does dirty hack, that is, to build and install a wheel package and run tests: https://github.com/ssato/yamllint-plugin-example/blob/master/tests/test_plugin.sh
tox configuration: https://github.com/ssato/yamllint-plugin-example/blob/master/tox.ini
I have build a small quiz using Tkinter in Python and I wish to release the game for all to play, so that people can just pip install and play the game.
I have gone through the docs to release a PyPi package, I released one, it gets successfully installed. However, I'm unable to launch the application from commandline nor can I look for the binary. I don't know where am I going wrong. Please help me out here.
My setup.py file looks like this
from setuptools import setup
from codecs import open
from os import path
here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.rst')) as f:
long_description = f.read()
setup(
name='py-quiz',
version='0.1.1',
description='Python based Quiz game.',
long_description=long_description,
author='Abhijit Nathwani',
author_email='abhijit.nathwani#gmail.com',
LICENSE='MIT',
url='https://github.com/abhijitnathwani/PyQuiz',
keywords='pyquiz tkinter'
)
To package it, I use
python setup.py sdist upload
The package is successfully added to PyPi package and I could install it using:
pip install py-quiz
The output of the installation:
Collecting py-quiz
Downloading py-quiz-0.1.1.tar.gz
Installing collected packages: py-quiz
Running setup.py install for py-quiz ... done
Successfully installed py-quiz-0.1.1
But then when i do,
user#somecomputer:~/PyQuiz$ py-quiz
py-quiz: command not found
How do I launch the game from command line? Please help me out here.
The application code is maintained here.
I finally solved the problem above by making the following changes.
There must be a package created in the directory and the folder structure should be as follows:
<Directory>
|-setup.py
|-dist
|-LICENCSE
|-readme
|-<package-name>
|-__init__.py
|-__main__.py
|-other files
and in the setup.py the following change should be
entry_points={
'console_scripts':['<command_name> = <package_name>.__main__:<function to be called>']
In my case, it is as follows:
entry_points={
'console_scripts':['py-quiz = py_quiz.__main__:main']
The main point is to create a package inside your project directory. This should solve major problems.
I have made a python package and my project directory looks like this :
MyProject
|-.pypirc
|- manifest.in
|- readme.rst
|- runnable.py # Main File
|- setup.py
The problem is that I have libraries like tkinter in the runnable.py which is making problem using requirement installation in linux. How can I make the modifications according to linux ? This is my first time with packaging a module.
My setup.py looks like this-
from setuptools import setup
from sys import platform
setup(name='randomdownloader',
version='0.1.6',
description='random downloader',
author='Pankaj',
author_email='xyz#gmail.com',
license='MIT',
py_modules=['runnable'],
install_requires=[
'youtube-dl',
'bs4',
'BeautifulSoup4',
'requests',
'tkinter',
])
Also it is not getting installing in my OSX during installation, this is the error I am getting.
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-vsthnrl2/urllib/
You could set a function to run sys.platform to distinguish between systems, catch the output and extract the first word. Then, accordingly to it, you could run apt-get install python3-tkfor all Debian-based distros, and for osx
xcode-select --install
brew uninstall python
brew install python --use-brewed-tk
You should ofcourse run all of these commands via
call({command}), preceeded by `import subprocess` in your python script.
This will require some tweaking, but it should point you to the right direction.
This is the tree structure of the module I'm writing the setup.py file for:
ls .
LICENSE
README.md
bin
examples
module
scratch
setup.py
tests
tox.ini
I configured my setup.py as follows:
from setuptools import setup, find_packages
setup(
name="package_name",
version="0.1",
packages=find_packages(),
install_requires=[
# [...]
],
extras_require={
# [...]
},
tests_require={
'pytest',
'doctest'
},
scripts=['bin/bootstrap'],
data_files=[
('license', ['LICENSE']),
],
# [...]
# could also include long_description, download_url, classifiers, etc.
)
If I install the package from my python environment (also a virtualenv)
pip install .
the LICENSE file gets correctly installed.
But running tox:
[tox]
envlist = py27, py35
[testenv]
deps =
pytest
git+https://github.com/djc/couchdb-python
docopt
commands = py.test \
{posargs}
I get this error:
running install_data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data/data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data/data/license
error: can't copy 'LICENSE': doesn't exist or not a regular file
Removing the data_files part from the setup.py makes tox running correctly.
Your issue here is that setuptools is not able to find the 'LICENSE' file in the files that have been included for building the source distribution. You have 2 options, to tell setuptools to include that file (both have been pointed to here):
Add a MANIFEST.in file (like https://github.com/pypa/sampleproject/)
Use include_package_data=True in your setup.py file.
Using MANIFEST.in is often simpler and easier to verify due to https://pypi.org/project/check-manifest/, making it possible to use automation to verify that things are indeed correct (if you use a VCS like Git or SVN).
pip install . builds a wheel using python setup.py bdist_wheel which is installed by simply unpacking it appropriately, as defined in the Wheel Specification: https://www.python.org/dev/peps/pep-0427/
tox builds a source distribution using python setup.py sdist, which is then unpacked and installed using python setup.py install.
That might be a reason for the difference in behavior for you.
I have some resource files inside my packages which I use during the execution. To make setup store them in a package with python code, I use include_package_data=True and I access them using importlib.resources. You can use backport for an older Python version than 3.7 or another library.
Before each release I have a script which verifies, that all files I need are placed inside a bdist wheel to be sure that everything is on the place.