Skip to content

Commit

Permalink
fix: adjust python package manager run command (#134)
Browse files Browse the repository at this point in the history
* chore: add test project with Pipenv

Add test project with Pipenv and updates the test function
to work with both GitLab and Github

* fix: adjust Eta.js whitespace delimiter

Eta.js comes with an implemented way of handling white spaces(see: https://eta.js.org/docs/syntax/whitespace-control).
Some commands were using the delimiter _ at the end of the tag
which trims all withe space after it, in our case just put a space before
the delimiter resolves the problem.

ref #132
  • Loading branch information
joao10lima authored Jan 5, 2022
1 parent 5b37cc6 commit 57601ad
Show file tree
Hide file tree
Showing 22 changed files with 435 additions and 32 deletions.
8 changes: 4 additions & 4 deletions core/plugins/stack/python/mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Deno.test("Plugins > Check if python version and django project is identified PI
name: "pipenv",
commands: {
install: "python -m pip install pipenv; pipenv install --dev",
run: "pipenv run",
run: "pipenv run ",
},
},
type: "webApp",
Expand Down Expand Up @@ -203,7 +203,7 @@ Deno.test("Plugins > Check if python version and a non-django-project PIPENV", a
name: "pipenv",
commands: {
install: "python -m pip install pipenv; pipenv install --dev",
run: "pipenv run",
run: "pipenv run ",
},
},
type: null,
Expand Down Expand Up @@ -248,7 +248,7 @@ Deno.test("Plugins > Check if python version and django project is identified PO
name: "poetry",
commands: {
install: "python -m pip install poetry; poetry install",
run: "poetry run",
run: "poetry run ",
},
},
type: "webApp",
Expand Down Expand Up @@ -288,7 +288,7 @@ Deno.test("Plugins > Check if python version and a non-django-project POETRY", a
name: "poetry",
commands: {
install: "python -m pip install poetry; poetry install",
run: "poetry run",
run: "poetry run ",
},
},
type: null,
Expand Down
4 changes: 2 additions & 2 deletions core/plugins/stack/python/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const poetry: IntrospectFn<PackageManager | Error> = async (context) => {
name: "poetry",
commands: {
install: "python -m pip install poetry; poetry install",
run: "poetry run",
run: "poetry run ",
},
};
}
Expand All @@ -42,7 +42,7 @@ const pipenv: IntrospectFn<PackageManager | Error> = async (context) => {
name: "pipenv",
commands: {
install: "python -m pip install pipenv; pipenv install --dev",
run: "pipenv run",
run: "pipenv run ",
},
};
}
Expand Down
13 changes: 13 additions & 0 deletions tests/default_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,16 @@ test(
await assertExpectedFiles();
},
);

test(
{ fixture: "python/python-pipenv", args: ["--no-strict"] },
async (stdout, _stderr, code, assertExpectedFiles) => {
assertStringIncludes(stdout, "Detected stack: python");
assertStringIncludes(
stdout,
"No formatters for python were identified in the project, creating default pipeline with 'black' WITHOUT any specific configuration",
);
assertEquals(code, 0);
await assertExpectedFiles();
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
name: Format Python
on:
pull_request:
paths:
- "**.py"
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
- run: python -m pip install pipenv; pipenv install --dev

- run: python -m pip install pip black

- run: pipenv run black . --check
- run: pipenv run isort . -c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
name: Lint Python
on:
pull_request:
paths:
- "**.py"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
- run: python -m pip install pipenv; pipenv install --dev


# Adapts Flake8 to run with the Black formatter, using the '--ignore' flag to skip incompatibilities errors
# Reference: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html?highlight=other%20tools#id1
- run: pipenv run flake8 --ignore E203,E501,W503 .
- run: pipenv run bandit -r .
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
name: SAST Python
on:
pull_request:
paths:
- "**.py"
jobs:
semgrep:
name: Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: returntocorp/semgrep-action@v1
with:
config: >-
p/owasp-top-ten
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
name: Test Python
on:
pull_request:
paths:
- "**.py"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: "3.8"
- run: python -m pip install pipenv; pipenv install --dev

- name: Run Tests
run: |
python manage.py test
13 changes: 13 additions & 0 deletions tests/fixtures/python/python-pipenv/expected/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
stages:
- lint
- format
- sast
- test

include:
- local: ".gitlab-ci/pipelinit.python.lint.yaml"
- local: ".gitlab-ci/pipelinit.python.format.yaml"
- local: ".gitlab-ci/pipelinit.python.test.yaml"
- local: ".gitlab-ci/pipelinit.python.sast.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
format:
stage: format
image: python:3.8
needs: []
script:
- python -m pip install pipenv; pipenv install --dev
- python -m pip install pip black
- pipenv run black . --check
- pipenv run isort . -c
only:
refs:
- merge_requests
changes:
- "**/*.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
lint:
stage: lint
image: python:3.8
needs: []
script:
- python -m pip install pipenv; pipenv install --dev
# Adapts Flake8 to run with the Black formatter, using the '--ignore' flag to skip incompatibilities errors
# Reference: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html?highlight=other%20tools#id1
- pipenv run flake8 --ignore E203,E501,W503 .
only:
refs:
- merge_requests
changes:
- "**/*.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
semgrep:
stage: sast
image: returntocorp/semgrep-agent:v1
needs: ["format", "lint"]
only:
refs:
- merge_requests
changes:
- "**/*.py"
script: semgrep-agent
variables:
SEMGREP_RULES: >-
p/owasp-top-ten
bandit:
stage: sast
image: python:3.8
needs: ["format", "lint"]
script:
- python -m pip install pipenv; pipenv install --dev
- pipenv run bandit -r .
only:
refs:
- merge_requests
changes:
- "**/*.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated with pipelinit 0.3.0
# https://pipelinit.com/
test:
stage: test
image: python:3.8
needs: ["format", "lint", "bandit", "semgrep"]
only:
refs:
- merge_requests
changes:
- "**/*.py"
script:
- python -m pip install pipenv; pipenv install --dev
- python manage.py test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
platforms = ["github", "gitlab"]
21 changes: 21 additions & 0 deletions tests/fixtures/python/python-pipenv/project/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = "~=2.25"
gunicorn = "~=20.1"
whitenoise = "~=5.2"
django = "~=3.0"

[dev-packages]
flake8 = "~=3.9.2"
isort = "~=5.9.3"
bandit = "~=1.7.0"

[requires]
python_version = "3.8"

[pipenv]
allow_prereleases = true
Empty file.
Empty file.
14 changes: 14 additions & 0 deletions tests/fixtures/python/python-pipenv/project/api/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings")

application = get_asgi_application()
Loading

0 comments on commit 57601ad

Please sign in to comment.