Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
As you all may know pip is a python package manager and everyone has worked with it to install python libs.

Some of the commands with pip that you may not know about it:

- freeze: output installed packages in requirements format. (you can grep and search for a specific package):


rply==0.7.4
rsa==3.2.3
sasl==0.2.1
scipy==0.13.0b1



- list: list installed packages:

tcpwatch (1.3.1)
telebot (0.0.3)
thrift (0.9.3)



- show: Show information about installed packages:

$ pip show pandas
Name: pandas
Version: 0.17.0
Summary: Powerful data structures for data analysis, time series,and statistics
Home-page: http://pandas.pydata.org
Author: The PyData Development Team
Author-email: pydata@googlegroups.com
License: BSD
Location: /Library/Python/2.7/site-packages
Requires: numpy, python-dateutil, pytz


Important note for devops: pip by default install a stable version of the package. If you need to install an unstable version of the package (latest version) use --pre flag to install pre-release package.

If you want to manage your custom python repository package versions (RC, Alpha, Beta, Stable, etc) add classifiers to your setup.py script like below:

setup(...,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: Web Environment',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Python Software Foundation License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python',
'Topic :: Communications :: Email',
'Topic :: Office/Business',
'Topic :: Software Development :: Bug Tracking',
],
)



The important part is Development Status :: 4 - Beta, which for stable release you would use Development Status :: 5 - Production/Stable.

To see list of pypi Development Status values read from the below link:
https://pypi.python.org/pypi?%3Aaction=list_classifiers

Now you can give versioning like Django 2.0b1 (for pre release) and Django 1.11.6 for stable release.
To see different classifiers see the link Django link below to learn more:
https://pypi.python.org/pypi/Django

#django #pip #pre_release #freeze #package #python #devops
To install your python module you need a setup.py file inside of your project. The content of the setup.py can be something like below:
setup(name=PROJECT_NAME,
version=PROJECT_VERSION,
description=PROJECT_DESCRIPTION,
long_description=PROJECT_LONG_DESCRIPTION,
author='Ali',
author_email='info@ali.com',
url='http://www.ali.com/',
license='SOMETHING',
entry_points=PROJECT_ENTRY_POINTS,
classifiers=[],
keywords='',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
namespace_packages=[],
install_requires=['LIST', 'OF', 'REQUIREMENTS'],
zip_safe=False,
test_suite='nose.collector')

Now if you want to install it on your machine as a package just:
python setup.py install

If you want to upload it into your python repository:
python setup.py sdist upload -r my_repo

NOTE: you should be in the root of your project before running the previous command.

my_repo server should be declared inside of ~/.pypirc:
[distutils]
index-servers =
my_repo

[my_repo]
repository: http://pypi.repo.my_host.com:5000
username: username
password: password

If you want to install something from your repository via pip you have to provide the extra-index-url argument:
--extra-index-url http://username:password@pypi.repo.my_host.com:5000 --trusted-host pypi.repo.my_host.com

NOTE: you can put inside of an ENV variable in OS to access it better and in more readable way.

#python #setuppy #setup #package #pypi #private_repo #pypirc #pip #install
Preventing installation of devDependencies node modules:

npm install in the package directory installs the dependencies in the local node_modules folder.

In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.

By default, npm install will install all modules listed as dependencies in package.json.

With the --production flag (or when the NODE_ENV environment variable is set to production`), `npm will not install modules listed in devDependencies.

#node #npm #package_json #devDependencies #NODE_ENV
In order to create a debian package from your shell script do as follow:

Let's consider our package name is dangling. We need to create 2 folders, first is called dangling and the second is DEBIAN which is inside of the dangling folder:
mkdir helloworld && mkdir helloworld/DEBIAN

You can copy the files into your package with the full paths on the destination filesystem. E.g. if you want to put a file in /usr/local/bin/ you put it in dangling/usr/local/bin/:
mkdir -p dangling/usr/local/bin
cp /usr/local/bin/dangling.sh dangling/usr/local/bin/

In your DEBIAN directory (created at the begining of the post), create a control file with the below content:
<span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Package: dangling
</span><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Version: 0.1
</span><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Maintainer: Alireza Hoseini
</span><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Architecture: all
</span><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Description: would wipe all docker dangling volumes out

NOTE: These are the mandatory fields in the control file.

Now build the package using dpkg-deb:
dpkg-deb --build dangling

This creates a dangling.deb file, which you can now install on any Debian installation with following command:
dpkg -i dangling.deb

#debian #deb #create #package #dpkg #build
Naming conventions and recipes related to packaging

Private (including closed-source) projects use a namespace

For internal/customer projects, use your company name as the namespace.

This rule applies to closed-source projectsi (local PyPi server).

As an example, if you are creating a "climbing" project for the "Python Sport" company: use "pythonsport.climbing" name, even if it is closed source.

NOTE: The above descriptions are derived from python PEP-423.

#python #package #packaging #pypi #pep423 #conflict