Unverified Commit c0fcaf71 authored by Sébastien Eustace's avatar Sébastien Eustace
Browse files

Add basic support for virtualenvs autogeneration

parent 241033c1
Loading
Loading
Loading
Loading
+6 −0
Changes for CHANGELOG.md: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Change Log

## [Unreleased]

### Added

- Added support for virtualenv autogeneration (Python 3.6+ only).


## [0.5.0] - 2018-03-14

poetry/config.py

0 → 100644
+88 −0
Changes for poetry/config.py: 88 added lines, 0 removed lines.
Original line number Diff line number Diff line
from pathlib import Path
from typing import Any

from .locations import CONFIG_DIR
from .utils.toml_file import TomlFile


class Config:

    def __init__(self, file: TomlFile):
        self._file = file
        self._raw_content = file.read(raw=True)
        self._content = file.read()
        
    @property
    def name(self):
        return str(self._file.path)

    @property
    def file(self):
        return self._file

    @property
    def raw_content(self):
        return self._raw_content

    @property
    def content(self):
        return self._content

    def setting(self, setting_name: str) -> Any:
        """
        Retrieve a setting value.
        """
        keys = setting_name.split('.')

        config = self._raw_content
        for key in keys:
            if key not in config:
                return None

            config = config[key]

        return config

    def add_property(self, key, value):
        keys = key.split('.')

        config = self._content
        for i, key in enumerate(keys):
            if key not in config and i < len(keys) - 1:
                config[key] = {}

            if i == len(keys) - 1:
                config[key] = value
                break

            config = config[key]

        self.dump()

    def remove_property(self, key):
        keys = key.split('.')

        config = self._content
        for i, key in enumerate(keys):
            if key not in config:
                return

            if i == len(keys) - 1:
                del config[key]
                break

            config = config[key]

        self.dump()

    def dump(self):
        self._file.write(self._content)

    @classmethod
    def create(cls, file, base_dir=None) -> 'Config':
        if base_dir is None:
            base_dir = CONFIG_DIR

        file = TomlFile(Path(base_dir) / file)

        return cls(file)
+0 −11
Changes for poetry/console/application.py: 0 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ class Application(BaseApplication):
        super().__init__('Poetry', Poetry.VERSION)

        self._poetry = None
        self._venv = Venv.create()

    @property
    def poetry(self) -> Poetry:
@@ -38,10 +37,6 @@ class Application(BaseApplication):
    def reset_poetry(self) -> None:
        self._poetry = None

    @property
    def venv(self) -> Venv:
        return self._venv

    def get_default_commands(self) -> list:
        commands = super(Application, self).get_default_commands()

@@ -58,9 +53,3 @@ class Application(BaseApplication):
            ShowCommand(),
            UpdateCommand(),
        ]

    def do_run(self, i, o) -> int:
        if self._venv.is_venv() and o.is_verbose():
            o.writeln(f'Using virtualenv: <comment>{self._venv.venv}</>')

        return super().do_run(i, o)
+3 −2
Changes for poetry/console/commands/add.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@ from poetry.installation import Installer
from poetry.semver.version_parser import VersionParser
from poetry.version.version_selector import VersionSelector

from .command import Command
from .venv_command import VenvCommand


class AddCommand(Command):
class AddCommand(VenvCommand):
    """
    Add a new depdency to <comment>poetry.toml</>.

@@ -66,6 +66,7 @@ If you do not specify a version constraint, poetry will choose a suitable one ba

        installer = Installer(
            self.output,
            self.venv,
            self.poetry.package,
            self.poetry.locker,
            self.poetry.pool
+2 −2
Changes for poetry/console/commands/build.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
from .command import Command
from .venv_command import VenvCommand

from poetry.masonry import Builder


class BuildCommand(Command):
class BuildCommand(VenvCommand):
    """
    Builds a package, as a tarball and a wheel by default.

Loading