Skip to content

Commit

Permalink
Merge pull request #12 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.23
  • Loading branch information
pomponchik committed Nov 28, 2023
2 parents ef4e473 + d95be80 commit b25aa61
Show file tree
Hide file tree
Showing 27 changed files with 131 additions and 67 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint

on:
push

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7']

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
shell: bash
run: pip install -r requirements_dev.txt

- name: Run ruff
shell: bash
run: ruff instld
4 changes: 2 additions & 2 deletions .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand All @@ -25,7 +25,7 @@ jobs:

- name: Install the library
shell: bash
run: python setup.py install
run: pip install .

- name: Print all libs
shell: bash
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ test.py
tests/cli/data/chpok
tests/cli/data/pok
.idea
.ruff_cache
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.290
hooks:
# Run the linter.
- id: ruff
args: [ instld ]
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore = ['E501', 'E712']
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![logo](https://raw.githubusercontent.com/pomponchik/instld/main/docs/assets/logo5.png)
![logo](https://raw.githubusercontent.com/pomponchik/instld/main/docs/assets/logo_5.png)

# INSTLD: the simplest package management

Expand All @@ -8,9 +8,11 @@
[![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)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

Thanks to this package, it is very easy to manage the lifecycle of packages.

- ⚡ Run your code without installing libraries.
- ⚡ You can use 2 different versions of the same library in the same program.
- ⚡ You can use incompatible libraries in the same project, as well as libraries with incompatible/conflicting dependencies.
- ⚡ It's easy to share written scripts. The script file becomes self-sufficient - the user does not need to install the necessary libraries.
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
Binary file added docs/assets/logo_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/presentation.pptx
Binary file not shown.
Binary file added docs/assets/terminal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 9 additions & 5 deletions instld/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import code
import builtins
import importlib
import importlib.util
import inspect
from contextlib import contextmanager
from tempfile import TemporaryDirectory
from threading import RLock

import instld
Expand Down Expand Up @@ -74,7 +74,7 @@ def import_wrapper(name, *args, **kwargs):
with set_import():
try:
result = __import__(name, *args, **kwargs)
except (ModuleNotFoundError, ImportError) as e:
except (ModuleNotFoundError, ImportError):
current_context.install(package_name, catch_output=catch_output, **options)
result = current_context.import_here(base_name)
sys.modules[base_name] = result
Expand All @@ -92,7 +92,7 @@ def import_wrapper(name, *args, **kwargs):

if python_file is None:
try:
import readline
import readline # noqa: F401
except ImportError:
pass

Expand Down Expand Up @@ -120,9 +120,13 @@ def push(self, line):
spec = importlib.util.spec_from_file_location('kek', os.path.abspath(python_file))
module = importlib.util.module_from_spec(spec)
sys.modules['__main__'] = module
set_cutting_excepthook(4)
if sys.platform.lower() in ('win32',):
cutting_trace_size = 4
else:
cutting_trace_size = 4
set_cutting_excepthook(cutting_trace_size)
spec.loader.exec_module(module)


if __name__ == "__main__":
start()
main()
1 change: 0 additions & 1 deletion instld/cli/parsing_arguments/get_python_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys


Expand Down
6 changes: 2 additions & 4 deletions instld/cli/traceback_cutting/cutting.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import io
import os
import sys
import traceback
from contextlib import redirect_stderr

from instld.cli.traceback_cutting.traceback_utils import cut_base_of_traceback
from instld.cli.traceback_cutting.traceback_utils import cut_base_of_traceback, cut_importlib_bug


def create_cutting_excepthook(old_hook, base_size):
def new_hook(exc_type, value, traceback_object):
traceback_object = cut_base_of_traceback(traceback_object, base_size)
traceback_object = cut_importlib_bug(traceback_object)
traceback.print_exception(exc_type, value, traceback_object)
return new_hook

Expand Down
15 changes: 15 additions & 0 deletions instld/cli/traceback_cutting/traceback_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ def cut_base_of_traceback(traceback_object, base_size):
return traceback_object
index += 1
traceback_object = traceback_object.tb_next


def cut_importlib_bug(traceback_object):
"""
This function fix the truble, that occurs only for windows.
See: https://github.com/pomponchik/instld/actions/runs/6997770395
"""
try:
while traceback_object is not None:
if not (traceback_object.tb_frame.f_code.co_filename == '<frozen importlib._bootstrap>' or traceback_object.tb_frame.f_code.co_filename == '<frozen importlib._bootstrap_external>'):
return traceback_object
traceback_object = traceback_object.tb_next
except AttributeError:
return traceback_object
2 changes: 1 addition & 1 deletion instld/module/command_executer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from threading import Thread, Lock
from subprocess import Popen, PIPE, CalledProcessError
from subprocess import Popen, PIPE

from instld.module.empty_logger import EmptyLogger
from instld.errors import RestartingCommandError, RunningCommandError
Expand Down
4 changes: 1 addition & 3 deletions instld/module/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def new_path(self, module_name):
old_path = sys.path
sys.path = [self.where] + copy.copy(self.original_path)
if module_name in sys.modules:
old_module = sys.modules.pop(module_name)
else:
old_module = None
sys.modules.pop(module_name)
yield
sys.path = old_path

Expand Down
3 changes: 0 additions & 3 deletions instld/module/context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tempfile
from functools import partial

from io import StringIO
from contextlib import contextmanager

from instld.errors import InstallingPackageError, RunningCommandError
Expand Down Expand Up @@ -52,8 +51,6 @@ def create_temp_directory():
new_error = InstallingPackageError(f'{str(e)} It occurred when installing one of the following packages: {", ".join(packages_names)}.')
new_error.stdout = e.stdout
new_error.stderr = e.stderr
#print('STDOUT', e.stdout)
#print('STDERR', e.stderr)
raise new_error from e

yield Context(where, logger, catch_output, options, partial(pip_context, logger=logger, runner=runner, catch_output=catch_output, where=directory))
2 changes: 2 additions & 0 deletions pre-commit_activate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Run it after the first clone of the repo.
pre-commit install
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[build-system]
requires = ['setuptools==68.0.0']
build-backend = 'setuptools.build_meta'

[project]
name = 'instld'
version = '0.0.23'
authors = [
{ name='Evgeniy Blinov', email='zheni-b@yandex.ru' },
]
description = 'The simplest package management'
readme = 'README.md'
requires-python = '>=3.7'
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',
'Programming Language :: Python :: 3.12',
'License :: OSI Approved :: MIT License',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Interpreters',
'Topic :: Utilities',
'Topic :: System :: Archiving :: Packaging',
'Intended Audience :: System Administrators',
'Intended Audience :: Developers',
]

[project.scripts]
instld = 'instld.cli.main:main'

[project.urls]
'Source' = 'https://github.com/pomponchik/instld'
'Tracker' = 'https://github.com/pomponchik/instld/issues'
3 changes: 3 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pytest==7.4.1
coverage==7.2.7
twine==4.0.2
build==0.9.0
wheel==0.40.0
pytest-timeout==2.1.0
contextif==0.0.3
ruff==0.0.290
pre-commit
42 changes: 0 additions & 42 deletions setup.py

This file was deleted.

3 changes: 1 addition & 2 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import shutil

import pytest
from contextif import state


@pytest.mark.timeout(180)
Expand All @@ -14,7 +13,7 @@ def test_cli_where(main_runner):
rf'import is_odd # instld: where {os.path.join("tests", "cli", "data", "pok")}',
rf'import is_even # instld: where {os.path.join("tests", "cli", "data", "chpok")}',
'assert is_odd.valid(23)',
'assert is_even.isEven(1)',
'assert is_even.is_even(2)',
]

script = os.path.join('tests', 'cli', 'data', 'main.py')
Expand Down
17 changes: 14 additions & 3 deletions tests/units/cli/parsing_comments/test_get_options_from_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ def test_get_normal_options():
assert options['cheburek'] == 'mek'


# TODO: fix it!
@pytest.mark.skip("I'll fix it later.")
def test_real_options():
options = get_options_from_comments_by_frame(inspect.currentframe()) # instld: where tests/cli/data/pok, version 1.0.4

assert options == {
'where': 'tests/cli/data/pok',
'version': '1.0.4',
}


def test_get_wrong_options():
with pytest.raises(InstallingPackageError):
options = get_options_from_comments_by_frame(inspect.currentframe()) # instld: lol kek cheburek, cheburek mek
get_options_from_comments_by_frame(inspect.currentframe()) # instld: lol kek cheburek, cheburek mek
with pytest.raises(InstallingPackageError):
options = get_options_from_comments_by_frame(inspect.currentframe()) # instld: lol
get_options_from_comments_by_frame(inspect.currentframe()) # instld: lol
with pytest.raises(InstallingPackageError):
options = get_options_from_comments_by_frame(inspect.currentframe()) # instld:
get_options_from_comments_by_frame(inspect.currentframe()) # instld:


def test_get_empty_options():
Expand Down

0 comments on commit b25aa61

Please sign in to comment.