I haven't touched Python at all, but I happened to upgrade and brush up Kafka extensions for Azure Functions, so I need to update the Python library as part of that. occured.
I had a hard time because I didn't know the language specifications and tools so much, so I want to record what I learned.
Virtual Environment Since Python 3.4, a mechanism called Virtual Environment is installed as standard. This will separate the environment when you install the library. There is something close to the mechanism of managing the library of npm in node or bundle in Ruby.
Specifically, execute the following command.
$ python -m venv .venv
This will create a directory called .venv
. Execute the following command to enable venv
.
$ source .venv/bin/activate
This will allow future installations of libraries to be saved under .venv
so that python programs can reference the libraries installed under them while .venv
is activated. Will be.
setup.py
If you want to add a library, add an entry to setup.py
. [Repository] I contributed (https://github.com/Azure/azure-functions-python-library/blob/dev/setup.py)
$ python -m pip install -U -e ./[dev\]
This command will also install the dev
part of ʻextras_require in
setup.py. Note that
-U means ʻUpgrade
, which updates the package to a newer version. -e
means ʻEditable, which makes the installed library editable. It is usually not in an editable format. When debugging a library, you'll want to experiment and see the source, so it's a good idea to add
-e`.
setup.py
from setuptools import setup
from azure.functions import __version__
setup(
name='azure-functions',
version=__version__,
description='Azure Functions for Python',
long_description='Python support for Azure Functions is based on '
'Python3.[6|7|8], serverless hosting on Linux and the '
'Functions 2.0 and 3.0 runtime. This module provides the '
'rich binding definitions for Azure Functions for Python '
'apps.',
author='Microsoft Corporation',
author_email='[email protected]',
classifiers=[
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: MacOS :: MacOS X',
'Environment :: Web Environment',
'Development Status :: 5 - Production/Stable',
],
license='MIT',
packages=['azure.functions'],
package_data={
'azure.functions': ['py.typed']
},
extras_require={
'dev': [
'flake8~=3.7.9',
'mypy',
'pytest',
'requests==2.*',
'coverage'
]
},
include_package_data=True,
test_suite='tests'
)
Lint
I haven't tried it yet, but Python's Lint is quite quirky, so it's a good idea to include Linter.
PR Python PR for the first time in my life