Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
Create projects with optional virtualenv inside
Browse files Browse the repository at this point in the history
  • Loading branch information
constrict0r committed Nov 11, 2018
1 parent e31e303 commit 4ee2bdc
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 14 deletions.
49 changes: 40 additions & 9 deletions amanita/project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# -*- coding: utf-8 -*-

"""Project creation."""
import os
import sys
import subprocess

import click


class Project:
"""Template to create python projects"""
Expand All @@ -18,22 +22,49 @@ class Project:
venv = False
web = False

# Construct0r: create the project.
def __init__(self, destination, direnv=True, venv=True):
# Create the project.
def __init__(self, destination, direnv=False, venv=False):

# Create package folder structure.
try:
assert subprocess.call('poetry new -- ' +
destination, shell=True) == 0

except AssertionError:
print('seringa')
click.echo(click.style('An error occured creating the project',
fg='red'))
sys.exit(1)

print('adios')
# Virtual enviroment.
# self.venv_setup(destination)
# Create virtual enviroment.
if venv is True:
self.venv_setup(destination)

# Configure virtual enviroment.
# Create virtual enviroment.
@staticmethod
def venv_setup(destination):
def venv_setup(path):

from poetry.utils.env import Env

# TODO: test this:
# path = '/dev/null'

# This will overwrite an existing virtual enviroment.
try:
Env.build_venv(os.path.join(path, ".venv"))

click.echo('Created virtualenv ' + click.style('.venv',
fg='green') + ' in ' + click.style(path, fg='blue'))

except PermissionError:
click.echo(click.style('Error creating the virtual enviroment: ',
fg='red') +
click.style('Permission denied writing to ', fg='red') +
click.style(path, fg='green'))
sys.exit(1)

print(destination)
except NotADirectoryError:
click.echo(click.style('Error creating the virtual enviroment: ',
fg='red') +
click.style(path, fg='cyan') +
click.style(' is not a directory', fg='red'))
sys.exit(1)
11 changes: 6 additions & 5 deletions tests/test_amanita.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Amanita tests.import subprocess
# Amanita tests.
import os
import subprocess
import pytest

from amanita import amanita

Expand All @@ -14,9 +15,10 @@ def test_enjoy(capfd):


# Console script without arguments.
@pytest.mark.xfail
def test_console_no_args():

subprocess.check_call('amanita', env=os.environ.copy(), shell=True)
subprocess.check_call('amanita', env=os.environ.copy(), shell=True)


# Console script with arguments.
Expand All @@ -27,7 +29,6 @@ def test_console_args(capfd):
shell=True)
print(console_output)
out, err = capfd.readouterr()
assert "amanita" in out
assert 'amanita' in out


# Create test for poetry change config on settings.virtualenvs.in-project.
# ...
61 changes: 61 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Project tests.
import os
import pytest
import subprocess
import shutil


from amanita import project


# Create project.
def test_create_project():

subprocess.check_call('amanita muscaria',
env=os.environ.copy(),
shell=True)
shutil.rmtree(os.path.join('muscaria'))


# Create virtual enviroment.
def test_create_venv():

project.Project.venv_setup(os.path.join(''))
if not os.path.exists('.venv'):
return False
shutil.rmtree(os.path.join('.venv'))


# Create virtual enviroment with non existing path
@pytest.mark.xfail
def test_create_venv_nonexist():

project.Project.venv_setup('/dev/null')


# Create virtual enviroment with non permission
@pytest.mark.xfail
def test_create_venv_forbidden():

project.Project.venv_setup('/root')


# Overwrite virtual enviroment.
def test_overwrite_venv():

project.Project.venv_setup(os.path.join(''))
project.Project.venv_setup(os.path.join(''))
if not os.path.exists('.venv'):
return False
shutil.rmtree(os.path.join('.venv'))


# Create project with virtual enviroment.
def test_create_project_venv():

subprocess.check_call('amanita muscaria -e',
env=os.environ.copy(),
shell=True)
if not os.path.exists('muscaria/.venv'):
return False
shutil.rmtree(os.path.join('muscaria'))

0 comments on commit 4ee2bdc

Please sign in to comment.