Package: lpk
learn-pythonmoduleminimum unit of module is a python file.a directory containing python files is also a module.a single file module is a binary__main__when executed aspython3 <path/to/file>.py, also is a library__init__when imported.a directory module can be a binary and executed aspython3 <path/to/directory>by containing__main__.py, also can be a library and imported by containing__init__.py.python tomodule/__init__.pyis as rust tomodule/mod.rs.
python tomodule.pyis almost as rust tomodule.rsbut also a binary.
top levelmodule/__main__.pyormodule.pyis as rust tosrc/main.rstop levelmodule/__init__.pyormodule.pyis as rust tosrc/lib.rs__main__and__init__are parts of meta info of a module.
there are a lot of other meta info. e.g.__name__packagepackage is also a module or collection of modules.
a package can be published tohttps://pypi.org/.
in actual, body of a package uploaded to the pypi registry is just a single module or some modules.
modules of a package are located under the project directly or the src directory by convention.poetryhttps://python-poetry.org/docs/the best package managing tool in Python project.
it was insipired by Rust's Cargo.manifest filepyproject.tomlhttps://python-poetry.org/docs/pyproject/initialize a packagepoetryinit# current directorypoetrynew<another># create another package under current directorycheck virtual environmentspoetryenvinfo# check executable section and set this custom path when using vscode via `Python: select interpreter`.poetryenvlistclear cachepoetrycacheclearpypi--all
find.|grep-E"__pycache__$"|xargsrm-rfpublish packagehttps://towardsdatascience.com/how-to-publish-a-python-package-to-pypi-using-poetry-aa804533fc6fhttps://www.digitalocean.com/community/tutorials/how-to-publish-python-packages-to-pypi-using-poetry-on-ubuntu-22-04make sure there is not same name package onhttps://pypi.orgpoetrysearch<package>currently you cannot publish with username and password.
you need to use api token.poetrybuild
poetrypublish-u=__token__-p=<yourpypiapitoken>if it's redundant to input token every time.poetryconfigpypi-token.pypi<yourpypiapitoken>and after thatpoetrybuild
poetrypublishprocess sources in a file only when executed as binary# processed whenever regardless of as library or binary....if__name__==__main__:# processed only when executed as binary....testingby convention, integration tests are located under top level tests directory.
and unittests are included in each module.frameworksunittest(std lib)https://docs.python.org/3/library/unittest.htmldoctest(std lib)https://docs.python.org/3/library/doctest.htmlpytesthttps://docs.pytest.org/https://github.com/pytest-dev/pytesthttps://pypi.org/project/pytest/documentingstandard or third-party tools list summaryhttps://realpython.com/documenting-python-code/#documentation-tools-and-resourceshttps://wiki.python.org/moin/DocumentationToolshostingreadthedocshttps://readthedocs.org/https://docs.readthedocs.io/en/stable/github pagescustom domain site of yours.generating/buildingsphinxhttps://www.sphinx-doc.org/en/master/https://github.com/sphinx-doc/sphinxhttps://pypi.org/project/Sphinx/functionalityautodoc rst from codesbuild static htmls from rstpublishusually automatically build & hosted from rst with readthedocs in CI/CD.you can also build html locally or in CI/CD & host on your own website.# first, create conf.py and index.rst in <docs_source_path> like this package.# then./sphinx_build.sh# open generated <docs_path>/sphinx_build/index.htmlmkdocshttps://www.mkdocs.org/https://pypi.org/project/mkdocs/https://github.com/mkdocs/mkdocsfunctionalitybuild static static htmls from markdownscannot autodoc from codes.pdoc (easy, simple)https://pypi.org/project/pdoc/https://github.com/mitmproxy/pdochttps://pdoc.dev/functionalityautodoc & build static htmls from codespublishyou can also build html locally or in CI/CD pipelines, then host on your own website, github pages or other hosting services ...automate this processes with CI/CD like github actions../pdoc_build.sh# open generated docs/with_pdoc/index.htmllintinghttps://code.visualstudio.com/docs/python/lintinghttps://code.visualstudio.com/docs/python/linting#_specific-linterslinterpylinthttps://github.com/PyCQA/pylinthttps://www.pylint.org/https://docs.pylint.org/https://pypi.org/project/pylint/flake8 (we recommend this)https://flake8.pycqa.org/en/latest/https://pypi.org/project/flake8/https://github.com/PyCQA/flake8mypy (we recommend)(typing linter)https://mypy-lang.org/https://mypy.readthedocs.io/en/stable/https://github.com/python/mypyhttps://pypi.org/project/mypy/pycodestyle(pep8 based)https://pypi.org/project/pycodestyle/https://pycodestyle.pycqa.org/en/latest/https://github.com/PyCQA/pycodestylepydocstylehttp://www.pydocstyle.org/en/stable/https://pypi.org/project/pydocstyle/https://github.com/PyCQA/pydocstyleprospectorhttps://prospector.landscape.io/en/master/https://pypi.org/project/prospector/https://github.com/PyCQA/prospectorpylamahttps://klen.github.io/pylama/https://github.com/klen/pylamahttps://pypi.org/project/pylama/bandithttps://bandit.readthedocs.io/en/latest/https://github.com/PyCQA/bandithttps://pypi.org/project/bandit/formattingformatterblack (we recommend)https://github.com/psf/blackhttps://black.readthedocs.io/en/stable/https://pypi.org/project/black/autopep8https://pypi.org/project/autopep8/https://github.com/peter-evans/autopep8isort (we recommend)sort importshttps://github.com/PyCQA/isorthttps://pycqa.github.io/isort/https://pypi.org/project/isort/CI/CD & automation supportingframeworkstoxhttps://tox.wiki/en/latest/index.htmlhttps://pypi.org/project/tox/https://github.com/tox-dev/toxnoxhttps://nox.thea.codes/en/stable/https://github.com/wntrblm/noxhttps://pypi.org/project/nox/invokehttps://www.pyinvoke.org/https://github.com/pyinvoke/invoke/https://pypi.org/project/invoke/Python public / private syntax conventionthere is no private module and file private objects limited by syntax.
by convention, to convey that a module or object is private to users,
you can make it start with a single underscore_.
and objects private too.
on the other hand, class members can be public, protected, private
protected member start with a single underscore_.
private member start with two under scores__.
class to protected member is as a file to private object.
private member is completely different. cannot accessible from outside normally. to access it,obj._ClassName__private_memberalso, private members are not inherited, so cannot be accessible anyhow through the childeren which inherited it.development with vscodeextensionsPythonPylanceLive ServerEven Better TOMLBash IDEautoDocstring - PythonGitLensmarkdownlintYAMLshell-format