Skip to content

Commit

Permalink
feature/python (#12)
Browse files Browse the repository at this point in the history
* feature/python
* adds Python as a supported language (see #9)
* add black codeformatter (requires python3.6+)
* install python3.7-minimal and pip3
* add config file for custom options

* Fix typo: Blacked -> Black
  • Loading branch information
wookiefriseur authored Jul 6, 2020
1 parent 994abac commit 76fdfdb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .black-format.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 120
target-version = ['py27', 'py36', 'py37', 'py38']
5 changes: 5 additions & 0 deletions .docker/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ RUN apt-get update -y && \
RUN apt-get update -y && \
apt-get install -y golang

# Packages for formatting Python code
RUN apt-get update -y && \
apt-get install -y python3.7-minimal python3-pip && \
pip3 install black

COPY .docker/web/vhost.conf /etc/apache2/sites-available/000-default.conf

WORKDIR /srv/app
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ RUN apt-get update -y && \
RUN apt-get update -y && \
apt-get install -y golang

# Packages for formatting Python code
RUN apt-get update -y && \
apt-get install -y python3.7-minimal python3-pip && \
pip3 install black

COPY vhost.conf /etc/apache2/sites-available/000-default.conf
COPY . /srv/app

Expand Down
28 changes: 28 additions & 0 deletions app/CodeFormatter/BlackPythonCodeFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace DevCommunityDE\CodeFormatter\CodeFormatter;

/**
* Class BlackPythonCodeFormatter
*
* @package DevCommunityDE\CodeFormatter\CodeFormatter
*/
class BlackPythonCodeFormatter extends CodeFormatter
{

/**
* @var array
*/
protected static $supported_languages = [
'python',
];

/**
* @param string $file
* @return string
*/
protected function getShellCommand(string $file) : string
{
return 'black --quiet --config ' . __DIR__ . '/../../.black-format.toml \'' . $file . '\'';
}
}
1 change: 1 addition & 0 deletions app/CodeFormatter/CodeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract class CodeFormatter
* @var array
*/
protected static $code_formatters = [
BlackPythonCodeFormatter::class,
ClangCodeFormatter::class,
GoCodeFormatter::class,
];
Expand Down

0 comments on commit 76fdfdb

Please sign in to comment.