Skip to content

Commit

Permalink
Merge pull request #10 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.21
  • Loading branch information
pomponchik committed Sep 5, 2023
2 parents 535b90f + 702de5d commit 23899ce
Show file tree
Hide file tree
Showing 34 changed files with 93 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: pip list

- name: Run tests and show coverage on the command line
run: coverage run --source=installed --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
run: coverage run --source=instld --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m

- name: Upload reports to codecov
env:
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![Downloads](https://static.pepy.tech/badge/instld/month)](https://pepy.tech/project/instld)
[![Downloads](https://static.pepy.tech/badge/instld)](https://pepy.tech/project/instld)
[![codecov](https://codecov.io/gh/pomponchik/installed/branch/main/graph/badge.svg)](https://codecov.io/gh/pomponchik/instld)
[![codecov](https://codecov.io/gh/pomponchik/instld/graph/badge.svg?token=XuhCNeksjG)](https://codecov.io/gh/pomponchik/instld)
[![Test-Package](https://github.com/pomponchik/instld/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/instld/actions/workflows/tests_and_coverage.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/instld.svg)](https://pypi.python.org/pypi/instld)
[![PyPI version](https://badge.fury.io/py/instld.svg)](https://badge.fury.io/py/instld)
Expand Down Expand Up @@ -50,9 +50,9 @@ instld script.py
You can also call the [context manager](#context-manager-mode) from your code:

```python
import installed
import instld

with installed('some_package'):
with instld('some_package'):
import some_module
```

Expand Down Expand Up @@ -114,17 +114,17 @@ Since script launch mode uses a context manager to install packages "under the h

## Context manager mode

You can also use `instld` to install and use packages in runtime. The context manager `installed` generates a context. While you are inside the context manager, you can import modules using the usual `import` command:
You can also use `instld` to install and use packages in runtime. The context manager `instld` generates a context. While you are inside the context manager, you can import modules using the usual `import` command:

```python
with installed('some_package'):
with instld('some_package'):
import some_module
```

However, there are cases when you need the module to be imported strictly from a given context. In this case, it is better to use the `import_here` method:

```python
with installed('some_package') as context:
with instld('some_package') as context:
module = context.import_here('some_module')
```

Expand All @@ -138,7 +138,7 @@ The library provides isolation of various contexts among themselves, so in the s
You can install several packages by specifying their names separated by commas:

```python
with installed('package_1', 'package_2', 'package_3') as context:
with instld('package_1', 'package_2', 'package_3') as context:
module_1 = context.import_here('module_1')
module_2 = context.import_here('module_2')
module_3 = context.import_here('module_3')
Expand All @@ -149,9 +149,9 @@ In this case, all packages will be installed in one context and you can import t
You can also create separate contexts for different packages:

```python
with installed('package_1') as context_1:
with installed('package_2') as context_2:
with installed('package_3') as context_3:
with instld('package_1') as context_1:
with instld('package_2') as context_2:
with instld('package_3') as context_3:
module_1 = context_1.import_here('module_1')
module_2 = context_2.import_here('module_2')
module_3 = context_3.import_here('module_3')
Expand All @@ -162,8 +162,8 @@ In this case, each package was installed in its own independent context, and we
This capability is very powerful. You can place libraries in different contexts that are incompatible with each other. You can also install different versions of the same library in neighboring contexts. Here's how it will work using the [Flask](https://flask.palletsprojects.com/) example:

```python
with installed('flask==2.0.2') as context_1:
with installed('flask==2.0.0') as context_2:
with instld('flask==2.0.2') as context_1:
with instld('flask==2.0.0') as context_2:
flask_1 = context_1.import_here('flask')
flask_2 = context_2.import_here('flask')

Expand All @@ -176,10 +176,10 @@ with installed('flask==2.0.2') as context_1:

### Options

You can use [any options](https://pip.pypa.io/en/stable/cli/pip_install/) available for `pip`. To do this, you need to slightly change the name of the option, replacing the hyphens with underscores, and pass it as an argument to `installed`. Here is an example of how using the `--index-url` option will look like:
You can use [any options](https://pip.pypa.io/en/stable/cli/pip_install/) available for `pip`. To do this, you need to slightly change the name of the option, replacing the hyphens with underscores, and pass it as an argument to `instld`. Here is an example of how using the `--index-url` option will look like:

```python
with installed('super_test_project==0.0.1', index_url='https://test.pypi.org/simple/'):
with instld('super_test_project==0.0.1', index_url='https://test.pypi.org/simple/'):
import super_test
```

Expand All @@ -191,7 +191,7 @@ You cannot use options that tell `pip` where to install libraries.
By default, through the [context manager](#context-manager-mode), packages are installed in a temporary virtual environment, which is deleted after exiting the context. However, if you want to install the package in a permanent environment, there is also a way to do this: use the `where` argument.

```python
with installed('package', where='path/to/the/venv'):
with instld('package', where='path/to/the/venv'):
import package
```

Expand All @@ -206,7 +206,7 @@ When manually specifying the path to the virtual environment directory, you need
By default, you can see the output of the installation progress in the console:

```python
>>> with installed('flask'):
>>> with instld('flask'):
... import flask
...
Collecting flask
Expand Down Expand Up @@ -234,20 +234,20 @@ Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.2 Werkzeug-2.3.3 blinker-1.6.
If you don't want to see this output, pass the `catch_output` argument:

```python
>>> with installed('flask', catch_output=True):
>>> with instld('flask', catch_output=True):
... import flask
...
>>>
```

In case of installation errors, you will get an `installed.errors.InstallingPackageError` exception. From the object of this exception, you can get `stdout` and `stderr` even if you have forbidden the output:
In case of installation errors, you will get an `instld.errors.InstallingPackageError` exception. From the object of this exception, you can get `stdout` and `stderr` even if you have forbidden the output:

```python
from installed.errors import InstallingPackageError
from instld.errors import InstallingPackageError


try:
with installed('some_wrong_pack', catch_output=True):
with instld('some_wrong_pack', catch_output=True):
import some_wrong_module
except InstallingPackageError as e:
print(e.stdout)
Expand All @@ -268,7 +268,7 @@ logging.basicConfig(
]
)

with installed('flask', catch_output=True):
with instld('flask', catch_output=True):
import flask
```

Expand Down
2 changes: 1 addition & 1 deletion installed/__init__.py → instld/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from installed.module.proxy_module import ProxyModule
from instld.module.proxy_module import ProxyModule


sys.modules[__name__].__class__ = ProxyModule
File renamed without changes.
14 changes: 7 additions & 7 deletions installed/cli/main.py → instld/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
from tempfile import TemporaryDirectory
from threading import RLock

import installed
from installed.cli.parsing_comments.get_options_from_comments import get_options_from_comments
from installed.cli.parsing_arguments.get_python_file import get_python_file
from installed.cli.traceback_cutting.cutting import set_cutting_excepthook
import instld
from instld.cli.parsing_comments.get_options_from_comments import get_options_from_comments
from instld.cli.parsing_arguments.get_python_file import get_python_file
from instld.cli.traceback_cutting.cutting import set_cutting_excepthook


def start():
def main():
python_file = get_python_file()

with installed() as context:
with instld() as context:
lock = RLock()
old_import = builtins.__import__
locations = {}
Expand All @@ -37,7 +37,7 @@ def get_current_context(where):
if location_context is not None:
return location_context[1]

manager = installed(where=where)
manager = instld(where=where)
local_context = manager.__enter__()
locations[where] = (manager, local_context)
return local_context
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import lru_cache

from installed.errors import InstallingPackageError
from instld.errors import InstallingPackageError


@lru_cache()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from installed.errors import InstallingPackageError
from installed.cli.parsing_comments.get_comment_string import get_comment_string
from instld.errors import InstallingPackageError
from instld.cli.parsing_comments.get_comment_string import get_comment_string


def get_options_from_comments(frame):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import traceback
from contextlib import redirect_stderr

from installed.cli.traceback_cutting.traceback_utils import cut_base_of_traceback
from instld.cli.traceback_cutting.traceback_utils import cut_base_of_traceback


def create_cutting_excepthook(old_hook, base_size):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from threading import Thread, Lock
from subprocess import Popen, PIPE, CalledProcessError

from installed.module.empty_logger import EmptyLogger
from installed.errors import RestartingCommandError, RunningCommandError
from instld.module.empty_logger import EmptyLogger
from instld.errors import RestartingCommandError, RunningCommandError


class CommandExecuter:
Expand Down
4 changes: 2 additions & 2 deletions installed/module/context.py → instld/module/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from contextlib import contextmanager
import copy

from installed.module.lock import lock
from installed.common_utils.convert_options import convert_options
from instld.module.lock import lock
from instld.common_utils.convert_options import convert_options


class Context:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from io import StringIO
from contextlib import contextmanager

from installed.errors import InstallingPackageError, RunningCommandError
from installed.module.context import Context
from installed.module.runner import run_python as standard_runner
from installed.module.lock import lock
from instld.errors import InstallingPackageError, RunningCommandError
from instld.module.context import Context
from instld.module.runner import run_python as standard_runner
from instld.module.lock import lock


@contextmanager
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys
import logging

from installed.module.context_manager import pip_context
from installed.module.runner import run_python
from installed.module.empty_logger import EmptyLogger
from installed.common_utils.convert_options import convert_options
from instld.module.context_manager import pip_context
from instld.module.runner import run_python
from instld.module.empty_logger import EmptyLogger
from instld.common_utils.convert_options import convert_options


class ProxyModule(sys.modules[__name__].__class__):
Expand Down
2 changes: 1 addition & 1 deletion installed/module/runner.py → instld/module/runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from installed.module.command_executer import CommandExecuter
from instld.module.command_executer import CommandExecuter


def run_python(args, logger, catch_output):
Expand Down
12 changes: 10 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='instld',
version='0.0.20',
version='0.0.21',
author='Evgeniy Blinov',
author_email='zheni-b@yandex.ru',
description='The simplest package management',
Expand All @@ -19,15 +19,23 @@
install_requires=requirements,
entry_points = {
'console_scripts': [
'instld = installed.cli.main:start'
'instld = instld.cli.main:main'
]
},
classifiers=[
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'License :: OSI Approved :: MIT License',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Interpreters',
'Topic :: Utilities',
'Topic :: System :: Archiving :: Packaging',
'Topic :: System :: Archiving :: Installation/Setup',
],
)
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import pytest

from installed.cli.main import start
from instld.cli.main import main


@dataclass
Expand Down Expand Up @@ -47,7 +47,7 @@ def exit_handler(number): raise LocalError
returncode = 0
with redirect_stdout(stdout_buffer) as stdout, redirect_stderr(stderr_buffer) as stderr:
try:
start()
main()
stdout = stdout_buffer.getvalue()
stderr = stderr_buffer.getvalue()
before_stderr = str.encode(stderr)
Expand Down
Loading

0 comments on commit 23899ce

Please sign in to comment.