How to package the project using wheel in python - python

I am not aware about wheel. I have requirement.txt file. There is one more thing - wheel. I confused about wheel and requirement.txt. I want package my project using wheel.How I can package my project using wheel so I can easy install all the project dependencies using one shot.

You can use my git to make a new project with setup.py file and after that run
pip install -e .
to make a new version of your project
https://github.com/adouani/create_template
EDIT
Example:
# -*- coding: utf-8 -*-
import os
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.txt')) as f:
README = f.read()
with open(os.path.join(here, 'CHANGES.txt')) as f:
CHANGES = f.read()
with open(os.path.join(here, 'external_requirements.txt')) as f:
requires = f.readlines()
# on sépare la définition des dépendances internes des dépendances externes
requires.extend([
......
])
setup(
name='..........',
version='0.1.0.dev0',
description='',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
author='............',
author_email='',
url='',
keywords='web wsgi bfg pylons pyramid',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=requires,
message_extractors={'.': [
('ihm/**.py', 'lingua_python', None),
('ihm/**.pt', 'lingua_xml', None),
('ihm/**.html', 'html', None),
('ihm/**.py', 'python', None),
('ihm/**.js', 'js', None),
]},
dependency_links=[
'............',
'.............',
'git+http://............#egg=ihm-0.7.0',
],
)

Related

Add other files in Python distribution

I am working on a project which I have to share as a standalone SDK with my team. For some reason files other than *.py are not being added to my distribution file
My project structure is as given below
My Setup.py is like this
import setuptools
from glob import glob
from os.path import basename
from os.path import splitext
with open("README.md", "r") as fh:
long_description = fh.read()
with open('requirements.txt') as f:
install_requires = f.read().splitlines()[2:]
with open('requirements-dev.txt') as f:
tests_require = f.read().splitlines()[2:]
extras = {
'test': tests_require,
}
setuptools.setup(
name='eu-taxonomy-sdk',
version='0.0.2',
author='Bhushan Fegade',
author_email='bhushan.fegade#morningtar.com',
description='a calculation library for eu-taxonomy',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://msstash.morningstar.com/scm/dataapi/eu-taxonomy-sdk.git',
packages=setuptools.find_packages(where='src'),
package_dir={'': 'src'},
package_data={'eu-taxonomy-sdk': [ 'config/*', 'category/config/*' ]},
py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
license='Apache Software License',
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
],
install_requires=install_requires,
python_requires='~=3.8',
tests_require=tests_require,
extras_require=extras,
test_suite='tests'
)
I am using the following commands to generate a distributable file
python setup.py build
python setup.py sdist
I have tried making some changes in the setup.py file but the distributable file inside the config folder is always empty with only the init.py file and no other file is present.
I want to know if there is a way to keep those other files(CSV, parq) in the final distributable file.
Add a MANIFEST.in file that describes the files you need included.
E.g.
recursive-include src *.csv *.parq

python package not packaging files under a subdirectory

Here is my setup.py
from setuptools import setup, find_packages
import versioneer
REQUIRES = [
"requests",
"subprocess32",
"systemd"
]
CLASSIFIERS = [
...
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6"
]
setup(
author="IBM",
cmdclass=versioneer.get_cmdclass(),
description="A collections of utilities",
entry_points={},
install_requires=REQUIRES,
keywords=["management", "segment_sqls"],
license="XXX",
long_description="""Utilities for instance management and house keeping""",
packages=find_packages(),
tests_require=["pytest"],
url="https://github.ibm.com/myrepo/management",
name="management",
version=versioneer.get_version(),
classifiers=CLASSIFIERS
)
I am trying to run python3 setup.py sdist upload -r local to package and upload to my artifactory.The package's tar.gz is uploaded to artifactory with all files except the ones under segment_sqls. Here is my directory structure. init.py under segment_sqls is packaged but not the actual sql files. Is there any additional param that needs to be specified in setup.py to include all files?

How to package my python program so the user can install it using setup.py

I have a single python file right now and I am asked to convert it into a python module where the user can install it using python setup.py install. I am not sure how to do that. I have followed some instructions online and created the setup.py file and the init.py file. The setup.py file looks like this:
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="",
version="0.0.1",
author="",
author_email="",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
I am not sure if this setup.py file is correct.Also I don't know what I am supposed to do next. Can anyone help me and tell me what am I supposed to do? Is there tutorial that teaches this? I can't really find anything related. Also is my setup.py correct? Thanks!
There are several ways to do packaging. packaging Python Projects on python.org and setuptools docs are a good start.
Unfortunately, examples tend to focus on package distributions, not single modules. Instead of packages, use the py_modules keyword. Assuming your module is called "test.py", this setup.py will work
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="test",
version="0.0.1",
author="",
author_email="",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
py_modules = ["test"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
If you think this will expand to multiple modules, then you can go back to using
setuptools.find_packages(). In this case, you want a subdirectory named after your desired package and put the init in there
some_random_project_file
+-- setup.py
README.md
LICENCE
+-- test
+-- __init__.py
test.py

Module imports with and without setuptools build

I want to make my python app distributable but when I run it from command line from project folder all works well. After the packaging, there is a problem with module import.
All modules exists in package tlen. In my app I use eg. from Sender import Sender where Sender is tlen/Sender.py module.
All works well when I running tlen/main.py.
Problem exists when I try do package by sudo python setup.py install and run command tlen. Then I receive:
File "/usr/lib/python3.7/site-packages/tlen-1.0-py3.7.egg/tlen/main.py", line 3, in <module>ModuleNotFoundError: Nomodule named 'Sender'
Whole project:
https://github.com/tloszabno/tl_en
My setup.py file:
setuptools.setup(
name='tlen',
version='1.0',
author='Tomasz Łoś',
author_email='tloszabno#gmail.com',
description='A tool to learn foreign language',
packages=["tlen"],
entry_points={
'console_scripts': [
'tlen = tlen.main:main'
]
},
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
)
What I doing wrong with imports?
Hah I've solved it!
Just added app.py file to main dir (.. of tlen) with content:
#!/usr/bin/env python
from tlen import main as app
def main():
app.main()
if __name__ == '__main__':
main()
then setup.py:
import setuptools
setuptools.setup(
name='tlen',
version='1.0',
author='Tomasz Łoś',
author_email='tloszabno#gmail.com',
description='A tool to learn foreign language',
packages=["tlen"],
entry_points={
'console_scripts': [
'tlen = app:main'
]
},
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
scripts=[
'app.py',
]
)

Unable to get module to publish correctly with PyPi

I'm attempting to publish my module to PyPi but I'm running into troubles. It publishes, and I can install it via Pip, but I cannot seem to figure out the correct import statement to instantiate my class.
This is my setup.py file, the code lives in discord_webhooks.py within the same directory. Here's the published package.
from setuptools import setup, find_packages
long_description = open('README.md').read()
setup(
name='Discord Webhooks',
version='1.0.1',
packages=find_packages(exclude=['tests', 'tests.*']),
url='https://github.com/JamesIves/discord-webhooks',
author='James Ives',
author_email='iam#jamesiv.es',
description='Easy to use package for Python which allows for sending of webhooks to a Discord server.',
long_description=long_description,
license='MIT',
install_requires=[
'requests==2.20.0'
],
classifiers=[
'Programming Language :: Python :: 3'
],
)
I've attempted import DiscordWebhooks, and from discord_webhooks import DiscordWebhooks after doing pip install discord-webhooks but neither seem to work. Any help would be appreciated!
Managed to solve this one on my own. As this is a single file module I need to use py_modules inside of the setup.py file.
Here's the updated file:
from setuptools import setup, find_packages
long_description = open('README.md').read()
setup(
name='Discord Webhooks',
version='1.0.3',
py_modules=['discord_webhooks'],
url='https://github.com/JamesIves/discord-webhooks',
author='James Ives',
author_email='iam#jamesiv.es',
description='Easy to use package for Python which allows for sending of webhooks to a Discord server.',
long_description=long_description,
license='MIT',
install_requires=[
'requests==2.20.0'
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Other Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
],
)

Categories

Resources