I have a directory with a lot of *.py files (scripts) and subdirs with *.py files.
How to add all *.py files from root directory to the package?
Now my setup.py is
from setuptools import setup, find_packages
setup(
name='my-awesome-helloworld-script', # This is the name of your PyPI-package.
version='0.1', # Update the version number for new releases
scripts=['????????????????????'], # The name of your scipt, and also the command you'll be using for calling it
# Packages
packages=find_packages(),
)
As you can see, I've solved addition question of folders with find_packages().
But how to add *.py files from root directory?
I am packaging with command python.exe setup.py sdist.
Thank you!
Solved with code:
from setuptools import setup, find_packages
pckgs=find_packages()
pckgs.append('.')
setup(
name='my-awesome-helloworld-script', # This is the name of your PyPI-package.
version='0.1', # Update the version number for new releases
# scripts=[''], # The name of your scipt, and also the command you'll be using for calling it
# Packages
packages=pckgs,
)
Related
Assume the project directory structure is below:
test-package:
__init__.py
hello.py
setup.py
And the setup.py is:
from setuptools import setup, find_packages
setup(
name="test-package",
packages=find_packages(),
version="1.0",
include_package_data=True,
)
'test-package' is the root directory of the project. Then do:
pip install .
In the site-packages directory, there is only:
test_package-1.0-py3.7.egg-info/
I can't see the source file 'hello.py'.
I know most python projects's package name is not the root directory of the project. But in case I want to create a root directory name as the package name like this, is that possible?
You need to make a parent folder for test-package and put setup.py in there also use underscores for the package name. Technically PEP8 recommends all lowercase with no underscores for package names, but it's not a strict recommendation.
my-project:
setup.py
test_package:
__init__.py
hello.py
this has a helpful tutorial: https://packaging.python.org/tutorials/packaging-projects/
Edit: package name should use underscores not dashes
I want to package .json files as well in the python egg file.
For example: boto package has endpoints.json file. But when I run python setup.py bdist_egg it does not include the json file in the egg. How do I include the Json file in the egg?
How do I include *.json file in the egg?
Below is the setup.py code
from setuptools import setup, find_packages, Extension
setup(
name='X-py-backend',
version='tip',
description='X Python backend tools',
author='meme',
packages=find_packages('python'),
package_dir={'': 'python'},
data_files=[('boto', ['python/boto/endpoints.json'])],
namespace_packages = ['br'],
zip_safe=True,
)
setup(
name='X-py-backend',
version='tip',
packages=find_packages('protobuf/target/python'),
package_dir={'': 'protobuf/target/python'},
namespace_packages = ['br'],
zip_safe=True,
)
You only need to list the file on data_files parameter. Here is the example.
setup(
name='X-py-backend',
version='tip',
description='XXX Python backend tools',
author='meme',
packages=find_packages('python'),
package_dir={'': 'python'},
data_files=[('boto', ['boto/*.json'])]
namespace_packages = ['br'],
zip_safe=True
)
You can see the details here. https://docs.python.org/2/distutils/setupscript.html#installing-additional-files
Another way to do this is to use MANIFEST.in files. you need to create a MANIFEST.in file in your project root. Here is the example.
include python/boto/endpoints.json
Please visit here for more information.https://docs.python.org/2/distutils/sourcedist.html#manifest-template
Well this works for me.
setup.py:
from setuptools import setup, find_packages
setup(
name="clean",
version="0.1",
description="Clean package",
packages=find_packages() + ['config'],
include_package_data=True
)
MANIFEST.in:
recursive-include config *
where there is a config file under the project root directory which contains a whole bunch of json files.
Hope this helps.
I tried to create executable of my File NewExistGUI2.py, where GUI is made using wxpython. The file depends upon other two files localsettings.py and Tryone.py. I referred to py2exe documentation, and created a setup.py file as:
from distutils.core import setup
import py2exe
setup(name = 'python eulexistdb module',
version = '1.0',
description = 'Python eXistdb communicator using eulexistdb module',
author = 'Sarvagya Pant',
py_modules = ['NewExistGUI2','localsettings','Tryone']
)
and compiled the program in command line using
python setup.py py2exe
But I didn't got any .exe file of the main program NewExistGUI2.py in dist folder created. What Should I do now?
I woul recommend you create a module (ExistGUI) with the following structure:
ExistGUI
\_ __init__.py
|_ localsettings.py
|_ Tryone.py
bin
\_ NewExistGUI2.py
Your init.py should have:
from . import localsettings, Tryone
__version__ = 1.0
Your setup.py should look something like:
from setuptools import setup, find_packages
import ExistGUI
import py2exe
setup(
name = 'ExistGUI',
version = ExistGUI.__version__,
console=['bin/NewExistGUI2.py'],
description = 'Python eXistdb communicator using eulexistdb module',
author = 'Sarvagya Pant',
packages= find_packages(),
scripts=['NewExistGUI2.py',],
py_modules = ['localsettings','Tryone'],
include_package_data=True,
zip_safe=False,
)
Then run python setup.py py2exe. Make sure you include any requirements for your module in setup.py. Also, remove the previously generated dist directory, just to be sure.
Hope this helps.
I have a project with this structure:
SomeProject/
bin/
CHANGES.txt
docs/
LICENSE.txt
MANIFEST.in
README.txt
setup.py
someproject/
__init__.py
location.py
utils.py
static/
javascript/
somescript.js
And a "setup.py" as follows:
#!/usr/bin/env python
import someproject
from os.path import exists
try:
from setuptools import setup, find_packages
except ImportError:
from distutils.core import setup, find_packages
setup(
name='django-some-project',
version=someproject.__version__,
maintainer='Some maintainer',
maintainer_email='some#manteiner.com',
packages=find_packages(),
include_package_data=True,
scripts=[],
url='https://github.com/xxx/some-project',
license='LICENSE',
description='Some project description.',
long_description=open('README.markdown').read() if exists("README.markdown") else "",
install_requires=[
"Django >= 1.4.0"
],
)
Then, when I upload it using the command:
python setup.py sdist upload
It seems ok, but there is no "static" folder with this "javascript" subfolder in the package. My "setup.py" was inspired on github.com/maraujop/django-crispy-forms that has a similar structure. Any hint on what is wrong on uploading this subfolders?
You should be able to add those files to source distributions by editing the MANIFEST.in file to add a line like:
recursive-include someproject/static *.js
or just:
include someproject/static/javascript/*.js
This will be enough to get the files included in source distributions. If the setuptools include_package_data option you're using isn't enough to get the files installed, you can ask for them to be installed explicitly with something like this in your setup.py:
package_data={'someproject': ['static/javascript/*.js']},
Use following
packages = ['.','templates','static','docs'],
package_data={'templates':['*'],'static':['*'],'docs':['*'],},
I cannot figure out how to write my setup.py script in order to include *.html files within the installed package.
Here is my attempt:
import os
from setuptools import setup, find_packages
setup(name='django-testapp',
version='0.1',
author='RadiantHex',
license='BSD',
keywords='testapp,django',
packages=['testapp']],
include_package_data=True,
data_files = os.walk('testapp'),
zip_safe = False,
)
The *.html files are contained within the testapp folder.
Any ideas?
Add following 'package_data' argument to the setup():
setup(...,
package_data={
'testapp' : ['testapp/*.html']
}, ...)