Skip to main content

learning python

Project description

learn-python

CI CD PyPI version readthedocs build status License: Apache pre-commit Github pages

module

minimum 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 as python3 <path/to/file>.py, also is a library __init__ when imported.
a directory module can be a binary and executed as python3 <path/to/directory> by containing__main__.py, also can be a library and imported by containing__init__.py.
python to module/__init__.py is as rust to module/mod.rs. python to module.py is almost as rust to module.rs but also a binary. top level module/__main__.py or module.py is as rust to src/main.rs top level module/__init__.py or module.py is as rust to src/lib.rs

__main__ and __init__ are parts of meta info of a module. there are a lot of other meta info. e.g. __name__

package

package is also a module or collection of modules. a package can be published to https://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.

poetry

https://python-poetry.org/docs/

the best package managing tool in Python project. it was insipired by Rust's Cargo.

manifest file

pyproject.toml https://python-poetry.org/docs/pyproject/

initialize a package

poetry init # current directory
poetry new <another> # create another package under current directory

check virtual environments

poetry env info # check executable section and set this custom path when using vscode via `Python: select interpreter`.
poetry env list

clear cache

poetry cache clear pypi --all
find . | grep -E "__pycache__$" | xargs rm -rf

publish package

make sure there is not same name package on https://pypi.org

poetry search <package>

currently you cannot publish with username and password. you need to use api token.

poetry build
poetry publish -u=__token__ -p=<your pypi api token>

if it's redundant to input token every time.

poetry config pypi-token.pypi <your pypi api token>

and after that

poetry build
poetry publish

process 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.
    ...

testing

by convention, integration tests are located under top level tests directory. and unittests are included in each module.

documenting

linting

formatting

CI/CD & automation supporting

Python public / private syntax convention

there 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_member also, private members are not inherited, so cannot be accessible anyhow through the childeren which inherited it.

development with vscode

extensions

  • Python
  • Pylance
  • Live Server
  • Even Better TOML
  • Bash IDE
  • autoDocstring - Python
  • GitLens
  • markdownlint
  • YAML
  • shell-format

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lpk-0.2.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

lpk-0.2.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file lpk-0.2.0.tar.gz.

File metadata

  • Download URL: lpk-0.2.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.1 Linux/5.15.0-58-generic

File hashes

Hashes for lpk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 be8e1dd90e2f746bb1ef6c6dbfdc141a8859982ec7443180473f6f912f3ab16d
MD5 68ecc7cde2daa4b2bda6da1b857b1487
BLAKE2b-256 aa0e0d73c03c07e3d475ae334ff96968540bcbd1e661387452866c281e6cefea

See more details on using hashes here.

File details

Details for the file lpk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: lpk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.1 Linux/5.15.0-58-generic

File hashes

Hashes for lpk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9cd9398b137660f74bd03b37861a588c69c050f61ca930bc14b6193f3cfc706
MD5 1130c497aeb8820871ca22dbc6d86858
BLAKE2b-256 3bcafaf4cd09f46a434769b4126394876d79b6a53c7347089e9a693b81d9ab8d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page