Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add common tasks via PoeThePoet (#17356)

Jonatan Witoszek56aafb6db705
diff --git a/.env.example b/.env.example
new file mode 100644
index 0000000000..cd8ff2b196
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,6 @@
+CELERY_BROKER_URL=redis://localhost:6379/1
+EMAIL_URL=smtp://localhost:1025
+SECRET_KEY=changeme
+HTTP_IP_FILTER_ALLOW_LOOPBACK_IPS=True
+DASHBOARD_URL=http://localhost:9000/
diff --git a/.gitignore b/.gitignore
index 7e08e82d76..3c74ccad12 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,6 +30,7 @@ ENV/
env.bak/
venv.bak/
Pipfile
+!.env.example
# Exported results file
django-queries-results.html
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7a68f84e71..f86b9e472b 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -99,6 +99,21 @@ Install pre commit hooks:
pre-commit install
```
+Create environment variables, by creating a `.env` file. You can use existing example for development:
+
+```shell
+cp .env.example .env
+```
+
+> [!NOTE]
+> Example env variables set-up Celery broker, mail server, allow `localhost` URLs and set Dashboard URL
+> so that your development setup works with additional services set-up via `docker compose`
+>
+> Learn more about each env variable in [Environment Variable docs](https://docs.saleor.io/setup/configuration)
+
+> [!TIP]
+> Env variables from `.env` file are loaded automatically by [Poe the Poet](https://poethepoet.natn.io/index.html) (when using `poe` commands below)
+
You are ready to go πŸŽ‰.
### Common commands
@@ -106,27 +121,49 @@ You are ready to go πŸŽ‰.
To start server:
```shell
-uvicorn saleor.asgi:application --reload
+poe start
+```
+
+to start Celery worker:
+
+```
+poe worker
+```
+
+to start Celery Beat scheduler:
+
+```shell
+poe scheduler
```
+> [!NOTE]
+> To learn more about Celery tasks and scheduler, check [Task Queue docs](https://docs.saleor.io/developer/running-saleor/task-queue#periodic-tasks)
+
To run database migrations:
```shell
-python manage.py migrate
+poe migrate
```
To populate database with example data and create the admin user:
```shell
-python manage.py populatedb --createsuperuser
+poe populatedb
```
-*Note that `--createsuperuser` argument creates an admin account for `[email protected]` with the password set to `admin`.*
+> [!NOTE]
+> `populatedb` populates database with example data and creates an admin account for `[email protected]` with the password set to `admin`.*
-To run Django shell:
+To build `schema.graphql` file:
```shell
-python manage.py shell
+poe build-schema
+```
+
+To run Django shell:
+
+```
+poe shell
```
## Managing dependencies
diff --git a/package.json b/package.json
index e70170acbc..0ed436d7df 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,6 @@
"release-it": "^15.6.0"
},
"scripts": {
- "build-schema": "python manage.py get_graphql_schema > saleor/graphql/schema.graphql",
"release": "release-it"
}
}
diff --git a/poetry.lock b/poetry.lock
index 9ef34a3f87..223498a42b 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -2989,6 +2989,18 @@ files = [
qa = ["flake8 (==5.0.4)", "mypy (==0.971)", "types-setuptools (==67.2.0.1)"]
testing = ["docopt", "pytest"]
+[[package]]
+name = "pastel"
+version = "0.2.1"
+description = "Bring colors to your terminal."
+optional = false
+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
+groups = ["dev"]
+files = [
+ {file = "pastel-0.2.1-py2.py3-none-any.whl", hash = "sha256:4349225fcdf6c2bb34d483e523475de5bb04a5c10ef711263452cb37d7dd4364"},
+ {file = "pastel-0.2.1.tar.gz", hash = "sha256:e6581ac04e973cac858828c6202c1e1e81fee1dc7de7683f3e1ffe0bfd8a573d"},
+]
+
[[package]]
name = "peewee"
version = "3.17.8"
@@ -3262,6 +3274,25 @@ files = [
dev = ["pre-commit", "tox"]
testing = ["pytest", "pytest-benchmark"]
+[[package]]
+name = "poethepoet"
+version = "0.32.2"
+description = "A task runner that works well with poetry."
+optional = false
+python-versions = ">=3.9"
+groups = ["dev"]
+files = [
+ {file = "poethepoet-0.32.2-py3-none-any.whl", hash = "sha256:97e165de8e00b07d33fd8d72896fad8b20ccafcd327b1118bb6a3da26af38d33"},
+ {file = "poethepoet-0.32.2.tar.gz", hash = "sha256:1d68871dac1b191e27bd68fea57d0e01e9afbba3fcd01dbe6f6bc3fcb071fe4c"},
+]
+
+[package.dependencies]
+pastel = ">=0.2.1,<0.3.0"
+pyyaml = ">=6.0.2,<7.0"
+
+[package.extras]
+poetry-plugin = ["poetry (>=1.2.0,<3.0.0)"]
+
[[package]]
name = "posuto"
version = "2025.1.0"
@@ -5774,4 +5805,4 @@ type = ["pytest-mypy"]
[metadata]
lock-version = "2.1"
python-versions = "~3.12"
-content-hash = "69135ddc680727483b44fba7675fe409f0576dbaa78211cfa4e82f0e3f142b7e"
+content-hash = "ee3d1bdbc410a32fc1c6e9e551aa0d5a57b6ab21f0e1203272e1ebaa90f233fc"
diff --git a/pyproject.toml b/pyproject.toml
index a800bcbbc1..210b5b6e7e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,6 +2,44 @@
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
+[tool.poe]
+envfile = ".env"
+
+[tool.poe.tasks]
+start.help = "Start development server with hot reload"
+start.cmd = "uvicorn saleor.asgi:application --reload"
+
+worker.help = "Start Celery worker"
+worker.cmd = "celery --app saleor.celeryconf:app worker -E"
+
+scheduler.help = "Start Celery Beat scheduler"
+scheduler.cmd = "celery --app saleor.celeryconf:app beat --scheduler saleor.schedulers.schedulers.DatabaseScheduler"
+
+build-schema.cmd = "python manage.py get_graphql_schema"
+build-schema.capture_stdout = "saleor/graphql/schema.graphql"
+build-schema.help = "Build GraphQL schema to saleor/graphql/schema.graphql file"
+
+migrate.cmd = "python manage.py migrate"
+migrate.help = "Run database migrations"
+
+release.shell = "npm run release"
+release.help = """
+Release new Saleor verison
+Prerequisities:
+- Node installed on machine
+- Run npm install to install dependencies
+"""
+
+shell.cmd = "python manage.py shell"
+shell.help = "Start Django shell in interactive mode"
+
+populatedb.cmd = "python manage.py populatedb --createsuperuser"
+populatedb.help = """
+Populates database with sample data and creates admin user with credentials:
+- password: admin
+"""
+
[tool.poetry]
name = "saleor"
version = "3.21.0-a.0"
@@ -134,6 +172,7 @@ package-mode = false
types-requests = "^2.31.0" # Cannot upgrade due to using an old version of urllib3 (https://github.com/saleor/saleor/issues/17130)
types-six = "^1.16.17"
vcrpy = ">=4.0,<7.0"
+ poethepoet = "^0.32.2"
ipdb = "^0.13.13"
[tool.deptry]