Python Revisited 2024: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Line 17: Line 17:
cd my-project
cd my-project
</syntaxhighlight>
</syntaxhighlight>
Now we can make the src/app/__main__.py
<syntaxhighlight lang="py">
from flask import Flask
def main() -> Flask:
    app = Flask(__name__)
    return app
def run():
    app = main()
    app.run("localhost", 5000)
if __name__ == "__main__":
</syntaxhighlight>
==Modify the pyproject.toml==
==Modify the pyproject.toml==
The main thing is to change the packages line. I had a bit of trouble getting pylance to find my packages because, maybe, I did not poetry install after this. See below.
The main thing is to change the packages line. I had a bit of trouble getting pylance to find my packages because, maybe, I did not poetry install after this. See below.

Revision as of 02:12, 27 October 2024

Introduction

A quick revisit to python to maybe improve/refresh my own knowledge.

Project Creation (Poetry)

Guess most folks know about this and knowing IT, some people will hate it, and some will love it. Coming fresh out of NodeJS and React/Nextjs, this seemed a good idea to me. I am starting to feel with AI, that technologies are going to be changing quickly and being able to get going quickly is useful. This looked easy but when I tried it, it was harder. Here goes

Make a Project

poetry new my-project

Make a Fask App

Now lets make a Flask app. We will start by putting the code in src/app

cd my-project
mkdir -p src/app
touch src/app/__init__.py
touch src/app/__main__.py
cd my-project

Now we can make the src/app/__main__.py

from flask import Flask

def main() -> Flask:
    app = Flask(__name__)

    return app

def run():
    app = main()
    app.run("localhost", 5000)

if __name__ == "__main__":

Modify the pyproject.toml

The main thing is to change the packages line. I had a bit of trouble getting pylance to find my packages because, maybe, I did not poetry install after this. See below.

[tool.poetry]
name = "my-project"
version = "0.1.0"
description = ""
authors = ["Bill Wiseman <bw@bibble.co.nz>"]
readme = "README.md"

packages = [{ include = "app", from = "src" }]

[tool.poetry.dependencies]
python = "^3.12"

[tool.poetry.group.dev.dependencies]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"