I use include_package_data=True with setuptools.
Despite I have include_package_data=True when I run python setup.py install my *.xml and *.ttl (and other) files are not installed.
What is my error? Or is it a bug of setuptools? What to do?
From https://github.com/vporton/xml-boiler setup.py:
from coverage.annotate import os
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py as DistutilsBuild
class MyBuild(DistutilsBuild):
def run(self):
DistutilsBuild.run(self)
os.system('make')
setup(
name='xml-boiler',
version='0.0.2',
url='https://github.com/vporton/xml-boiler',
license='AGPLv3',
author='Victor Porton',
author_email='porton#narod.ru',
description='Automatically transform between XML namespaces',
use_scm_version=True,
setup_requires=['setuptools_scm'],
packages=find_packages(),
# package_data={'': ['**/*.xml', '**/*.ttl', '**/*.net', 'data/assets/*', 'data/scripts/*.xslt',
# 'xmlboiler/doc/*.html', 'xmlboiler/doc/*.css']},
include_package_data=True,
scripts=['bin/boiler'],
# Does not work for non-root install:
# data_files = [
# ('/etc/xmlboiler', ['etc/config-cli.ttl'])
# ],
test_suite="xmlboiler.tests",
cmdclass={'build_py': MyBuild},
)
Here is my MANIFEST.in:
recursive-include xmlboiler *.xml *.ttl *.xslt
recursive-include xmlboiler/core/data/assets *
I encountered the same issue using this MANIFEST.in:
include setup.json
recursive-include . *.coffee
the .coffee files were present in the .tar.gz file but not installed
the problem was not resolved by adding zip_safe=False
it was resolved by switching from recursive-include to individual includes
This is using
wheel 0.32.3
twine 1.12.1
setuptools 39.2.0
Needs zip_safe=False flag to prevent installation inside a ZIP file.
Related
I have a GUI Python app that I'm trying to distribute a desktop entry with. Normally, one would write a setup.py with setuptools that has this in it:
from setuptools import setup
setup(
name = 'myapp',
version = '0.0.1',
packages = ['myapp'],
data_files = [
('share/applications', ['myapp.desktop']),
],
)
This is deprecated, however, and my goal is to use only pyproject.toml in my repo with no setup.py or setup.cfg needed. I have been unable to find any information on how I would go about doing this.
I'm trying to make a python program into a package:
This is my setup.py
from setuptools import setup, find_packages
setup(
name='scroll',
version='2020.6.14',
# package_dir={'': 'scroll'},
packages=find_packages(),
install_requires=[
'Click',
],
entry_points='''
[console_scripts]
scroll=scroll:scroll
''',
# .... all other stuff
)
This is the module structure,
SCROLL
- scroll/
|
+--scroll.py
- setup.py
- MANIFEST.in
- venv/
When I run python setup.py sdist, a tar.gz file is created and when extracted, it contains the source code at projects\SCROLL\dist\scroll-2020.6.14\dist_scroll-2020.6\scroll-2020.6.14\scroll
But when I install the archive using pip install ./dist/scroll-2020.6.14.tar.gz,
Running scroll produces an ModuleNotFoundError: No module named 'scroll'
This is because during installation, the source code is not copied to SCROLL\venv\lib\python3.8\site-packages\.
Copying the scroll folder manually to site-packages solves this error
I have tried using MANIFEST.in file with contents below but the code is still not copied to site-packages
include scroll
recursive-include scroll *.py
I solved this by packaging the module using flit. I just found out it can create scripts too after asking the question.
For the how-to:
Refer to https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation
In my project, I have a single setup.py file that builds multiple modules using the following namespace pattern:
from setuptools import setup
setup(name="testmoduleserver",
packages=["testmodule.server","testmodule.shared"],
namespace_packages=["testmodule"])
setup(name="testmoduleclient",
packages=["testmodule.client","testmodule.shared"],
namespace_packages=["testmodule"])
I am trying to build wheel files for both packages. However, when I do:
python -m pip wheel .
It only ever builds the package for one of the definitions.
Why does only one package get built?
You cannot call setuptools.setup() more than once in your setup.py, even if you want to create several packages out of one codebase.
Instead you need to separate everything out into separate namespace packages, and have one setup.py for each (they all can reside in one Git repository!):
testmodule/
testmodule-client/
setup.py
testmodule/
client/
__init__.py
testmodule-server/
setup.py
testmodule/
server/
__init__.py
testmodule-shared/
setup.py
testmodule/
shared/
__init__.py
And each setup.py contains something along the lines
from setuptools import setup
setup(
name='testmodule-client',
packages=['testmodule.client'],
install_requires=['testmodule-shared'],
...
)
and
from setuptools import setup
setup(
name='testmodule-server',
packages=['testmodule.server'],
install_requires=['testmodule-shared'],
...
)
and
from setuptools import setup
setup(
name='testmodule-shared',
packages=['testmodule.shared'],
...
)
To build all three wheels you then run
pip wheel testmodule-client
pip wheel testmodule-server
pip wheel testmodule-shared
I'm trying get the file VERSION in the root of my python package installed into so that I can read from this file once it's installed, however using MANIFEST.in, the file is placed in the top-level /usr/lib/python3.6/site-packages rather than inside of /usr/lib/python3.6/site-packages/mypackage.
I'm trying to do this so that I can display the packages version at runtime and also easily make use of it inside of the repo.
directory structure:
setup.py
MANIFEST.in
VERSION
mypackage/
- __init__.py
- __main__.py
- foo.py
MANIFEST.in:
include VERSION
setup.py:
#!/usr/bin/env python3
from setuptools import setup, find_packages
with open("VERSION", "r") as versionFile:
version = versionFile.read().strip()
setup(
name="mypackage",
version=version,
packages=find_packages(),
include_package_data=True)
mypackage/__main__.py:
...
verFile = pkg_resources.resource_string(__name__, "VERSION")
with open(verFile, "r") as fin:
version = str(fin.read().strip())
print(version)
...
How can I get the VERSION file to install inside of the package directory?
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.