Skip to content

Commit

Permalink
feat: prepare virtual environment
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoGuadrini committed Aug 29, 2024
2 parents b97878d + cc96936 commit d92da8e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release notes

## 0.0.4
Aug 29, 2024
- Add **prj_venv** function
- Fix grouped check tools
- Fix prompt errors

## 0.0.3
Aug 08, 2024
- Add **prj_test** function
Expand Down
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[package]
name = "psp"
version = "0.0.3"
version = "0.0.4"
edition = "2021"
authors = ["matteoguadrini"]
authors = ["matteoguadrini <matteo.guadrini@hotmail.it>"]
description = "PSP (Python Scaffolding Projects)"
readme = "README.md"
repository = "https://github.com/MatteoGuadrini/psp"

[dependencies]
inquire = "0.7"
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

```console
psp # Press Enter
Welcome to PSP (Python Scaffolding Projects): 0.0.3
Welcome to PSP (Python Scaffolding Projects): 0.0.4
> Name of Python project: test
> Do you want start git repository? Yes
> Do you want to start git repository? Yes
> Do you want unit test files? Yes
> Do you want to create a virtual environment? Yes
Project `test` created
```

Expand All @@ -16,9 +17,9 @@ Project `test` created
## Prerequisites

`psp` has three prerequisetes installed on own machine:
- git
- python3
- pip
- `git`
- `python3`
- `pip`

## Installation

Expand All @@ -27,16 +28,17 @@ To install compiled file into your machine, download it:
```console
# For Linux (all users)
sudo -i
curl -L https://github.com/MatteoGuadrini/psp/releases/download/v0.0.3/psp_linux > /usr/bin/psp
curl -L https://github.com/MatteoGuadrini/psp/releases/download/v0.0.4/psp_linux > /usr/bin/psp
chmod +x /usr/bin/psp

# For Linux (current user)
curl -L https://github.com/MatteoGuadrini/psp/releases/download/v0.0.3/psp_linux > $HOME/.local/bin/psp
curl -L https://github.com/MatteoGuadrini/psp/releases/download/v0.0.4/psp_linux > $HOME/.local/bin/psp
chmod +x $HOME/.local/bin/psp

# For MacOS
sudo curl -L https://github.com/MatteoGuadrini/psp/releases/download/v0.0.3/psp_macos > /usr/bin/psp
sudo chmod +x /usr/bin/psp
sudo su -
curl -L https://github.com/MatteoGuadrini/psp/releases/download/v0.0.4/psp_macos > /usr/bin/psp
chmod +x /usr/bin/psp
```

Instead, if you compile this project as own, follow this steps:
Expand All @@ -51,7 +53,7 @@ cd psp && cargo build && sudo cp -var target/debug/psp /usr/bin/psp
- [x] Scaffolding file and folder structures for your Python project
- [x] Prepare git and gitignore
- [x] Prepare unit test files (also with pytest)
- [ ] Prepare virtual environment
- [x] Prepare virtual environment
- [ ] Install dependencies
- [ ] Prepare pyproject.toml
- [ ] Prepare CI configuration files
Expand Down
37 changes: 31 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

// Constants
const VERSION: &str = "0.0.3";
const VERSION: &str = "0.0.4";

// Utility functions

Expand Down Expand Up @@ -60,6 +60,7 @@ fn prompt_text(question: &str, default: &str, help: &str) -> String {
answer.unwrap().to_string()
}

// Function for prompt confirm (yes/no)
fn prompt_confirm(question: &str, default: bool, help: &str) -> bool {
let answer = if help != "None" {
Confirm::new(question)
Expand Down Expand Up @@ -106,15 +107,16 @@ fn prj_name() -> String {

// Project git
fn prj_git(name: &str) -> bool {
let confirm = prompt_confirm("Do you want start git repository?", true, "None");
let confirm = prompt_confirm("Do you want to start git repository?", true, "None");
if confirm {
let output = std::process::Command::new("git")
.arg("init")
.current_dir(name)
.output()
.expect("error: something wrong with `git init`");
.expect("git should be installed");
// Check if command exit successfully
if !output.status.success() {
eprintln!("error: something wrong with `git init`");
exit(5)
}
// Create .gitignore file
Expand Down Expand Up @@ -192,7 +194,7 @@ fn prj_test(name: &str) {
Ok(_) => (),
}
let all_module = make_file(
format!("{name}/tests/all.py").as_str(),
format!("{name}/tests/test_{name}.py").as_str(),
format!(
"#! /usr/bin/env python3\n\n\n\
import unittest\n\n\n\
Expand All @@ -215,18 +217,41 @@ fn prj_test(name: &str) {
}
}

// Project venv
fn prj_venv(name: &str) -> bool {
let confirm = prompt_confirm("Do you want to create a virtual environment?", true, "None");
if confirm {
let output = std::process::Command::new("python3")
.args(["-m", "venv", "venv"])
.current_dir(name)
.output()
.expect("python should be installed");
// Check if command exit successfully
if !output.status.success() {
eprintln!("error: `venv` creation failed");
exit(7)
} else {
return true;
}
}
false
}

fn main() {
// Print welcome screen and version
println!("Welcome to PSP (Python Scaffolding Projects): {VERSION}");
// Check if Python 3 is installed
// Check dependencies tools
check_tool("python3");
check_tool("git");
check_tool("pip3");
// Create project structure by name
let name = prj_name();
// Start git
check_tool("git");
let _git = prj_git(&name);
// Unit tests
prj_test(&name);
// Virtual Environment
let _venv = prj_venv(&name);
// Finish scaffolding process
println!("Project `{name}` created")
}

0 comments on commit d92da8e

Please sign in to comment.