Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
add poetry python packages manager handler #50 , format files
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Jul 2, 2022
1 parent 27445a9 commit a8643d2
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 16 deletions.
13 changes: 12 additions & 1 deletion docker/full.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ENV PATH /go/bin:$PATH
RUN rm "$(curl https://go.dev/VERSION?m=text).linux-amd64.tar.gz"

### deno ###
RUN curl -fsSL https://deno.land/x/install/install.sh | sh
RUN curl -fsSL https://deno.land/install.sh | sh
ENV DENO_INSTALL="$HOME/.deno"
ENV PATH="${DENO_INSTALL}/bin:${PATH}"

Expand All @@ -54,6 +54,9 @@ RUN tar -xzf gh.tar.gz
RUN sudo mv "gh_$(curl https://get-latest.herokuapp.com/cli/cli/no-v)_linux_amd64/bin/gh" /usr/bin
RUN rm -rf gh*

### fleet ###
RUN curl -L get.fleet.rs | sh

### pyenv ###
RUN pip install tld --ignore-installed six distlib --user
RUN curl https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
Expand All @@ -66,6 +69,14 @@ RUN /bin/bash -c "bash"
### pipenv ###
RUN curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python3

# poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3

ENV PATH="/root/.poetry/bin:$PATH"
RUN echo 'eval "$(poetry env install -q)"' >> ~/.bashrc
RUN echo 'eval "$(poetry env shell -q)"' >> ~/.bashrc
RUN /bin/bash -c "bash"

### rm old ~/.zshrc ###
RUN sudo rm -rf $ZSHRC
COPY ./tools/.zshrc .
Expand Down
2 changes: 1 addition & 1 deletion internal/pipes/new/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func updatePMs(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
m.PMCoice = 0
}
}
} else if m.LangChoice == 2 {
} else if m.LangChoice == 0 || m.LangChoice == 2 {
if m.PMCoice > 2 {
m.PMCoice = 2
}
Expand Down
5 changes: 4 additions & 1 deletion internal/pipes/new/discord_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"github.com/abdfnx/botway/templates/discord/csharp"
"github.com/abdfnx/botway/templates/discord/dart"
"github.com/abdfnx/botway/templates/discord/deno"
"github.com/abdfnx/botway/templates/discord/go"
dgo "github.com/abdfnx/botway/templates/discord/go"
"github.com/abdfnx/botway/templates/discord/nodejs"
"github.com/abdfnx/botway/templates/discord/python/pip"
"github.com/abdfnx/botway/templates/discord/python/pipenv"
"github.com/abdfnx/botway/templates/discord/python/poetry"
"github.com/abdfnx/botway/templates/discord/ruby"
"github.com/abdfnx/botway/templates/discord/rust"
)
Expand All @@ -18,6 +19,8 @@ func DiscordHandler(m model) {
pip.DiscordPythonPip(opts.BotName)
} else if m.PlatformChoice == 0 && m.LangChoice == 0 && m.PMCoice == 1 {
pipenv.DiscordPythonPipenv(opts.BotName)
} else if m.PlatformChoice == 0 && m.LangChoice == 0 && m.PMCoice == 2 {
poetry.DiscordPythonPoetry(opts.BotName)
} else if m.PlatformChoice == 0 && m.LangChoice == 1 {
dgo.DiscordGo(opts.BotName)
} else if m.PlatformChoice == 0 && m.LangChoice == 2 && m.PMCoice == 0 {
Expand Down
8 changes: 8 additions & 0 deletions internal/pipes/new/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func BotStartCmd(m model) string {
} else {
return `pipenv run python3 ./src/main.py`
}
} else if m.LangChoice == 0 && m.PMCoice == 2 {
if runtime.GOOS == "windows" {
return `poetry run .\src\main.py`
} else {
return `poetry run ./src/main.py`
}
} else if m.LangChoice == 1 {
if m.PlatformChoice == 2 {
return nodeCmd
Expand Down Expand Up @@ -111,6 +117,8 @@ func BotPM(m model) string {
return "pip"
} else if m.LangChoice == 0 && m.PMCoice == 1 {
return "pipenv"
} else if m.LangChoice == 0 && m.PMCoice == 2 {
return "poetry"
} else if m.LangChoice == 1 {
return "go mod"
} else if m.LangChoice == 2 && m.PMCoice == 0 {
Expand Down
6 changes: 5 additions & 1 deletion internal/pipes/new/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ func pmsView(m model) string {

if m.LangChoice == 0 {
langs += fmt.Sprintf(
"%s\n%s",
"%s\n%s\n%s",
checkbox("pip", pm == 0),
checkbox("pipenv", pm == 1),
checkbox("poetry", pm == 2),
)
} else if m.LangChoice == 1 {
if m.PlatformChoice == 2 {
Expand Down Expand Up @@ -192,6 +193,9 @@ func finalView(m model) string {

case 1:
pm = "pipenv"

case 2:
pm = "poetry"
}

case 1:
Expand Down
2 changes: 1 addition & 1 deletion packages/botway_dart/lib/botway_dart.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
library botway_dart;

export 'src/botway_dart_base.dart';
export "src/botway_dart_base.dart";
14 changes: 7 additions & 7 deletions packages/botway_dart/lib/src/botway_dart_base.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'dart:io';
import 'dart:convert';
import 'package:yaml/yaml.dart';
import 'package:path/path.dart' as p;
import "dart:io";
import "dart:convert";
import "package:yaml/yaml.dart";
import "package:path/path.dart" as p;

/// This is Botway class
class Botway {
get_bot_info(String value) {
if (File(".botway.yaml").existsSync()) {
String BotConfigFile = File('.botway.yaml').readAsStringSync();
String BotConfigFile = File(".botway.yaml").readAsStringSync();
dynamic BotConfig = loadYaml(BotConfigFile);

return BotConfig["bot"][value];
Expand All @@ -17,10 +17,10 @@ class Botway {
}

String? get HomePath =>
Platform.environment['HOME'] ?? Platform.environment['USERPROFILE'];
Platform.environment["HOME"] ?? Platform.environment["USERPROFILE"];

String BotwayConfigFile() {
File BWFile = File(p.join(HomePath.toString(), '.botway', 'botway.json'));
File BWFile = File(p.join(HomePath.toString(), ".botway", "botway.json"));

if (BWFile.existsSync()) {
return BWFile.readAsStringSync();
Expand Down
81 changes: 81 additions & 0 deletions templates/discord/python/poetry/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package poetry

import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/abdfnx/botway/constants"
"github.com/abdfnx/botway/templates"
"github.com/abdfnx/botway/templates/discord/python"
"github.com/abdfnx/looker"
)

func PyProjectContent(botName string) string {
return templates.Content("pyproject.toml", "discord-python", botName)
}

func DiscordPythonPoetry(botName string) {
pythonPath := "python3"

if runtime.GOOS == "windows" {
pythonPath = "python"
}

_, err := looker.LookPath(pythonPath)
poetry, perr := looker.LookPath("poetry")

if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" python is not installed"))
} else if perr != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" poetry is not installed"))
} else {
dockerFileContent := templates.Content("poetry.dockerfile", "dockerfiles", botName)

mainFile := os.WriteFile(filepath.Join(botName, "src", "main.py"), []byte(python.MainPyContent()), 0644)
pyprojectFile := os.WriteFile(filepath.Join(botName, "pyproject.toml"), []byte(PyProjectContent(botName)), 0644)
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(dockerFileContent), 0644)
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(python.Resources()), 0644)

if mainFile != nil {
log.Fatal(mainFile)
}

if pyprojectFile != nil {
log.Fatal(pyprojectFile)
}

if dockerFile != nil {
log.Fatal(dockerFile)
}

if resourcesFile != nil {
log.Fatal(resourcesFile)
}

poetryAdd := poetry + " add discord-py-api botway.py pyyaml pynacl"

cmd := exec.Command("bash", "-c", poetryAdd)

if runtime.GOOS == "windows" {
cmd = exec.Command("powershell.exe", poetryAdd)
}

cmd.Dir = botName
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()

if err != nil {
log.Printf("error: %v\n", err)
}

templates.CheckProject(botName, "discord")
}
}
16 changes: 12 additions & 4 deletions templates/shared.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package templates

import (
"bytes"
"fmt"
"os"
"strings"

"github.com/abdfnx/botway/constants"
"github.com/abdfnx/resto/core/api"
"github.com/charmbracelet/lipgloss"
"github.com/spf13/viper"
)

func Content(arg, templateName, botName string) string {
Expand All @@ -24,11 +26,17 @@ func Content(arg, templateName, botName string) string {
os.Exit(0)
}

if strings.Contains(arg, ".dockerfile") || strings.Contains(arg, "Cargo.toml") || strings.Contains(arg, "shard.yml") || strings.Contains(arg, "pubspec.yaml") {
return strings.ReplaceAll(respone, "{{.BotName}}", botName)
} else {
return respone
if strings.Contains(arg, ".dockerfile") || strings.Contains(arg, "Cargo.toml") || strings.Contains(arg, "shard.yml") || strings.Contains(arg, "pubspec.yaml") || strings.Contains(arg, "pyproject.toml") {
respone = strings.ReplaceAll(respone, "{{.BotName}}", botName)

viper.SetConfigType("json")

viper.ReadConfig(bytes.NewBuffer(constants.BotwayConfig))

respone = strings.ReplaceAll(respone, "{{.Author}}", viper.GetString("user.github_username"))
}

return respone
}

func CheckProject(botName, botType string) {
Expand Down

0 comments on commit a8643d2

Please sign in to comment.