Difference between revisions of "Nicegui widgets/Tutorial"

From BITPlan Wiki
Jump to navigation Jump to search
Line 41: Line 41:
 
This '''pyproject.toml''' file configures the Python project 'ConferenceCorpus', an API for accessing academic events and event series from different sources.  
 
This '''pyproject.toml''' file configures the Python project 'ConferenceCorpus', an API for accessing academic events and event series from different sources.  
  
== Build System ==
+
=== Build System ===
The <code>[build-system]</code> section specifies that the project uses 'hatchling' as its build backend, with:
+
The <code>[build-system]</code> section defines the build requirements and backend. It specifies the use of 'hatchling' as the build backend:
 
<source lang="toml">
 
<source lang="toml">
 
[build-system]
 
[build-system]
Line 48: Line 48:
 
build-backend = "hatchling.build"
 
build-backend = "hatchling.build"
 
</source>
 
</source>
More about Hatchling: [https://github.com/pypa/hatch Hatchling on GitHub].
+
Hatchling is a modern build backend for Python projects, aligning with PEP 517.
  
== Project Information ==
+
=== Project Metadata ===
The <code>[project]</code> section includes basic information about the project:
+
Under the <code>[project]</code> section, several key details about the project are listed:
 
<source lang="toml">
 
<source lang="toml">
 
[project]
 
[project]
Line 62: Line 62:
 
maintainers = [{name = "Wolfgang Fahl", email = "wf@WolfgangFahl.com"}]
 
maintainers = [{name = "Wolfgang Fahl", email = "wf@WolfgangFahl.com"}]
 
requires-python = ">=3.9"
 
requires-python = ">=3.9"
classifiers = [
+
classifiers = ['Programming Language :: Python', ...]
    'Programming Language :: Python',
 
    ...
 
]
 
 
dynamic = ["version"]
 
dynamic = ["version"]
 
</source>
 
</source>
The project's homepage: [https://raw.githubusercontent.com/WolfgangFahl/ConferenceCorpus/main/pyproject.toml pyproject.toml].
+
This section sets the project's name, description, homepage, README, license, authors, maintainers, required Python version, classifiers, and dynamic versioning.
 
 
== Version Control ==
 
Version control is dynamically set using the <code>[tool.hatch.version]</code> section:
 
<source lang="toml">
 
[tool.hatch.version]
 
path = "corpus/__init__.py"
 
</source>
 
  
== Dependencies ==
+
=== Dependencies ===
The <code>dependencies</code> list includes various libraries required by the project:
+
The <code>dependencies</code> section lists the required external libraries for the project to function:
 
<source lang="toml">
 
<source lang="toml">
 
dependencies = [
 
dependencies = [
Line 85: Line 75:
 
]
 
]
 
</source>
 
</source>
 +
These dependencies ensure that the necessary packages are installed for the project.
  
== Optional Dependencies and Scripts ==
+
=== Project Scripts ===
The file also defines optional dependencies under <code>[project.optional-dependencies]</code> and various scripts under <code>[project.scripts]</code> for different functionalities of the project:
+
The <code>[project.scripts]</code> section defines executable commands for various functionalities, with a focus on the `ccServer` script for starting the web server:
 
<source lang="toml">
 
<source lang="toml">
[project.optional-dependencies]
 
test = ["green",]
 
 
 
[project.scripts]
 
[project.scripts]
aelookup = "corpus.lookup:main"
+
ccServer = "corpus.web.cc_cmd:main"
 
...
 
...
 
</source>
 
</source>
  
== Project URLs ==
+
==== Understanding the ccServer Script ====
Lastly, the <code>[project.urls]</code> section provides links to the project's home, source, and documentation:
+
- '''Command''': <code>ccServer</code> is the command that users will run in the terminal.
 +
- '''Function''': The value <code>"corpus.web.cc_cmd:main"</code> specifies the Python function that gets executed when `ccServer` is invoked.
 +
  - '''Package and Module''': The first part, <code>corpus.web.cc_cmd</code>, is the Python package and module where the function resides.
 +
  - '''Function Name''': The second part, <code>main</code>, is the name of the function within that module.
 +
 
 +
==== Usage ====
 +
- To start the webserver, a user would execute the following command in the terminal:
 +
  <code>$ ccServer</code>
 +
- This command calls the `main` function from the `cc_cmd.py` file located in the `corpus.web` package, effectively initiating the web server for the ConferenceCorpus project.
 +
 
 +
=== Project URLs ===
 +
The <code>[project.urls]</code> section provides links to the project's home, source, and documentation:
 
<source lang="toml">
 
<source lang="toml">
 
[project.urls]
 
[project.urls]
Line 105: Line 104:
 
Documentation = "https://github.com/WolfgangFahl/ConferenceCorpus/issues"
 
Documentation = "https://github.com/WolfgangFahl/ConferenceCorpus/issues"
 
</source>
 
</source>
 +
These URLs direct users to relevant resources for the project.

Revision as of 10:23, 18 November 2023

Example Usecase

This tutorial uses the ConferenceCorpus as it's usecase. As part of my research for the ConfIDent Project i am gathering metadata for scientific events from different datasources. There has been a lack of a proper frontend for the past few years although there have been several attempts to create a webserver and RESTFul services e.g. with

As of 2023-11 the project is now migrated to [nicegui https://nicegui.io/] using the nicegui widgets (demo)

Setting up the project

The project is on github see ConferenceCorpus

README

A GitHub README is a document that introduces and explains a project hosted on GitHub, providing essential information such as its purpose, how to install and use it, and its features. It is important because it serves as the first point of contact for anyone encountering the project, helping them understand what the project is about and how to engage with it.

The README consists of

  • header
  • badges
  • link to demo
  • example API calls
  • links to documentation
  • authors list

README screenshot as of start of migration

CcReadme2023-11-18.jpg

License

The LICENSE file in a software project specifies the legal terms under which the software can be used, modified, and shared, defining the rights and restrictions for users and developers. Using the Apache License is a good choice for many projects because it is a permissive open-source license that allows for broad freedom in use and distribution, while also providing legal protection against patent claims and requiring preservation of copyright notices.

LICENSE

pyproject.toml

pyproject.toml

pyproject.toml is a configuration file used in Python projects to define project metadata, dependencies, and build system requirements, providing a consistent and standardized way to configure Python projects. For more information, see pyproject.toml documentation.

Hatchling is a popular choice for a build system because it offers a modern, fast, and straightforward approach to building and managing Python projects, aligning well with the standardized structure provided by pyproject.toml. Learn more about Hatchling at Hatchling on GitHub.

This pyproject.toml file configures the Python project 'ConferenceCorpus', an API for accessing academic events and event series from different sources.

Build System

The [build-system] section defines the build requirements and backend. It specifies the use of 'hatchling' as the build backend:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

Hatchling is a modern build backend for Python projects, aligning with PEP 517.

Project Metadata

Under the [project] section, several key details about the project are listed:

[project]
name = "ConferenceCorpus"
description = "python api providing access to academic events and event series from different sources"
home-page = "http://wiki.bitplan.com/index.php/ConferenceCorpus"
readme = "README.md"
license = {text = "Apache-2.0"}
authors = [{name = "Wolfgang Fahl", email = "wf@WolfgangFahl.com"}]
maintainers = [{name = "Wolfgang Fahl", email = "wf@WolfgangFahl.com"}]
requires-python = ">=3.9"
classifiers = ['Programming Language :: Python', ...]
dynamic = ["version"]

This section sets the project's name, description, homepage, README, license, authors, maintainers, required Python version, classifiers, and dynamic versioning.

Dependencies

The dependencies section lists the required external libraries for the project to function:

dependencies = [
    "pylodstorage>=0.4.9",
    ...
]

These dependencies ensure that the necessary packages are installed for the project.

Project Scripts

The [project.scripts] section defines executable commands for various functionalities, with a focus on the `ccServer` script for starting the web server:

[project.scripts]
ccServer = "corpus.web.cc_cmd:main"
...

Understanding the ccServer Script

- Command: ccServer is the command that users will run in the terminal. - Function: The value "corpus.web.cc_cmd:main" specifies the Python function that gets executed when `ccServer` is invoked.

 - Package and Module: The first part, corpus.web.cc_cmd, is the Python package and module where the function resides.
 - Function Name: The second part, main, is the name of the function within that module.

Usage

- To start the webserver, a user would execute the following command in the terminal:

 $ ccServer

- This command calls the `main` function from the `cc_cmd.py` file located in the `corpus.web` package, effectively initiating the web server for the ConferenceCorpus project.

Project URLs

The [project.urls] section provides links to the project's home, source, and documentation:

[project.urls]
Home = "http://wiki.bitplan.com/index.php/ConferenceCorpus"
Source = "https://github.com/WolfgangFahl/ConferenceCorpus"
Documentation = "https://github.com/WolfgangFahl/ConferenceCorpus/issues"

These URLs direct users to relevant resources for the project.