├── docs ├── source │ ├── _static │ │ ├── .gitkeep │ │ ├── logo_smaller.png │ │ ├── _js │ │ │ └── custom.js │ │ ├── Knowledge_Base_logo.png │ │ └── css │ │ │ └── custom.css │ ├── tvm_tutorials │ │ ├── index.rst │ │ └── creating_two_dev_env.rst │ ├── tvm_how_to_guides │ │ ├── index.rst │ │ └── how_to_configure_vars.rst │ ├── tvm_topic_guides │ │ ├── index.rst │ │ ├── environment_manager.rst │ │ └── version_manager.rst │ ├── tvm_advanced_information.rst │ ├── index.rst │ ├── tvm_quickstart.rst │ └── conf.py ├── images │ ├── tvm_list.png │ ├── tvm_list_project.png │ └── tvm_plugins_list.png ├── make.bat └── Makefile ├── tests ├── version_manager │ ├── __init__.py │ ├── application │ │ ├── __init__.py │ │ ├── test_tutor_version_enabler.py │ │ ├── test_tutor_version_uninstaller.py │ │ ├── test_tutor_version_lister.py │ │ ├── test_tutor_plugin_installer.py │ │ ├── test_tutor_plugin_uninstaller.py │ │ └── test_tutor_version_installer.py │ └── infrastructure │ │ ├── __init__.py │ │ └── version_manager_in_memory_repository.py ├── environment_manager │ ├── __init__.py │ ├── application │ │ ├── __init__.py │ │ ├── test_tutor_project_remover.py │ │ ├── test_plugin_installer.py │ │ ├── test_plugin_uninstaller.py │ │ └── test_tutor_project_creator.py │ └── infrastructure │ │ ├── __init__.py │ │ └── environment_manager_in_memory_repository.py └── test_cli.py ├── tvm ├── share │ ├── __init__.py │ ├── domain │ │ ├── __init__.py │ │ └── client_logger_repository.py │ └── infrastructure │ │ ├── __init__.py │ │ └── click_client_logger_repository.py ├── version_manager │ ├── __init__.py │ ├── domain │ │ ├── __init__.py │ │ ├── tutor_version_format_error.py │ │ ├── tutor_version_is_not_installed.py │ │ ├── tutor_version.py │ │ └── version_manager_repository.py │ ├── templates │ │ ├── __init__.py │ │ └── tutor_switcher.py │ ├── application │ │ ├── __init__.py │ │ ├── tutor_version_enabler.py │ │ ├── tutor_vesion_lister.py │ │ ├── tutor_version_finder.py │ │ ├── tutor_version_installer.py │ │ ├── tutor_version_uninstaller.py │ │ ├── tutor_plugin_installer.py │ │ └── tutor_plugin_uninstaller.py │ └── infrastructure │ │ ├── __init__.py │ │ └── version_manager_git_repository.py ├── environment_manager │ ├── domain │ │ ├── __init__.py │ │ ├── project_name_format_error.py │ │ ├── project_name.py │ │ └── environment_manager_repository.py │ ├── __init__.py │ ├── application │ │ ├── __init__.py │ │ ├── tutor_project_remover.py │ │ ├── plugin_installer.py │ │ ├── plugin_uninstaller.py │ │ └── tutor_project_creator.py │ └── infrastructure │ │ ├── __init__.py │ │ └── environment_manager_git_repository.py ├── templates │ ├── __init__.py │ ├── tutor_switcher.py │ └── tvm_activate.py ├── __init__.py ├── settings.py └── cli.py ├── .github ├── CODEOWNERS ├── workflows │ ├── commitlint.yml │ ├── add_to_apollo_project.yml │ ├── tests.yml │ ├── labeler.yml │ └── bump_version.yml ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── pull_request_template.md ├── .coveragerc ├── requirements ├── pip.in ├── base.in ├── pip-tools.in ├── dev.in ├── pip.txt ├── doc.in ├── constraints.txt ├── pip-tools.txt ├── base.txt ├── doc.txt └── dev.txt ├── commitlint.config.js ├── setup.cfg ├── .readthedocs.yml ├── .gitignore ├── Makefile ├── README.md ├── CONTRIBUTING.md ├── setup.py ├── pylintrc ├── CHANGELOG.md └── LICENSE /docs/source/_static/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/version_manager/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/environment_manager/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tvm/share/__init__.py: -------------------------------------------------------------------------------- 1 | """Share init.""" 2 | -------------------------------------------------------------------------------- /tests/version_manager/application/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/version_manager/infrastructure/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/environment_manager/application/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/environment_manager/infrastructure/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tvm/share/domain/__init__.py: -------------------------------------------------------------------------------- 1 | """Domain module for TVM.""" 2 | -------------------------------------------------------------------------------- /tvm/version_manager/__init__.py: -------------------------------------------------------------------------------- 1 | """Version manager init.""" 2 | -------------------------------------------------------------------------------- /tvm/version_manager/domain/__init__.py: -------------------------------------------------------------------------------- 1 | """Domain init.""" 2 | -------------------------------------------------------------------------------- /tvm/environment_manager/domain/__init__.py: -------------------------------------------------------------------------------- 1 | """Domain init.""" 2 | -------------------------------------------------------------------------------- /tvm/version_manager/templates/__init__.py: -------------------------------------------------------------------------------- 1 | """Template init.""" 2 | -------------------------------------------------------------------------------- /tvm/environment_manager/__init__.py: -------------------------------------------------------------------------------- 1 | """Environment manager init.""" 2 | -------------------------------------------------------------------------------- /tvm/share/infrastructure/__init__.py: -------------------------------------------------------------------------------- 1 | """Infrastructure for TVM.""" 2 | -------------------------------------------------------------------------------- /tvm/version_manager/application/__init__.py: -------------------------------------------------------------------------------- 1 | """Application init.""" 2 | -------------------------------------------------------------------------------- /tvm/environment_manager/application/__init__.py: -------------------------------------------------------------------------------- 1 | """Application init.""" 2 | -------------------------------------------------------------------------------- /tvm/version_manager/infrastructure/__init__.py: -------------------------------------------------------------------------------- 1 | """Infrastructure init.""" 2 | -------------------------------------------------------------------------------- /tvm/environment_manager/infrastructure/__init__.py: -------------------------------------------------------------------------------- 1 | """Infrastructure init.""" 2 | -------------------------------------------------------------------------------- /tvm/templates/__init__.py: -------------------------------------------------------------------------------- 1 | """Package with templates of the stack library.""" 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # The following team is maintainer of this repo 2 | * @eduNEXT/dedalo 3 | -------------------------------------------------------------------------------- /docs/images/tvm_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eduNEXT/tvm/HEAD/docs/images/tvm_list.png -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | branch = True 3 | data_file = .coverage 4 | source=tvm 5 | omit = 6 | tests 7 | -------------------------------------------------------------------------------- /docs/images/tvm_list_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eduNEXT/tvm/HEAD/docs/images/tvm_list_project.png -------------------------------------------------------------------------------- /docs/images/tvm_plugins_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eduNEXT/tvm/HEAD/docs/images/tvm_plugins_list.png -------------------------------------------------------------------------------- /requirements/pip.in: -------------------------------------------------------------------------------- 1 | # Core dependencies for installing other packages 2 | 3 | pip 4 | setuptools 5 | wheel 6 | -------------------------------------------------------------------------------- /docs/source/_static/logo_smaller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eduNEXT/tvm/HEAD/docs/source/_static/logo_smaller.png -------------------------------------------------------------------------------- /docs/source/tvm_tutorials/index.rst: -------------------------------------------------------------------------------- 1 | Tutorials 2 | ########## 3 | 4 | .. toctree:: 5 | 6 | creating_two_dev_env 7 | -------------------------------------------------------------------------------- /docs/source/_static/_js/custom.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function () { 2 | $('a.external').attr('target', '_blank'); 3 | }); 4 | -------------------------------------------------------------------------------- /docs/source/tvm_how_to_guides/index.rst: -------------------------------------------------------------------------------- 1 | How-to Guides 2 | -------------- 3 | .. toctree:: 4 | 5 | how_to_configure_vars 6 | -------------------------------------------------------------------------------- /docs/source/_static/Knowledge_Base_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eduNEXT/tvm/HEAD/docs/source/_static/Knowledge_Base_logo.png -------------------------------------------------------------------------------- /tvm/__init__.py: -------------------------------------------------------------------------------- 1 | """Helps you keep your cool when creating dozens of open edX and eduNEXT environments.""" 2 | 3 | __version__ = '2.3.1' 4 | -------------------------------------------------------------------------------- /docs/source/tvm_topic_guides/index.rst: -------------------------------------------------------------------------------- 1 | Topic Guides 2 | ############# 3 | 4 | .. toctree:: 5 | 6 | environment_manager 7 | version_manager 8 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/no-extraneous-dependencies */ 2 | 3 | module.exports = { 4 | extends: ['@commitlint/config-conventional'], 5 | } 6 | -------------------------------------------------------------------------------- /tvm/environment_manager/domain/project_name_format_error.py: -------------------------------------------------------------------------------- 1 | """Project name format error.""" 2 | 3 | 4 | class ProjectNameFormatError(Exception): 5 | """Project name format error exception.""" 6 | -------------------------------------------------------------------------------- /requirements/base.in: -------------------------------------------------------------------------------- 1 | # Core requirements for using this application 2 | -c constraints.txt 3 | 4 | Click>=8.0.1 5 | requests 6 | jinja2 7 | pyyaml 8 | GitPython 9 | virtualenv 10 | packaging 11 | -------------------------------------------------------------------------------- /tvm/version_manager/domain/tutor_version_format_error.py: -------------------------------------------------------------------------------- 1 | """Tutor version format error message.""" 2 | 3 | 4 | class TutorVersionFormatError(Exception): 5 | """Tutor version format error exception.""" 6 | -------------------------------------------------------------------------------- /tvm/version_manager/domain/tutor_version_is_not_installed.py: -------------------------------------------------------------------------------- 1 | """Tutor vesion is not installed.""" 2 | 3 | 4 | class TutorVersionIsNotInstalled(Exception): 5 | """Tutor vesion is not installed domain.""" 6 | -------------------------------------------------------------------------------- /requirements/pip-tools.in: -------------------------------------------------------------------------------- 1 | # Just the dependencies to run pip-tools, mainly for the "upgrade" make target 2 | -c constraints.txt 3 | 4 | pip-tools # Contains pip-compile, used to generate pip requirements files 5 | -------------------------------------------------------------------------------- /requirements/dev.in: -------------------------------------------------------------------------------- 1 | # Additional requirements for development of this application 2 | -c constraints.txt 3 | 4 | -r base.txt 5 | 6 | pylint 7 | pycodestyle 8 | pydocstyle 9 | coverage 10 | pytest 11 | pudb 12 | requests 13 | -------------------------------------------------------------------------------- /.github/workflows/commitlint.yml: -------------------------------------------------------------------------------- 1 | name: Lint Commit Messages 2 | on: [pull_request] 3 | 4 | jobs: 5 | commitlint: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | with: 10 | fetch-depth: 0 11 | - uses: wagoid/commitlint-github-action@v4.1.12 12 | -------------------------------------------------------------------------------- /tvm/share/domain/client_logger_repository.py: -------------------------------------------------------------------------------- 1 | """Domain clien logger repository.""" 2 | import abc 3 | from abc import abstractmethod 4 | 5 | 6 | class ClientLoggerRepository(abc.ABC): 7 | """Clien logger.""" 8 | 9 | @abstractmethod 10 | def echo(self, message) -> None: 11 | """Echo a message.""" 12 | -------------------------------------------------------------------------------- /requirements/pip.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with Python 3.10 3 | # by the following command: 4 | # 5 | # make upgrade 6 | # 7 | wheel==0.43.0 8 | # via -r requirements/pip.in 9 | 10 | # The following packages are considered to be unsafe in a requirements file: 11 | pip==24.0 12 | # via -r requirements/pip.in 13 | setuptools==69.5.1 14 | # via -r requirements/pip.in 15 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 2.3.1 3 | commit = False 4 | tag = False 5 | 6 | [bumpversion:file:tvm/__init__.py] 7 | 8 | [isort] 9 | include_trailing_comma = True 10 | indent = ' ' 11 | line_length = 120 12 | multi_line_output = 3 13 | 14 | [bdist_wheel] 15 | universal = 1 16 | 17 | [pycodestyle] 18 | ignore = E501, E722 19 | exclude = .git,.tvm 20 | 21 | [tool:pytest] 22 | norecursedirs = strains .tvm 23 | -------------------------------------------------------------------------------- /docs/source/tvm_advanced_information.rst: -------------------------------------------------------------------------------- 1 | Advanced Information 2 | ##################### 3 | 4 | TVM is the acronym for: 5 | 6 | - Tutor Version Manager: handles the version of Tutor. 7 | - Tutor enVironment Manager: creates project-based environments with Tutor. 8 | 9 | To develop this tool, we separate the code into two apps accord the two meanings of TVM, and we use a `Hexagonal Architecture `_. 10 | -------------------------------------------------------------------------------- /tvm/share/infrastructure/click_client_logger_repository.py: -------------------------------------------------------------------------------- 1 | """Infrastructure click clien logger repository.""" 2 | import click 3 | 4 | from tvm.share.domain.client_logger_repository import ClientLoggerRepository 5 | 6 | 7 | class ClickClientLoggerRepository(ClientLoggerRepository): 8 | """click clien logger repository.""" 9 | 10 | def echo(self, message) -> None: 11 | """Echo message.""" 12 | click.echo(click.style(message, fg="yellow")) 13 | -------------------------------------------------------------------------------- /requirements/doc.in: -------------------------------------------------------------------------------- 1 | sphinx==4.2.0 2 | sphinx-book-theme==0.3.3 3 | recommonmark==0.6.0 4 | sphinxcontrib.images==0.9.4 5 | sphinx_panels==0.6.0 6 | sphinxcontrib.contentui==0.2.5 7 | sphinx_copybutton==0.5.0 8 | sphinxcontrib.mermaid==0.7.1 9 | sphinxcontrib-applehelp==1.0.4 10 | sphinxcontrib-devhelp==1.0.2 11 | sphinxcontrib-htmlhelp==2.0.1 12 | sphinxcontrib-qthelp==1.0.3 13 | sphinxcontrib-serializinghtml==1.1.5 14 | sphinxcontrib-jsmath==1.0.1 15 | sphinxcontrib-youtube==1.3.0 16 | -------------------------------------------------------------------------------- /tvm/templates/tutor_switcher.py: -------------------------------------------------------------------------------- 1 | """Tutor switcher jinja template.""" 2 | from jinja2 import Template 3 | 4 | TEMPLATE = ''' 5 | {% if tutor_root %} 6 | export TUTOR_ROOT={{ tutor_root }} 7 | export TUTOR_PLUGINS_ROOT={{ tutor_plugins_root }} 8 | {% endif %} 9 | {% if version %} 10 | {{ tvm }}/{{ version }}/venv/bin/tutor $@ 11 | {% else %} 12 | echo "You need to select a tutor active version at first. Run 'tvm use '" 13 | {% endif %} 14 | ''' 15 | 16 | TUTOR_SWITCHER_TEMPLATE = Template(TEMPLATE) 17 | -------------------------------------------------------------------------------- /requirements/constraints.txt: -------------------------------------------------------------------------------- 1 | # Version constraints for pip-installation. 2 | # 3 | # This file doesn't install any packages. It specifies version constraints 4 | # that will be applied if a package is needed. 5 | # 6 | # When pinning something here, please provide an explanation of why. Ideally, 7 | # link to other information that will help people in the future to remove the 8 | # pin when possible. Writing an issue against the offending project and 9 | # linking to it here is good. 10 | 11 | pylint<2.15.0 12 | -------------------------------------------------------------------------------- /tvm/version_manager/templates/tutor_switcher.py: -------------------------------------------------------------------------------- 1 | """Tutor switcher jinja template.""" 2 | from jinja2 import Template 3 | 4 | TEMPLATE = ''' 5 | {% if tutor_root %} 6 | export TUTOR_ROOT={{ tutor_root }} 7 | export TUTOR_PLUGINS_ROOT={{ tutor_plugins_root }} 8 | {% endif %} 9 | {% if version %} 10 | {{ tvm }}/{{ version }}/venv/bin/tutor $@ 11 | {% else %} 12 | echo "You need to select a tutor active version at first. Run 'tvm use '" 13 | {% endif %} 14 | ''' 15 | 16 | TUTOR_SWITCHER_TEMPLATE = Template(TEMPLATE) 17 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Set the version of Python and other tools you might need 6 | version: 2 7 | build: 8 | os: ubuntu-22.04 9 | tools: 10 | python: "3.11" 11 | 12 | # Build documentation in the docs/ directory with Sphinx 13 | sphinx: 14 | configuration: docs/source/conf.py 15 | fail_on_warning: true 16 | 17 | python: 18 | install: 19 | - requirements: requirements/doc.txt 20 | -------------------------------------------------------------------------------- /.github/workflows/add_to_apollo_project.yml: -------------------------------------------------------------------------------- 1 | name: Add issues and PRs to the Apollo project 2 | 3 | on: 4 | issues: 5 | types: [opened] 6 | pull_request: 7 | types: [opened] 8 | 9 | jobs: 10 | add-to-project: 11 | name: Add to Apollo project 12 | uses: openedx/.github/.github/workflows/add-issue-to-a-project.yml@master 13 | secrets: 14 | GITHUB_APP_ID: ${{ vars.APOLLO_APP_ID }} 15 | GITHUB_APP_PRIVATE_KEY: ${{ secrets.APOLLO_APP_SECRET }} 16 | with: 17 | ORGANIZATION: eduNEXT 18 | PROJECT_NUMBER: 1 19 | -------------------------------------------------------------------------------- /tvm/environment_manager/application/tutor_project_remover.py: -------------------------------------------------------------------------------- 1 | """Tutor project initialize.""" 2 | from tvm.environment_manager.domain.environment_manager_repository import EnvironmentManagerRepository 3 | 4 | 5 | class TutorProjectRemover: 6 | """Tutor project initialize for environment manager.""" 7 | 8 | def __init__(self, repository: EnvironmentManagerRepository) -> None: 9 | """init.""" 10 | self.repository = repository 11 | 12 | def __call__(self, prune: bool) -> None: 13 | """call.""" 14 | self.repository.project_remover(prune=prune) 15 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Unit tests, QA 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up Python 3.8 17 | uses: actions/setup-python@v2 18 | with: 19 | python-version: 3.8 20 | - name: Install dependencies 21 | run: | 22 | make requirements 23 | - name: Run the QA suite 24 | run: | 25 | make quality 26 | - name: Unit tests 27 | run: | 28 | make test 29 | -------------------------------------------------------------------------------- /tvm/environment_manager/application/plugin_installer.py: -------------------------------------------------------------------------------- 1 | """Tutor plugin installer application.""" 2 | from typing import List 3 | 4 | from tvm.environment_manager.domain.environment_manager_repository import EnvironmentManagerRepository 5 | 6 | 7 | class PluginInstaller: 8 | """Tutor plugin installer for environment manager.""" 9 | 10 | def __init__(self, repository: EnvironmentManagerRepository) -> None: 11 | """init.""" 12 | self.repository = repository 13 | 14 | def __call__(self, options: List) -> None: 15 | """call.""" 16 | self.repository.install_plugin(options=options) 17 | -------------------------------------------------------------------------------- /tvm/environment_manager/application/plugin_uninstaller.py: -------------------------------------------------------------------------------- 1 | """Tutor plugin uninstaller application.""" 2 | from typing import List 3 | 4 | from tvm.environment_manager.domain.environment_manager_repository import EnvironmentManagerRepository 5 | 6 | 7 | class PluginUninstaller: 8 | """Tutor plugin uninstaller for environment manager.""" 9 | 10 | def __init__(self, repository: EnvironmentManagerRepository) -> None: 11 | """init.""" 12 | self.repository = repository 13 | 14 | def __call__(self, options: List) -> None: 15 | """call.""" 16 | self.repository.uninstall_plugin(options=options) 17 | -------------------------------------------------------------------------------- /tests/version_manager/application/test_tutor_version_enabler.py: -------------------------------------------------------------------------------- 1 | from tests.version_manager.infrastructure.version_manager_in_memory_repository import ( 2 | VersionManagerInMemoryRepository, 3 | ) 4 | from tvm.version_manager.application.tutor_version_enabler import TutorVersionEnabler 5 | 6 | 7 | def test_should_enabler_the_tutor_version(): 8 | # Given 9 | version = "v1.2.3" 10 | repository = VersionManagerInMemoryRepository() 11 | 12 | # When 13 | enabler = TutorVersionEnabler(repository=repository) 14 | enabler(version=version) 15 | 16 | # Then 17 | assert version in repository.VERSIONS_INSTALLED 18 | -------------------------------------------------------------------------------- /tests/environment_manager/application/test_tutor_project_remover.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tests.environment_manager.infrastructure.environment_manager_in_memory_repository import ( 4 | EnvironmentManagerInMemoryRepository, 5 | ) 6 | from tvm.environment_manager.application.tutor_project_remover import ( 7 | TutorProjectRemover, 8 | ) 9 | 10 | 11 | def test_should_remove_tutor_project(): 12 | # Given 13 | repository = EnvironmentManagerInMemoryRepository() 14 | 15 | # When 16 | remove = TutorProjectRemover(repository=repository) 17 | remove(prune=False) 18 | 19 | # Then 20 | assert repository.PROJECT_NAME == [] 21 | -------------------------------------------------------------------------------- /tvm/environment_manager/domain/project_name.py: -------------------------------------------------------------------------------- 1 | """Project name domain.""" 2 | import re 3 | 4 | from tvm.environment_manager.domain.project_name_format_error import ProjectNameFormatError 5 | 6 | 7 | class ProjectName(str): 8 | """Project name fotmat.""" 9 | 10 | def __init__(self, value: str): # pylint: disable=super-init-not-called 11 | """Raise BadParameter if the value is not a project name.""" 12 | self._value = value 13 | 14 | result = re.match(r"^v([0-9]+)\.([0-9]+)\.([0-9]+)\@[a-zA-Z0-9_-]+$", value) 15 | if not result: 16 | raise ProjectNameFormatError("format must be 'vX.Y.Z@project_name'") 17 | -------------------------------------------------------------------------------- /requirements/pip-tools.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with Python 3.10 3 | # by the following command: 4 | # 5 | # make upgrade 6 | # 7 | build==1.2.1 8 | # via pip-tools 9 | click==8.1.7 10 | # via pip-tools 11 | packaging==24.0 12 | # via build 13 | pip-tools==7.4.1 14 | # via -r requirements/pip-tools.in 15 | pyproject-hooks==1.1.0 16 | # via 17 | # build 18 | # pip-tools 19 | tomli==2.0.1 20 | # via 21 | # build 22 | # pip-tools 23 | wheel==0.43.0 24 | # via pip-tools 25 | 26 | # The following packages are considered to be unsafe in a requirements file: 27 | # pip 28 | # setuptools 29 | -------------------------------------------------------------------------------- /tvm/version_manager/application/tutor_version_enabler.py: -------------------------------------------------------------------------------- 1 | """Tutor version enabler application.""" 2 | from tvm.version_manager.domain.tutor_version import TutorVersion 3 | from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository 4 | 5 | 6 | class TutorVersionEnabler: 7 | """Tutor version enabler for version manager.""" 8 | 9 | def __init__(self, repository: VersionManagerRepository) -> None: 10 | """init.""" 11 | self.repository = repository 12 | 13 | def __call__(self, version: str) -> None: 14 | """call.""" 15 | version = TutorVersion(version) 16 | self.repository.use_version(version) 17 | -------------------------------------------------------------------------------- /tvm/version_manager/application/tutor_vesion_lister.py: -------------------------------------------------------------------------------- 1 | """Tutor version application.""" 2 | from typing import List 3 | 4 | from tvm.version_manager.domain.tutor_version import TutorVersion 5 | from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository 6 | 7 | 8 | class TutorVersionLister: 9 | """Tutor version lister for version manage.""" 10 | 11 | def __init__(self, repository: VersionManagerRepository) -> None: 12 | """init.""" 13 | self.repository = repository 14 | 15 | def __call__(self, limit: int) -> List[TutorVersion]: 16 | """call.""" 17 | return self.repository.list_versions(limit=limit) 18 | -------------------------------------------------------------------------------- /tests/version_manager/application/test_tutor_version_uninstaller.py: -------------------------------------------------------------------------------- 1 | from tests.version_manager.infrastructure.version_manager_in_memory_repository import ( 2 | VersionManagerInMemoryRepository, 3 | ) 4 | from tvm.version_manager.application.tutor_version_uninstaller import ( 5 | TutorVersionUninstaller, 6 | ) 7 | 8 | 9 | def test_should_uninstall_the_tutor_version(): 10 | # Given 11 | version = "v1.2.4" 12 | repository = VersionManagerInMemoryRepository() 13 | 14 | # When 15 | uninstaller = TutorVersionUninstaller(repository=repository) 16 | uninstaller(version=version) 17 | 18 | # Then 19 | assert version not in repository.VERSIONS_INSTALLED 20 | -------------------------------------------------------------------------------- /tvm/version_manager/application/tutor_version_finder.py: -------------------------------------------------------------------------------- 1 | """Tutor version finder application.""" 2 | from tvm.version_manager.domain.tutor_version import TutorVersion 3 | from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository 4 | 5 | 6 | class TutorVersionFinder: 7 | """Tutor version finder for version manager.""" 8 | 9 | def __init__(self, repository: VersionManagerRepository): 10 | """init.""" 11 | self.repository = repository 12 | 13 | def __call__(self, version: str) -> TutorVersion: 14 | """call.""" 15 | version = TutorVersion(version) 16 | return self.repository.find_version(version=version) 17 | -------------------------------------------------------------------------------- /tvm/version_manager/domain/tutor_version.py: -------------------------------------------------------------------------------- 1 | """Tutor version domain.""" 2 | import re 3 | 4 | from tvm.version_manager.domain.tutor_version_format_error import TutorVersionFormatError 5 | 6 | 7 | class TutorVersion(str): 8 | """Tutor version format.""" 9 | 10 | def __init__(self, value: str, file_url: str = None): # pylint: disable=super-init-not-called 11 | """Raise BadParameter if the value is not a tutor version.""" 12 | self._value = value 13 | self._file_url = file_url 14 | 15 | result = re.match(r"^v([0-9]+)\.([0-9]+)\.([0-9]+)$", value) 16 | if not result: 17 | raise TutorVersionFormatError("format must be 'vX.Y.Z'") 18 | -------------------------------------------------------------------------------- /tvm/version_manager/application/tutor_version_installer.py: -------------------------------------------------------------------------------- 1 | """Tutor version installer application.""" 2 | from tvm.version_manager.domain.tutor_version import TutorVersion 3 | from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository 4 | 5 | 6 | class TutorVersionInstaller: 7 | """Tutor version installer for version manager.""" 8 | 9 | def __init__(self, repository: VersionManagerRepository) -> None: 10 | """init.""" 11 | self.repository = repository 12 | 13 | def __call__(self, version: str) -> None: 14 | """call.""" 15 | version = TutorVersion(version) 16 | self.repository.install_version(version=version) 17 | -------------------------------------------------------------------------------- /tests/version_manager/application/test_tutor_version_lister.py: -------------------------------------------------------------------------------- 1 | from tests.version_manager.infrastructure.version_manager_in_memory_repository import ( 2 | VersionManagerInMemoryRepository, 3 | ) 4 | from tvm.version_manager.application.tutor_vesion_lister import TutorVersionLister 5 | 6 | 7 | def test_should_list_tutor_versions(): 8 | # Given 9 | limit = 10 10 | list_versions = [] 11 | for version in range(limit): 12 | list_versions.append(f"v1.2.{version}") 13 | repository = VersionManagerInMemoryRepository() 14 | 15 | # When 16 | lister = TutorVersionLister(repository=repository) 17 | 18 | # Then 19 | assert list_versions == lister(limit=limit) 20 | -------------------------------------------------------------------------------- /tvm/version_manager/application/tutor_version_uninstaller.py: -------------------------------------------------------------------------------- 1 | """Tutor version uninstaller application.""" 2 | from tvm.version_manager.domain.tutor_version import TutorVersion 3 | from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository 4 | 5 | 6 | class TutorVersionUninstaller: 7 | """Tutor version uninstaller for version manager.""" 8 | 9 | def __init__(self, repository: VersionManagerRepository) -> None: 10 | """init.""" 11 | self.repository = repository 12 | 13 | def __call__(self, version: str) -> None: 14 | """call.""" 15 | version = TutorVersion(version) 16 | self.repository.uninstall_version(version) 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEAT]" 5 | labels: enhancement 6 | 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 11 | 12 | **Describe the solution you'd like** 13 | A clear and concise description of what you want to happen. 14 | 15 | **Describe alternatives you've considered** 16 | A clear and concise description of any alternative solutions or features you've considered. 17 | 18 | **Additional context** 19 | Add any other context or screenshots about the feature request here. 20 | -------------------------------------------------------------------------------- /tvm/environment_manager/application/tutor_project_creator.py: -------------------------------------------------------------------------------- 1 | """Tutor project initialize.""" 2 | from tvm.environment_manager.domain.environment_manager_repository import EnvironmentManagerRepository 3 | from tvm.environment_manager.domain.project_name import ProjectName 4 | 5 | 6 | class TutorProjectCreator: 7 | """Tutor project initialize for environment manager.""" 8 | 9 | def __init__(self, repository: EnvironmentManagerRepository) -> None: 10 | """init.""" 11 | self.repository = repository 12 | 13 | def __call__(self, version: str) -> None: 14 | """call.""" 15 | project_name = ProjectName(version) 16 | self.repository.project_creator(project_name) 17 | -------------------------------------------------------------------------------- /tvm/settings.py: -------------------------------------------------------------------------------- 1 | """Settings file for tutor.""" 2 | from tvm.environment_manager.infrastructure.environment_manager_git_repository import EnvironmentManagerGitRepository 3 | from tvm.share.infrastructure.click_client_logger_repository import ClickClientLoggerRepository 4 | from tvm.version_manager.infrastructure.version_manager_git_repository import VersionManagerGitRepository 5 | 6 | logger = ClickClientLoggerRepository() 7 | version_manager = VersionManagerGitRepository(logger=logger) 8 | 9 | 10 | def environment_manager(project_path: str) -> EnvironmentManagerGitRepository: 11 | """Environment manager repository.""" 12 | return EnvironmentManagerGitRepository(project_path=project_path, logger=logger) 13 | -------------------------------------------------------------------------------- /tvm/version_manager/application/tutor_plugin_installer.py: -------------------------------------------------------------------------------- 1 | """Tutor plugin installer application.""" 2 | from typing import List 3 | 4 | from tvm.version_manager.domain.tutor_version import TutorVersion 5 | from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository 6 | 7 | 8 | class TutorPluginInstaller: 9 | """Tutor plugin installer for version manager.""" 10 | 11 | def __init__(self, repository: VersionManagerRepository) -> None: 12 | """init.""" 13 | self.repository = repository 14 | 15 | def __call__(self, options: List, version: TutorVersion = None) -> None: 16 | """call.""" 17 | if version: 18 | version = TutorVersion(value=version) 19 | self.repository.install_plugin(options=options, version=version) 20 | -------------------------------------------------------------------------------- /tvm/version_manager/application/tutor_plugin_uninstaller.py: -------------------------------------------------------------------------------- 1 | """Tutor plugin uninstaller application.""" 2 | from typing import List 3 | 4 | from tvm.version_manager.domain.tutor_version import TutorVersion 5 | from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository 6 | 7 | 8 | class TutorPluginUninstaller: 9 | """Tutor plugin uninstaller for version manager.""" 10 | 11 | def __init__(self, repository: VersionManagerRepository) -> None: 12 | """init.""" 13 | self.repository = repository 14 | 15 | def __call__(self, options: List, version: str = None) -> None: 16 | """call.""" 17 | if version: 18 | version = TutorVersion(value=version) 19 | self.repository.uninstall_plugin(options=options, version=version) 20 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: labeler 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - 'main' 7 | 8 | jobs: 9 | labeler: 10 | runs-on: ubuntu-latest 11 | name: Label the PR size 12 | steps: 13 | - uses: CodelyTV/pr-size-labeler@v1.7.0 14 | with: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | xs_max_size: '10' 17 | s_max_size: '100' 18 | m_max_size: '500' 19 | l_max_size: '1000' 20 | fail_if_xl: 'true' 21 | message_if_xl: > 22 | 'This PR exceeds the recommended size of 1000 lines. 23 | Please make sure you are NOT addressing multiple issues with one PR. 24 | Note this PR might be rejected due to its size.' 25 | github_api_url: 'api.github.com' 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug, help wanted 6 | 7 | --- 8 | 9 | **Describe the bug** 10 | A clear and concise description of what the bug is. 11 | 12 | **To Reproduce** 13 | Steps to reproduce the behavior: 14 | 1. Go to '...' 15 | 2. Click on '....' 16 | 3. Scroll down to '....' 17 | 4. See error 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | 25 | **Desktop (please complete the following information):** 26 | - OS: [e.g. Ubuntu] 27 | - Version [e.g. 22.04] 28 | - TVM Version: [e.g. v0.1.0] 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | install_requirements: ## install the requirements to start working on documentation 12 | pip install -r requirements/doc.txt 13 | 14 | serve_docs: ## serve the built docs locally to preview the site in the browser 15 | python -m http.server 8200 --directory build/html 16 | 17 | # Put it first so that "make" without argument is like "make help". 18 | help: 19 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 20 | 21 | .PHONY: help Makefile 22 | 23 | # Catch-all target: route all unknown targets to Sphinx using the new 24 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 25 | %: Makefile 26 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 27 | -------------------------------------------------------------------------------- /requirements/base.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with Python 3.10 3 | # by the following command: 4 | # 5 | # make upgrade 6 | # 7 | certifi==2024.2.2 8 | # via requests 9 | charset-normalizer==3.3.2 10 | # via requests 11 | click==8.1.7 12 | # via -r requirements/base.in 13 | distlib==0.3.8 14 | # via virtualenv 15 | filelock==3.14.0 16 | # via virtualenv 17 | gitdb==4.0.11 18 | # via gitpython 19 | gitpython==3.1.43 20 | # via -r requirements/base.in 21 | idna==3.7 22 | # via requests 23 | jinja2==3.1.3 24 | # via -r requirements/base.in 25 | markupsafe==2.1.5 26 | # via jinja2 27 | packaging==24.0 28 | # via -r requirements/base.in 29 | platformdirs==4.2.1 30 | # via virtualenv 31 | pyyaml==6.0.1 32 | # via -r requirements/base.in 33 | requests==2.31.0 34 | # via -r requirements/base.in 35 | smmap==5.0.1 36 | # via gitdb 37 | urllib3==2.2.1 38 | # via requests 39 | virtualenv==20.26.1 40 | # via -r requirements/base.in 41 | -------------------------------------------------------------------------------- /tests/version_manager/application/test_tutor_plugin_installer.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tests.version_manager.infrastructure.version_manager_in_memory_repository import ( 4 | VersionManagerInMemoryRepository, 5 | ) 6 | from tvm.version_manager.application.tutor_plugin_installer import TutorPluginInstaller 7 | 8 | 9 | def test_should_install_the_tutor_plugin(): 10 | # Given 11 | options = ["tutor-mfe"] 12 | repository = VersionManagerInMemoryRepository() 13 | 14 | # When 15 | installer = TutorPluginInstaller(repository=repository) 16 | installer(options) 17 | 18 | # Then 19 | assert options in repository.PLUGINS_INSTALLED 20 | 21 | 22 | def test_should_fail_if_not_add_tutor_plugin(): 23 | # Given 24 | options = [] 25 | repository = VersionManagerInMemoryRepository() 26 | 27 | # When 28 | installer = TutorPluginInstaller(repository=repository) 29 | 30 | # Then 31 | with pytest.raises(Exception) as format_err: 32 | installer(options) 33 | -------------------------------------------------------------------------------- /tests/environment_manager/application/test_plugin_installer.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tests.environment_manager.infrastructure.environment_manager_in_memory_repository import ( 4 | EnvironmentManagerInMemoryRepository, 5 | ) 6 | from tvm.environment_manager.application.plugin_installer import PluginInstaller 7 | 8 | 9 | def test_should_install_the_tutor_plugin(): 10 | # Given 11 | options = ["tutor-mfe"] 12 | repository = EnvironmentManagerInMemoryRepository() 13 | 14 | # When 15 | installer = PluginInstaller(repository=repository) 16 | installer(options) 17 | 18 | # Then 19 | assert options in repository.PLUGINS_INSTALLED 20 | 21 | 22 | def test_should_fail_if_not_add_tutor_plugin(): 23 | # Given 24 | options = [] 25 | repository = EnvironmentManagerInMemoryRepository() 26 | 27 | # When 28 | installer = PluginInstaller(repository=repository) 29 | 30 | # Then 31 | with pytest.raises(Exception) as format_err: 32 | installer(options) 33 | -------------------------------------------------------------------------------- /tests/environment_manager/application/test_plugin_uninstaller.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tests.environment_manager.infrastructure.environment_manager_in_memory_repository import ( 4 | EnvironmentManagerInMemoryRepository, 5 | ) 6 | from tvm.environment_manager.application.plugin_uninstaller import ( 7 | PluginUninstaller, 8 | ) 9 | 10 | 11 | def test_should_uninstall_the_tutor_plugin(): 12 | # Given 13 | options = "codejail" 14 | repository = EnvironmentManagerInMemoryRepository() 15 | 16 | # When 17 | uninstaller = PluginUninstaller(repository=repository) 18 | uninstaller(options) 19 | 20 | # Then 21 | assert options not in repository.PLUGINS_INSTALLED 22 | 23 | 24 | def test_should_fail_if_not_add_tutor_plugin(): 25 | # Given 26 | options = "tutor-mfe" 27 | repository = EnvironmentManagerInMemoryRepository() 28 | 29 | # When 30 | uninstaller = PluginUninstaller(repository=repository) 31 | 32 | # Then 33 | with pytest.raises(Exception) as format_err: 34 | uninstaller(options) 35 | -------------------------------------------------------------------------------- /tests/version_manager/application/test_tutor_plugin_uninstaller.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tests.version_manager.infrastructure.version_manager_in_memory_repository import ( 4 | VersionManagerInMemoryRepository, 5 | ) 6 | from tvm.version_manager.application.tutor_plugin_uninstaller import ( 7 | TutorPluginUninstaller, 8 | ) 9 | 10 | 11 | def test_should_uninstall_the_tutor_plugin(): 12 | # Given 13 | options = "codejail" 14 | repository = VersionManagerInMemoryRepository() 15 | 16 | # When 17 | uninstaller = TutorPluginUninstaller(repository=repository) 18 | uninstaller(options) 19 | 20 | # Then 21 | assert options not in repository.VERSIONS_INSTALLED 22 | 23 | 24 | def test_should_fail_if_not_add_tutor_plugin(): 25 | # Given 26 | options = "tutor-mfe" 27 | repository = VersionManagerInMemoryRepository() 28 | 29 | # When 30 | uninstaller = TutorPluginUninstaller(repository=repository) 31 | 32 | # Then 33 | with pytest.raises(Exception) as format_err: 34 | uninstaller(options) 35 | -------------------------------------------------------------------------------- /tvm/environment_manager/domain/environment_manager_repository.py: -------------------------------------------------------------------------------- 1 | """Environment manager repository methods.""" 2 | from abc import ABC, abstractmethod 3 | from typing import List 4 | 5 | from tvm.environment_manager.domain.project_name import ProjectName 6 | 7 | 8 | class EnvironmentManagerRepository(ABC): 9 | """Administrate environment manager repository methods.""" 10 | 11 | @abstractmethod 12 | def project_creator(self, project_name: ProjectName) -> None: 13 | """Tutor Project Init to environment manager.""" 14 | 15 | @abstractmethod 16 | def project_remover(self, prune: bool) -> None: 17 | """Tutor Project Remove to environment manager.""" 18 | 19 | @abstractmethod 20 | def current_version(self) -> None: 21 | """Get the project's version.""" 22 | 23 | @abstractmethod 24 | def install_plugin(self, options: List) -> None: 25 | """Install a pip package.""" 26 | 27 | @abstractmethod 28 | def uninstall_plugin(self, options: List) -> None: 29 | """Uninstall a pip package.""" 30 | -------------------------------------------------------------------------------- /tests/environment_manager/application/test_tutor_project_creator.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tests.environment_manager.infrastructure.environment_manager_in_memory_repository import ( 4 | EnvironmentManagerInMemoryRepository, 5 | ) 6 | from tvm.environment_manager.application.tutor_project_creator import ( 7 | TutorProjectCreator, 8 | ) 9 | 10 | 11 | def test_should_create_tutor_project(): 12 | # Given 13 | project_name = "v13.1.0@testtutor" 14 | repository = EnvironmentManagerInMemoryRepository() 15 | 16 | # When 17 | inicialize = TutorProjectCreator(repository=repository) 18 | inicialize(project_name) 19 | 20 | # Then 21 | assert project_name in repository.PROJECT_NAME 22 | 23 | 24 | def test_should_fail_if_project_name_exists(): 25 | # Given 26 | project_name = "v13.1.0@tutortest" 27 | repository = EnvironmentManagerInMemoryRepository() 28 | 29 | # When 30 | inicialize = TutorProjectCreator(repository=repository) 31 | 32 | # Then 33 | with pytest.raises(Exception) as format_err: 34 | inicialize(project_name) 35 | -------------------------------------------------------------------------------- /tests/version_manager/application/test_tutor_version_installer.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tests.version_manager.infrastructure.version_manager_in_memory_repository import ( 4 | VersionManagerInMemoryRepository, 5 | ) 6 | from tvm.version_manager.application.tutor_version_installer import ( 7 | TutorVersionInstaller, 8 | ) 9 | from tvm.version_manager.domain.tutor_version_format_error import ( 10 | TutorVersionFormatError, 11 | ) 12 | 13 | 14 | def test_should_fail_if_version_format_is_not_valid(): 15 | # Given 16 | version = "v123" 17 | repository = VersionManagerInMemoryRepository() 18 | 19 | # When 20 | installer = TutorVersionInstaller(repository=repository) 21 | 22 | # Then 23 | with pytest.raises(TutorVersionFormatError) as format_err: 24 | installer(version=version) 25 | 26 | 27 | def test_should_install_the_tutor_version(): 28 | # Given 29 | version = "v1.2.3" 30 | repository = VersionManagerInMemoryRepository() 31 | 32 | # When 33 | installer = TutorVersionInstaller(repository=repository) 34 | installer(version=version) 35 | 36 | # Then 37 | assert version in repository.VERSIONS_INSTALLED 38 | -------------------------------------------------------------------------------- /tests/test_cli.py: -------------------------------------------------------------------------------- 1 | """Package for tests of the tutor version manager.""" 2 | import pytest 3 | from click.exceptions import BadParameter 4 | from click.testing import CliRunner 5 | 6 | from tvm.cli import cli, install, validate_version, projects 7 | 8 | 9 | def test_should_return_all_tvm_cli_commands(): 10 | runner = CliRunner() 11 | result = runner.invoke(cli) 12 | 13 | assert result.exit_code == 0 14 | assert ' install ' in result.output 15 | assert ' uninstall ' in result.output 16 | assert ' list ' in result.output 17 | assert ' use ' in result.output 18 | assert ' plugins ' in result.output 19 | 20 | 21 | def test_should_fail_if_format_version_is_not_valid(): 22 | with pytest.raises(BadParameter): 23 | validate_version(None, None, 'v12.0.') 24 | 25 | 26 | def test_should_fail_if_version_does_not_exist(): 27 | runner = CliRunner() 28 | result = runner.invoke(install, ["v0.0.99"]) 29 | assert 'Could not find target: v0.0.99' in result.stdout 30 | 31 | 32 | def test_should_return_all_tvm_project_commands(): 33 | runner = CliRunner() 34 | result = runner.invoke(projects) 35 | 36 | assert result.exit_code == 0 37 | assert ' init ' in result.output 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | __pycache__ 3 | 4 | # C extensions 5 | *.so 6 | 7 | # Packages 8 | *.egg 9 | *.egg-info 10 | dist 11 | build 12 | eggs 13 | parts 14 | bin 15 | var 16 | sdist 17 | develop-eggs 18 | .installed.cfg 19 | lib 20 | lib64 21 | 22 | # Installer logs 23 | pip-log.txt 24 | 25 | # Unit test / coverage reports 26 | .cache/ 27 | .pytest_cache/ 28 | .coverage 29 | .coverage.* 30 | .tox 31 | coverage.xml 32 | htmlcov/ 33 | 34 | # Translations 35 | *.mo 36 | 37 | # IDEs and text editors 38 | *~ 39 | *.swp 40 | .idea/ 41 | .project 42 | .pycharm_helpers/ 43 | .pydevproject 44 | .vscode 45 | 46 | # The Silver Searcher 47 | .agignore 48 | 49 | # OS X artifacts 50 | *.DS_Store 51 | 52 | # Logging 53 | log/ 54 | logs/ 55 | chromedriver.log 56 | ghostdriver.log 57 | 58 | # Complexity 59 | output/*.html 60 | output/*/index.html 61 | 62 | # Sphinx 63 | docs/_build 64 | docs/modules.rst 65 | docs/customerdataapi.rst 66 | docs/customerdataapi.*.rst 67 | 68 | # Private requirements 69 | requirements/private.in 70 | requirements/private.txt 71 | 72 | # tox environment temporary artifacts 73 | tests/__init__.py 74 | 75 | # local respository of tutor versions 76 | .tvm/ 77 | 78 | # Development task artifacts 79 | default.db 80 | private.py 81 | venv/ 82 | venv3/ 83 | 84 | # Local configurations 85 | # Note: maintain ignored until we know exactly what goes in the repo 86 | strains/*/env 87 | strains/*/data 88 | strains/*/volumes 89 | strains/*/src 90 | -------------------------------------------------------------------------------- /tests/environment_manager/infrastructure/environment_manager_in_memory_repository.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from tvm.environment_manager.domain.environment_manager_repository import ( 4 | EnvironmentManagerRepository, 5 | ) 6 | 7 | 8 | class EnvironmentManagerInMemoryRepository(EnvironmentManagerRepository): 9 | PLUGINS_INSTALLED = ["codejail"] 10 | PROJECT_NAME = ["v13.1.0@tutortest"] 11 | 12 | def project_creator(self, version: str) -> None: 13 | if version not in self.PROJECT_NAME: 14 | self.PROJECT_NAME.append(version) 15 | else: 16 | raise Exception('There is already a project initiated.') 17 | 18 | def project_remover(self, prune: bool) -> None: 19 | """Tutor Project Remove to environment manager.""" 20 | if self.PROJECT_NAME: 21 | self.PROJECT_NAME.clear() 22 | else: 23 | raise Exception('There is no project to remove.') 24 | 25 | 26 | def install_plugin(self, options: List) -> None: 27 | if options: 28 | self.PLUGINS_INSTALLED.append(options) 29 | else: 30 | raise Exception(f"Error running venv commands: None") 31 | 32 | def uninstall_plugin(self, options: List) -> None: 33 | if options == self.PLUGINS_INSTALLED[0]: 34 | self.PLUGINS_INSTALLED.clear() 35 | else: 36 | raise Exception(f"Error running venv commands: None") 37 | 38 | @staticmethod 39 | def current_version(self) -> None: 40 | pass 41 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | TVM 2 | #### 3 | 4 | TVM is a tool that allows you to manage several Tutor development environments so that they work in isolation, and you can work on different projects with independent Tutor version and configurations. 5 | 6 | User Guide 7 | ----------- 8 | 9 | .. toctree:: 10 | 11 | tvm_quickstart 12 | tvm_topic_guides/index 13 | tvm_tutorials/index 14 | tvm_how_to_guides/index 15 | tvm_advanced_information 16 | 17 | Releases 18 | --------- 19 | 20 | The Releases are listed on the `Github release page `_. All notable changes to this project are documented in the `CHANGELOG `_ file. 21 | 22 | Source code 23 | ----------- 24 | 25 | The complete source code for TVM is available on Github: https://github.com/eduNEXT/tvm 26 | 27 | Support 28 | -------- 29 | 30 | Get support in the TVM Github discussion forum: https://github.com/eduNEXT/tvm/discussions 31 | 32 | Contributing 33 | ------------- 34 | 35 | Contributions are welcome! See our `CONTRIBUTING `_ file for more information. It also contains guidelines for how to maintain high code quality, which will make your contribution more likely to be accepted. 36 | 37 | License 38 | -------- 39 | 40 | The code in this repository is licensed under version 3 of the AGPL unless otherwise noted. Please see the `LICENSE `_ file for details. 41 | -------------------------------------------------------------------------------- /docs/source/tvm_how_to_guides/how_to_configure_vars.rst: -------------------------------------------------------------------------------- 1 | How to configure environment variables in TVM 2 | ############################################## 3 | 4 | In this section, you will learn how to configure the environment variables for each project. 5 | 6 | The project has two variables: ``TUTOR_ROOT`` and ``TUTOR_PLUGINS_ROOT``. 7 | 8 | Index 9 | ------ 10 | 11 | - `Set the TUTOR_ROOT`_ 12 | - `Set the TUTOR_PLUGINS_ROOT`_ 13 | - `Remove the environment variables`_ 14 | 15 | 16 | Set the TUTOR_ROOT 17 | ------------------- 18 | 19 | To set the TUTOR_ROOT, you need to use: 20 | 21 | .. code-block:: bash 22 | 23 | tvm config save 24 | 25 | # For example: 26 | # tvm config save /home/user/tutor-test 27 | # or 28 | # tvm config save . 29 | 30 | 31 | Set the TUTOR_PLUGINS_ROOT 32 | --------------------------- 33 | 34 | By default TUTOR_PLUGINS_ROOT = TUTOR_ROOT/plugins. If you want to set a different TUTOR_PLUGINS_ROOT, you should use the flag ``--plugins-root="PATH"`` 35 | 36 | .. code-block:: bash 37 | 38 | tvm config save --plugins-root="ABSOLUTE PATH" 39 | 40 | # For example: 41 | # tvm config save /home/user/tutor-test --plugins-root="/home/user/tutor-test/plugins" 42 | # or 43 | # tvm config save . --plugins-root="/home/user/tutor-test/plugins" 44 | 45 | 46 | Remove the environment variables 47 | --------------------------------- 48 | 49 | To remove the actual configuration of ``TUTOR_ROOT`` and ``TUTOR_PLUGINS_ROOT`` use: 50 | 51 | .. code-block:: bash 52 | 53 | tvm config clear 54 | -------------------------------------------------------------------------------- /docs/source/tvm_tutorials/creating_two_dev_env.rst: -------------------------------------------------------------------------------- 1 | Creating two development environments 2 | ###################################### 3 | 4 | At the end of this tutorial, you will have two different TVM projects in two separate development environments. 5 | 6 | Step by Step 7 | ------------- 8 | 9 | #. Install the latest stable release of TVM. 10 | 11 | .. code-block:: bash 12 | 13 | pip install git+https://github.com/eduNEXT/tvm.git 14 | 15 | #. Verify the installation. 16 | 17 | .. code-block:: bash 18 | 19 | tvm --version 20 | 21 | #. Create a new project with TVM. 22 | 23 | .. code-block:: bash 24 | 25 | tvm project init 26 | 27 | # For example: 28 | # tvm project init tvm-test v14.0.0 29 | 30 | #. Open the project folder. 31 | 32 | .. code-block:: bash 33 | 34 | cd 35 | 36 | #. Activate the project environment. 37 | 38 | .. code-block:: bash 39 | 40 | source .tvm/bin/activate 41 | 42 | #. Run your project. 43 | 44 | .. code-block:: bash 45 | 46 | tutor dev launch 47 | 48 | #. Stop your project. 49 | 50 | .. code-block:: bash 51 | 52 | tutor dev stop 53 | 54 | #. Deactivate the project environment. 55 | 56 | .. code-block:: bash 57 | 58 | tvmoff 59 | 60 | #. Repeat steps 3 to 8 using the project-name and tutor-version you want. 61 | 62 | .. note:: You can have as many projects as you want, but you can not have two projects with the same name and tutor version. 63 | 64 | Next Steps 65 | ----------- 66 | 67 | - To do more with TVM, check :doc:`TVM Topic Guides `. 68 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | ## Description 12 | 13 | Describe what this pull request changes, and why. Include implications for people using this change. 14 | 15 | Useful information to include: 16 | - Which user roles will this change impact? Common user roles are "Learner", "Course Author", 17 | "Developer", and "Operator". 18 | - Include screenshots for changes to the UI (ideally, both "before" and "after" screenshots, if applicable). 19 | - Provide links to the description of corresponding configuration changes. Remember to annotate these 20 | changes correctly. 21 | 22 | ## Testing instructions 23 | 24 | Please provide detailed step-by-step instructions for testing this change. 25 | 26 | ## Additional information 27 | 28 | Include anything else that will help reviewers and consumers understand the change. 29 | - Does this change depend on other changes elsewhere? 30 | - Any particular concerns or limitations? For example: deprecations, migrations, security, or accessibility. 31 | - Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions. 32 | 33 | ## Checklist for Merge 34 | 35 | - [ ] Updated documentation 36 | - [ ] Rebased master/main 37 | - [ ] Squashed commits 38 | 39 | 44 | -------------------------------------------------------------------------------- /tvm/version_manager/domain/version_manager_repository.py: -------------------------------------------------------------------------------- 1 | """Version manager repository methods.""" 2 | from abc import ABC, abstractmethod 3 | from typing import List, Optional 4 | 5 | from tvm.version_manager.domain.tutor_version import TutorVersion 6 | 7 | 8 | class VersionManagerRepository(ABC): 9 | """Administrate version manager repository methods.""" 10 | 11 | @abstractmethod 12 | def list_versions(self, limit: int) -> List[TutorVersion]: 13 | """List versions of the version manager.""" 14 | 15 | @staticmethod 16 | @abstractmethod 17 | def local_versions(tvm_path: str) -> List[TutorVersion]: 18 | """List local versions of the version manager.""" 19 | 20 | @staticmethod 21 | @abstractmethod 22 | def current_version(tvm_path: str) -> List[TutorVersion]: 23 | """Present the current version of the version manager.""" 24 | 25 | @abstractmethod 26 | def install_version(self, version: TutorVersion) -> None: 27 | """Install the version manager for tutor version.""" 28 | 29 | @abstractmethod 30 | def find_version(self, version: TutorVersion) -> Optional[TutorVersion]: 31 | """Find the tutor version manager.""" 32 | 33 | @abstractmethod 34 | def uninstall_version(self, version: TutorVersion) -> None: 35 | """Uninstall the version manager for tutor version selected.""" 36 | 37 | @abstractmethod 38 | def use_version(self, version: TutorVersion) -> None: 39 | """Use selected version when is installed.""" 40 | 41 | @staticmethod 42 | @abstractmethod 43 | def version_is_installed(version: str) -> None: 44 | """Version is installed method.""" 45 | 46 | @abstractmethod 47 | def install_plugin(self, options: List, version: TutorVersion = None) -> None: 48 | """Install tutor plugin.""" 49 | 50 | @abstractmethod 51 | def uninstall_plugin(self, options: List, version: TutorVersion = None) -> None: 52 | """Uninstall tutor plugin.""" 53 | -------------------------------------------------------------------------------- /tests/version_manager/infrastructure/version_manager_in_memory_repository.py: -------------------------------------------------------------------------------- 1 | from typing import List, Optional 2 | 3 | from tvm.version_manager.domain.tutor_version import TutorVersion 4 | from tvm.version_manager.domain.version_manager_repository import ( 5 | VersionManagerRepository, 6 | ) 7 | 8 | 9 | class VersionManagerInMemoryRepository(VersionManagerRepository): 10 | VERSIONS_INSTALLED = ["v1.2.4"] 11 | PLUGINS_INSTALLED = ["codejail"] 12 | LIST_VERSIONS = [] 13 | for version in range(20): 14 | LIST_VERSIONS.append(f"v1.2.{version}") 15 | 16 | def list_versions(self, limit: int) -> List[TutorVersion]: 17 | return self.LIST_VERSIONS[0:limit] 18 | 19 | @staticmethod 20 | def local_versions(tvm_path: str) -> List[TutorVersion]: 21 | pass 22 | 23 | @staticmethod 24 | def current_version(tvm_path: str) -> List[TutorVersion]: 25 | pass 26 | 27 | def install_version(self, version: TutorVersion) -> None: 28 | self.VERSIONS_INSTALLED.append(version) 29 | 30 | def find_version(self, version: TutorVersion) -> Optional[TutorVersion]: 31 | return version if version in self.VERSIONS_INSTALLED else None 32 | 33 | def uninstall_version(self, version: TutorVersion) -> None: 34 | if version in self.VERSIONS_INSTALLED: 35 | self.VERSIONS_INSTALLED.clear() 36 | 37 | def use_version(self, version: TutorVersion) -> None: 38 | self.VERSIONS_INSTALLED[0] = version 39 | 40 | @staticmethod 41 | def version_is_installed(version: str) -> None: 42 | pass 43 | 44 | def install_plugin(self, options: List, version: str = None) -> None: 45 | if options: 46 | self.PLUGINS_INSTALLED.append(options) 47 | else: 48 | raise Exception(f"Error running venv commands: None") 49 | 50 | def uninstall_plugin(self, options: List, version: str = None) -> None: 51 | if options == self.PLUGINS_INSTALLED[0]: 52 | self.PLUGINS_INSTALLED.clear() 53 | else: 54 | raise Exception(f"Error running venv commands: None") 55 | -------------------------------------------------------------------------------- /docs/source/tvm_quickstart.rst: -------------------------------------------------------------------------------- 1 | Quickstart 2 | ########### 3 | 4 | Let's start by configuring and running our first project. 5 | 6 | Index 7 | ------ 8 | - `Requirements`_ 9 | - `Step by Step`_ 10 | - `Next Steps`_ 11 | 12 | Requirements 13 | ------------- 14 | 15 | TVM works with Tutor for that reason the Tutor requirements are also the TVM requirements. 16 | 17 | **Basic Requirements:** 18 | 19 | - Software: 20 | - `Docker `_: v24.0.5+ (with BuildKit 0.11+) 21 | - `Docker Compose `_: v2.0.0+ 22 | - Hardware: 23 | - Minimum configuration: 4 GB RAM, 2 CPU, 8 GB disk space 24 | - Recommended configuration: 8 GB RAM, 4 CPU, 25 GB disk space 25 | 26 | For more information, see the `Tutor requirements `_. 27 | 28 | 29 | Step by Step 30 | ------------- 31 | 32 | #. Install the latest stable release of TVM. 33 | 34 | .. code-block:: bash 35 | 36 | pip install git+https://github.com/eduNEXT/tvm.git 37 | 38 | #. Verify the installation. 39 | 40 | .. code-block:: bash 41 | 42 | tvm --version 43 | 44 | #. Create a new project with TVM. 45 | 46 | .. code-block:: bash 47 | 48 | tvm project init 49 | 50 | # For example: 51 | # tvm project init tvm-test v14.0.0 52 | 53 | #. Open the project folder. 54 | 55 | .. code-block:: bash 56 | 57 | cd 58 | 59 | #. Activate the project environment. 60 | 61 | .. code-block:: bash 62 | 63 | source .tvm/bin/activate 64 | 65 | #. Run your project. 66 | 67 | .. code-block:: bash 68 | 69 | tutor local launch 70 | 71 | .. note:: For Tutor versions <15, init a project with ``tutor local quickstart``` 72 | 73 | 74 | Next Steps 75 | ----------- 76 | 77 | - To do more with TVM, check :doc:`Tutorials ` or :doc:`TVM Topic Guides `. 78 | - To know more about Tutor, check `Tutor documentation `_. 79 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean help \ 2 | quality requirements selfcheck test upgrade 3 | 4 | .DEFAULT_GOAL := help 5 | 6 | # For opening files in a browser. Use like: $(BROWSER)relative/path/to/file.html 7 | BROWSER := python -m webbrowser file://$(CURDIR)/ 8 | 9 | help: ## display this help message 10 | @echo "Please use \`make ' where is one of" 11 | @awk -F ':.*?## ' '/^[a-zA-Z]/ && NF==2 {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort 12 | 13 | clean: ## remove generated byte code, coverage reports, and build artifacts 14 | find tvm -name '__pycache__' -exec rm -rf {} + 15 | find tvm -name '*.pyc' -exec rm -f {} + 16 | find tvm -name '*.pyo' -exec rm -f {} + 17 | find tvm -name '*~' -exec rm -f {} + 18 | coverage erase 19 | rm -fr build/ 20 | rm -fr dist/ 21 | rm -fr *.egg-info 22 | 23 | # Define PIP_COMPILE_OPTS=-v to get more information during make upgrade. 24 | PIP_COMPILE = pip-compile --upgrade $(PIP_COMPILE_OPTS) 25 | 26 | upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade 27 | upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in 28 | pip install -r requirements/pip-tools.txt 29 | # Make sure to compile files after any other files they include! 30 | $(PIP_COMPILE) --allow-unsafe --rebuild -o requirements/pip.txt requirements/pip.in 31 | $(PIP_COMPILE) -o requirements/pip-tools.txt requirements/pip-tools.in 32 | pip install -r requirements/pip-tools.txt 33 | $(PIP_COMPILE) -o requirements/base.txt requirements/base.in 34 | $(PIP_COMPILE) -o requirements/dev.txt requirements/dev.in 35 | $(PIP_COMPILE) -o requirements/doc.txt requirements/doc.in 36 | 37 | quality: ## check coding style with pycodestyle and pylint 38 | pylint tvm *.py 39 | pycodestyle tvm *.py --exclude='*/templates/*' 40 | pydocstyle tvm *.py 41 | isort --check-only --diff tvm *.py 42 | 43 | requirements: ## install development environment requirements 44 | pip install -r requirements/pip.txt 45 | pip install -r requirements/pip-tools.txt 46 | pip-sync requirements/dev.txt 47 | pip install -e . 48 | 49 | test: ## run unitary tests and meassure coverage 50 | coverage run -m pytest 51 | coverage report -m --fail-under=37 52 | 53 | run_tests: test quality 54 | 55 | autocomplete: 56 | @_TVM_COMPLETE=bash_source tvm >> ~/.ednx-tvm-complete.sh 57 | @echo 'Now run: echo ". ~/.ednx-tvm-complete.sh" >> ~/.bashrc' 58 | 59 | selfcheck: ## check that the Makefile is well-formed 60 | @echo "The Makefile is well-formed." 61 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # For the full list of built-in configuration values, see the documentation: 4 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 5 | 6 | # -- Project information ----------------------------------------------------- 7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information 8 | 9 | project = 'TVM' 10 | copyright = '2022, eduNEXT' 11 | author = 'eduNEXT' 12 | 13 | # -- General configuration --------------------------------------------------- 14 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration 15 | 16 | extensions = [ 17 | "sphinxcontrib.youtube", 18 | "sphinxcontrib.images", 19 | "sphinx_panels", 20 | "sphinxcontrib.contentui", 21 | "sphinx_copybutton", 22 | "sphinx.ext.graphviz", 23 | "sphinxcontrib.mermaid", 24 | "recommonmark", 25 | ] 26 | 27 | templates_path = ['_templates'] 28 | exclude_patterns = [] 29 | 30 | 31 | 32 | # -- Options for HTML output ------------------------------------------------- 33 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output 34 | 35 | html_theme = 'sphinx_book_theme' 36 | html_static_path = ['_static'] 37 | 38 | # eduNEXT configuration 39 | html_logo = '_static/Knowledge_Base_logo.png' 40 | extra_navbar_content = """ 41 |

42 | 43 | About the 44 | project in Github:
45 | 46 | 47 | """ 48 | 49 | html_theme_options = { 50 | "repository_url": "https://github.com/eduNEXT/tvm", 51 | "repository_branch": "main", 52 | "path_to_docs": "source", 53 | "use_edit_page_button": True, 54 | "logo_only": False, 55 | "extra_navbar": extra_navbar_content, 56 | "home_page_in_toc": True, 57 | "show_navbar_depth": 1, 58 | "use_repository_button": True, 59 | "use_issues_button": True 60 | } 61 | 62 | html_sidebars = {'**': ["sidebar-logo.html", "search-field.html", "sbt-sidebar-nav.html"]} 63 | 64 | # For custom styles 65 | images_config = { 66 | "default_image_width": "100%", 67 | } 68 | 69 | html_css_files = [ 70 | "css/custom.css", 71 | "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css", 72 | ] 73 | 74 | html_js_files = [ 75 | "_js/custom.js", 76 | ] 77 | 78 | togglebutton_hint = "Show" 79 | togglebutton_hint_hide = "Hide" 80 | 81 | # Panels conf 82 | panels_add_bootstrap_css = False 83 | # html_title = "" 84 | -------------------------------------------------------------------------------- /tvm/templates/tvm_activate.py: -------------------------------------------------------------------------------- 1 | """Tutor switcher jinja template.""" 2 | from jinja2 import Template 3 | 4 | TEMPLATE = ''' 5 | # This file must be used with "source bin/activate" *from bash* 6 | # you cannot run it directly 7 | if [ "${BASH_SOURCE-}" = "$0" ]; then 8 | echo "You must source this script: \$ source $0" >&2 9 | exit 33 10 | fi 11 | tvmoff () { 12 | # reset old environment variables 13 | # ! [ -z ${VAR+_} ] returns true if VAR is declared at all 14 | if ! [ -z "${TVM_PROJECT_ENV:+_}" ] ; then 15 | unset TVM_PROJECT_ENV 16 | fi 17 | 18 | if ! [ -z "${_TVM_OLD_VIRTUAL_PATH:+_}" ] ; then 19 | PATH="$_TVM_OLD_VIRTUAL_PATH" 20 | export PATH 21 | unset _TVM_OLD_VIRTUAL_PATH 22 | fi 23 | if ! [ -z "${_TVM_OLD_TUTOR_ROOT:+_}" ] ; then 24 | TUTOR_ROOT="$_TVM_OLD_TUTOR_ROOT" 25 | export TUTOR_ROOT 26 | unset _TVM_OLD_TUTOR_ROOT 27 | else 28 | unset TUTOR_ROOT 29 | fi 30 | if ! [ -z "${_TVM_OLD_TUTOR_PLUGINS_ROOT:+_}" ] ; then 31 | TUTOR_PLUGINS_ROOT="$_TVM_OLD_TUTOR_PLUGINS_ROOT" 32 | export TUTOR_PLUGINS_ROOT 33 | unset _TVM_OLD_TUTOR_PLUGINS_ROOT 34 | else 35 | unset TUTOR_PLUGINS_ROOT 36 | fi 37 | # The hash command must be called to get it to forget past 38 | # commands. Without forgetting past commands the $PATH changes 39 | # we made may not be respected 40 | hash -r 2>/dev/null 41 | if ! [ -z "${_TVM_OLD_VIRTUAL_PS1+_}" ] ; then 42 | PS1="$_TVM_OLD_VIRTUAL_PS1" 43 | export PS1 44 | unset _TVM_OLD_VIRTUAL_PS1 45 | fi 46 | unset VIRTUAL_ENV 47 | if [ ! "${1-}" = "nondestructive" ] ; then 48 | # Self destruct! 49 | unset -f tvmoff 50 | fi 51 | } 52 | # unset irrelevant variables 53 | tvmoff nondestructive 54 | TVM_PROJECT_ENV="{{ tutor_root }}" 55 | export TVM_PROJECT_ENV 56 | _TVM_OLD_VIRTUAL_PATH="$PATH" 57 | PATH="{{tvm_path}}/{{version}}/venv/bin:$PATH" 58 | export PATH 59 | if ! [ -z "${TUTOR_ROOT+_}" ] ; then 60 | _TVM_OLD_TUTOR_ROOT="$TUTOR_ROOT" 61 | fi 62 | TUTOR_ROOT="{{ tutor_root }}" 63 | export TUTOR_ROOT 64 | if ! [ -z "${TUTOR_PLUGINS_ROOT+_}" ] ; then 65 | _TVM_OLD_TUTOR_PLUGINS_ROOT="$TUTOR_PLUGINS_ROOT" 66 | fi 67 | TUTOR_PLUGINS_ROOT="{{ tutor_plugins_root }}" 68 | export TUTOR_PLUGINS_ROOT 69 | _TVM_OLD_VIRTUAL_PS1="${PS1-}" 70 | if [ "x{{version}}" != x ] ; then 71 | PS1="[{{version}}] ${PS1-}" 72 | else 73 | PS1="(`basename \"$VIRTUAL_ENV\"`) ${PS1-}" 74 | fi 75 | export PS1 76 | # The hash command must be called to get it to forget past 77 | # commands. Without forgetting past commands the $PATH changes 78 | # we made may not be respected 79 | hash -r 2>/dev/null 80 | ''' 81 | 82 | TVM_ACTIVATE_SCRIPT = Template(TEMPLATE) 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TVM 2 | 3 | ![Maintainance Badge](https://img.shields.io/badge/Status-Maintained-brightgreen) 4 | ![Test Badge](https://img.shields.io/github/actions/workflow/status/edunext/tvm/.github%2Fworkflows%2Ftests.yml?label=Test) 5 | ![GitHub Tag](https://img.shields.io/github/v/tag/edunext/tvm?label=Tag) 6 | 7 | 8 | TVM is a tool that allows you to manage several Tutor development environments so that they work in isolation, and you can work on different projects with independent Tutor versions and configurations. 9 | 10 | TVM is also the acronym for: 11 | 12 | - **Tutor Version Manager:** Handle the Tutor versions. 13 | - **Tutor enVironment Manager:** Create project-based environments with Tutor. 14 | 15 | # Installing TVM 16 | 17 | Open a terminal and run: 18 | 19 | ```bash 20 | pip install git+https://github.com/eduNEXT/tvm.git 21 | ``` 22 | 23 | Verify the installation: 24 | 25 | ```bash 26 | tvm --version 27 | ``` 28 | 29 | # Getting Started 30 | 31 | Create and activate a new project with the following steps: 32 | 33 | 1. Install the version of Tutor you want to use with TVM. 34 | 35 | ```bash 36 | tvm install 37 | 38 | # For example: 39 | # tvm install v14.0.0 40 | ``` 41 | 42 | 2. Create a new project with TVM. 43 | 44 | ```bash 45 | tvm project init 46 | 47 | # For example: 48 | # tvm project init tvm-test v14.0.0 49 | ``` 50 | 51 | 3. Open the project folder. 52 | 53 | ```bash 54 | cd 55 | ``` 56 | 57 | 4. Activate the project environment. 58 | 59 | ```bash 60 | source .tvm/bin/activate 61 | ``` 62 | 63 | 5. Run your project. 64 | 65 | ```bash 66 | tutor local launch 67 | ``` 68 | 69 | > [!NOTE] 70 | > For Tutor versions <15, init a project with `tutor local quickstart` 71 | 72 | You can start configuring and using your Tutor instance. 73 | 74 | ## Next steps 75 | 76 | If you want to see what else you can do, access **the complete TVM documentation**: https://tvm.docs.edunext.co 77 | 78 | # Getting Help 79 | 80 | - To report a bug or ask for a feature, go to the TVM GitHub issues: https://github.com/eduNEXT/tvm/issues 81 | 82 | - To get support, go to the TVM Github discussion forum: https://github.com/eduNEXT/tvm/discussions 83 | 84 | # How to Contribute 85 | 86 | Contributions are welcome! See our [CONTRIBUTING](https://github.com/edunext/tvm/blob/master/CONTRIBUTING.md) file for more information – it also contains guidelines for how to maintain high code quality, which will make your contribution more likely to be accepted. 87 | 88 | # License 89 | 90 | The code in this repository is licensed under version 3 of the AGPL unless 91 | otherwise noted. Please see the [LICENSE](https://github.com/edunext/tvm/blob/main/LICENSE) file for details. 92 | -------------------------------------------------------------------------------- /requirements/doc.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with Python 3.10 3 | # by the following command: 4 | # 5 | # make upgrade 6 | # 7 | alabaster==0.7.16 8 | # via sphinx 9 | babel==2.14.0 10 | # via sphinx 11 | beautifulsoup4==4.12.3 12 | # via pydata-sphinx-theme 13 | certifi==2024.2.2 14 | # via requests 15 | charset-normalizer==3.3.2 16 | # via requests 17 | commonmark==0.9.1 18 | # via recommonmark 19 | docutils==0.17.1 20 | # via 21 | # pydata-sphinx-theme 22 | # recommonmark 23 | # sphinx 24 | # sphinx-panels 25 | idna==3.7 26 | # via requests 27 | imagesize==1.4.1 28 | # via sphinx 29 | jinja2==3.1.3 30 | # via sphinx 31 | markupsafe==2.1.5 32 | # via jinja2 33 | packaging==24.0 34 | # via 35 | # pydata-sphinx-theme 36 | # sphinx 37 | pydata-sphinx-theme==0.8.1 38 | # via sphinx-book-theme 39 | pygments==2.17.2 40 | # via sphinx 41 | pyyaml==6.0.1 42 | # via sphinx-book-theme 43 | recommonmark==0.6.0 44 | # via -r requirements/doc.in 45 | requests==2.31.0 46 | # via 47 | # sphinx 48 | # sphinxcontrib-images 49 | # sphinxcontrib-youtube 50 | snowballstemmer==2.2.0 51 | # via sphinx 52 | soupsieve==2.5 53 | # via beautifulsoup4 54 | sphinx==4.2.0 55 | # via 56 | # -r requirements/doc.in 57 | # pydata-sphinx-theme 58 | # recommonmark 59 | # sphinx-book-theme 60 | # sphinx-copybutton 61 | # sphinx-panels 62 | # sphinxcontrib-contentui 63 | # sphinxcontrib-images 64 | # sphinxcontrib-youtube 65 | sphinx-book-theme==0.3.3 66 | # via -r requirements/doc.in 67 | sphinx-copybutton==0.5.0 68 | # via -r requirements/doc.in 69 | sphinx-panels==0.6.0 70 | # via -r requirements/doc.in 71 | sphinxcontrib-applehelp==1.0.4 72 | # via 73 | # -r requirements/doc.in 74 | # sphinx 75 | sphinxcontrib-contentui==0.2.5 76 | # via -r requirements/doc.in 77 | sphinxcontrib-devhelp==1.0.2 78 | # via 79 | # -r requirements/doc.in 80 | # sphinx 81 | sphinxcontrib-htmlhelp==2.0.1 82 | # via 83 | # -r requirements/doc.in 84 | # sphinx 85 | sphinxcontrib-images==0.9.4 86 | # via -r requirements/doc.in 87 | sphinxcontrib-jsmath==1.0.1 88 | # via 89 | # -r requirements/doc.in 90 | # sphinx 91 | sphinxcontrib-mermaid==0.7.1 92 | # via -r requirements/doc.in 93 | sphinxcontrib-qthelp==1.0.3 94 | # via 95 | # -r requirements/doc.in 96 | # sphinx 97 | sphinxcontrib-serializinghtml==1.1.5 98 | # via 99 | # -r requirements/doc.in 100 | # sphinx 101 | sphinxcontrib-youtube==1.3.0 102 | # via -r requirements/doc.in 103 | urllib3==2.2.1 104 | # via requests 105 | 106 | # The following packages are considered to be unsafe in a requirements file: 107 | # setuptools 108 | -------------------------------------------------------------------------------- /.github/workflows/bump_version.yml: -------------------------------------------------------------------------------- 1 | name: Bump version 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | bumpversion: 8 | runs-on: ubuntu-latest 9 | outputs: 10 | version: ${{ steps.tag_version.outputs.new_version }} 11 | previous_tag: ${{ steps.tag_version.outputs.previous_tag }} 12 | bump_commit_sha: ${{ steps.bumpversion.outputs.commit_hash }} 13 | steps: 14 | - uses: actions/checkout@v3 15 | with: 16 | token: ${{ secrets.DEDALO_PAT }} 17 | - name: Get next version 18 | id: tag_version 19 | uses: mathieudutour/github-tag-action@v6.0 20 | with: 21 | github_token: ${{ secrets.GITHUB_TOKEN }} 22 | default_bump: false 23 | default_prerelease_bump: false 24 | dry_run: true 25 | - name: Set up Python 3.8 26 | uses: actions/setup-python@v2 27 | with: 28 | python-version: "3.8" 29 | - name: Create bumpversion 30 | if: steps.tag_version.outputs.new_version 31 | run: | 32 | pip install bumpversion 33 | bumpversion --new-version ${{ steps.tag_version.outputs.new_version }} setup.cfg 34 | - name: Update Changelog 35 | if: steps.tag_version.outputs.new_version 36 | uses: stefanzweifel/changelog-updater-action@v1.6.2 37 | with: 38 | latest-version: ${{ steps.tag_version.outputs.new_tag }} 39 | release-notes: ${{ steps.tag_version.outputs.changelog }} 40 | - name: Commit bumpversion 41 | id: bumpversion 42 | if: steps.tag_version.outputs.new_version 43 | uses: stefanzweifel/git-auto-commit-action@v4.14.1 44 | with: 45 | branch: ${{ github.ref }} 46 | commit_message: "docs(bumpversion): ${{ steps.tag_version.outputs.previous_tag }} → ${{ steps.tag_version.outputs.new_version }}" 47 | file_pattern: setup.cfg CHANGELOG.md tvm/* 48 | release: 49 | needs: bumpversion 50 | if: needs.bumpversion.outputs.version 51 | runs-on: ubuntu-latest 52 | outputs: 53 | tag: ${{ steps.tag_version.outputs.new_tag }} 54 | changelog: ${{ steps.tag_version.outputs.changelog }} 55 | steps: 56 | - uses: actions/checkout@v3 57 | with: 58 | token: ${{ secrets.DEDALO_PAT }} 59 | - name: Create tag 60 | id: tag_version 61 | uses: mathieudutour/github-tag-action@v6.0 62 | with: 63 | github_token: ${{ secrets.GITHUB_TOKEN }} 64 | commit_sha: ${{ needs.bumpversion.outputs.bump_commit_sha }} 65 | default_bump: false 66 | default_prerelease_bump: false 67 | - name: Create a GitHub release 68 | if: steps.tag_version.outputs.new_tag 69 | uses: ncipollo/release-action@v1 70 | with: 71 | tag: ${{ steps.tag_version.outputs.new_tag }} 72 | name: Release ${{ steps.tag_version.outputs.new_tag }} 73 | body: ${{ steps.tag_version.outputs.changelog }} 74 | draft: true 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the eduNEXT TVM 2 | 3 | # If you've got only the idea 4 | If you do not have the ability to develop the idea but you need that solution, you will be able to [open a new feature request](https://github.com/eduNEXT/tvm/issues/new/choose)), if the idea is adopted by the community, this can be continued the next process, read __If you want contribute with code__ 5 | 6 | # If you want contribute with code 7 | ## Step 0: Join the Conversation 8 | Got an idea for how to improve the codebase? Fantastic, we'd love to hear about it! Before you dive in and spend a lot of time and effort making a pull request, it's a good idea to discuss your idea with other interested developers and/or the eduNEXT product team. You may get some valuable feedback that changes how you think about your idea, or you may find other developers who have the same idea and want to work together. 9 | 10 | ### Repository Discussions 11 | If you've got an idea for a new feature, please start a discussion in the [__ideas__](https://github.com/eduNEXT/tvm/discussions/categories/ideas) category of the github repository discussion to get feedback from the community about your idea. 12 | 13 | ## Step 1: Fork, Commit, and Pull Request 14 | __This confirms that you have the authority to contribute the code in the pull request and ensures that eduNEXT can re-license it__ 15 | 16 | GitHub has some great documentation on [how to fork a git repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo). Once you've done that, make your changes and send us a pull request! Be sure to include a detailed description for your pull request, so that a community manager can understand what change you're making, why you're making it, how it should work now, and how you can test that it's working correctly. 17 | 18 | ## Step 2: Meet PR Requirements 19 | - Commits signed - [How to do it](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) 20 | - The commits respects conventional commits - [How to do it](https://www.conventionalcommits.org/en/v1.0.0/) 21 | - Repository actions are passing without problems. 22 | - Good Pull Request Cover Letter [How to do it](https://blog.alphasmanifesto.com/2016/07/11/how-to-create-a-good-pull-request/) 23 | 24 | ## Step 4: Code Review by team TVM Maintainers member(s) 25 | A team tvm maintainers member will read the description of your pull request. If the descriptions is understandable and your pull request meets the requirements listed in the contributor documentation (__read Meet PR Requirements__), then it will be reviewed by one or more core commiters. 26 | 27 | Once the code review process has started, please be responsive to comments on the pull request, so we can keep the review process moving forward. If you are unable to respond for a few days, that's fine, but please add a comment informing us of that -- otherwise, it looks like you're abandoning your work! 28 | 29 | ## Step 5: Merge! 30 | Once the team tvm maintainers members are satisfied that your pull request is ready to go, one of them will merge it for you. Congrats! 31 | -------------------------------------------------------------------------------- /requirements/dev.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with Python 3.10 3 | # by the following command: 4 | # 5 | # make upgrade 6 | # 7 | astroid==2.11.7 8 | # via pylint 9 | certifi==2024.2.2 10 | # via 11 | # -r requirements/base.txt 12 | # requests 13 | charset-normalizer==3.3.2 14 | # via 15 | # -r requirements/base.txt 16 | # requests 17 | click==8.1.7 18 | # via -r requirements/base.txt 19 | coverage==7.5.0 20 | # via -r requirements/dev.in 21 | dill==0.3.8 22 | # via pylint 23 | distlib==0.3.8 24 | # via 25 | # -r requirements/base.txt 26 | # virtualenv 27 | exceptiongroup==1.2.1 28 | # via pytest 29 | filelock==3.14.0 30 | # via 31 | # -r requirements/base.txt 32 | # virtualenv 33 | gitdb==4.0.11 34 | # via 35 | # -r requirements/base.txt 36 | # gitpython 37 | gitpython==3.1.43 38 | # via -r requirements/base.txt 39 | idna==3.7 40 | # via 41 | # -r requirements/base.txt 42 | # requests 43 | iniconfig==2.0.0 44 | # via pytest 45 | isort==5.13.2 46 | # via pylint 47 | jedi==0.19.1 48 | # via pudb 49 | jinja2==3.1.3 50 | # via -r requirements/base.txt 51 | lazy-object-proxy==1.10.0 52 | # via astroid 53 | markupsafe==2.1.5 54 | # via 55 | # -r requirements/base.txt 56 | # jinja2 57 | mccabe==0.7.0 58 | # via pylint 59 | packaging==24.0 60 | # via 61 | # -r requirements/base.txt 62 | # pudb 63 | # pytest 64 | parso==0.8.4 65 | # via jedi 66 | platformdirs==4.2.1 67 | # via 68 | # -r requirements/base.txt 69 | # pylint 70 | # virtualenv 71 | pluggy==1.5.0 72 | # via pytest 73 | pudb==2024.1 74 | # via -r requirements/dev.in 75 | pycodestyle==2.11.1 76 | # via -r requirements/dev.in 77 | pydocstyle==6.3.0 78 | # via -r requirements/dev.in 79 | pygments==2.17.2 80 | # via pudb 81 | pylint==2.14.5 82 | # via 83 | # -c requirements/constraints.txt 84 | # -r requirements/dev.in 85 | pytest==8.2.0 86 | # via -r requirements/dev.in 87 | pyyaml==6.0.1 88 | # via -r requirements/base.txt 89 | requests==2.31.0 90 | # via 91 | # -r requirements/base.txt 92 | # -r requirements/dev.in 93 | smmap==5.0.1 94 | # via 95 | # -r requirements/base.txt 96 | # gitdb 97 | snowballstemmer==2.2.0 98 | # via pydocstyle 99 | tomli==2.0.1 100 | # via 101 | # pylint 102 | # pytest 103 | tomlkit==0.12.4 104 | # via pylint 105 | typing-extensions==4.11.0 106 | # via urwid 107 | urllib3==2.2.1 108 | # via 109 | # -r requirements/base.txt 110 | # requests 111 | urwid==2.6.11 112 | # via 113 | # pudb 114 | # urwid-readline 115 | urwid-readline==0.14 116 | # via pudb 117 | virtualenv==20.26.1 118 | # via -r requirements/base.txt 119 | wcwidth==0.2.13 120 | # via urwid 121 | wrapt==1.16.0 122 | # via astroid 123 | 124 | # The following packages are considered to be unsafe in a requirements file: 125 | # setuptools 126 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Package metadata for tvm.""" 3 | import os 4 | import re 5 | import sys 6 | 7 | from setuptools import find_packages, setup 8 | 9 | 10 | def get_version(*file_paths): 11 | """ 12 | Extract the version string from the file. 13 | 14 | Input: 15 | - file_paths: relative path fragments to file with 16 | version string 17 | """ 18 | filename = os.path.join(os.path.dirname(__file__), *file_paths) 19 | 20 | with open(filename, 'r', encoding='utf-8') as version_file: 21 | version_file = version_file.read() 22 | version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", 23 | version_file, re.M) 24 | if version_match: 25 | return version_match.group(1) 26 | raise RuntimeError('Unable to find version string.') 27 | 28 | 29 | def load_requirements(*requirements_paths): 30 | """ 31 | Load all requirements from the specified requirements files. 32 | 33 | Returns: 34 | list: Requirements file relative path strings 35 | """ 36 | requirements = set() 37 | for path in requirements_paths: 38 | with open(path, 'r', encoding='utf-8') as requirements_file: 39 | requirements.update( 40 | line.split('#')[0].strip() for line in requirements_file.readlines() 41 | if is_requirement(line.strip()) 42 | ) 43 | return list(requirements) 44 | 45 | 46 | def is_requirement(line): 47 | """ 48 | Return True if the requirement line is a package requirement. 49 | 50 | Returns: 51 | bool: True if the line is not blank, a comment, a URL, or 52 | an included file 53 | """ 54 | return line and not line.startswith(('-r', '#', '-e', 'git+', '-c')) 55 | 56 | 57 | VERSION = get_version('tvm', '__init__.py') 58 | 59 | if sys.argv[-1] == 'tag': 60 | print("Tagging the version on github:") 61 | os.system(f"git tag -a {VERSION} -m 'version {VERSION}'") 62 | os.system("git push --tags") 63 | sys.exit() 64 | 65 | with open(os.path.join(os.path.dirname(__file__), 'README.md'), 'r', encoding='utf-8') as readme_file: 66 | README = readme_file.read() 67 | 68 | with open(os.path.join(os.path.dirname(__file__), 'CHANGELOG.md'), 'r', encoding='utf-8') as changelog_file: 69 | CHANGELOG = changelog_file.read() 70 | 71 | setup( 72 | name='tutor-version-manager', 73 | version=VERSION, 74 | description="""It manages Tutor versions and enables switching between them.""", 75 | long_description=README + '\n\n' + CHANGELOG, 76 | author='eduNEXT', 77 | author_email='contact@edunext.co', 78 | packages=find_packages(exclude=["tests*"]), 79 | include_package_data=True, 80 | install_requires=load_requirements('requirements/base.in'), 81 | python_requires=">=3.8", 82 | zip_safe=False, 83 | keywords='Python eduNEXT Open edX Tutor', 84 | classifiers=[ 85 | 'Development Status :: 3 - Alpha', 86 | 'Intended Audience :: Developers', 87 | 'License :: Other/Proprietary License', 88 | 'Natural Language :: English', 89 | 'Programming Language :: Python :: 3', 90 | 'Programming Language :: Python :: 3.8', 91 | ], 92 | entry_points={ 93 | 'console_scripts': [ 94 | 'tvm = tvm.cli:main', 95 | ], 96 | }, 97 | ) 98 | -------------------------------------------------------------------------------- /docs/source/tvm_topic_guides/environment_manager.rst: -------------------------------------------------------------------------------- 1 | TVM as Environment Manager 2 | ########################### 3 | 4 | Index 5 | ------ 6 | 7 | - `Create a Project`_ 8 | - `Remove a Project Environment`_ 9 | - `Activate a Project Environment`_ 10 | - `Deactivate a Project Environment`_ 11 | - `List Environments and Projects`_ 12 | - `Install Tutor Plugins`_ 13 | - `Uninstall Tutor Plugins`_ 14 | 15 | 16 | Create a Project 17 | ----------------- 18 | 19 | .. code-block:: bash 20 | 21 | tvm project init 22 | 23 | # For example: 24 | # tvm project init tvm-test v14.0.0 25 | 26 | 27 | .. note:: The parameter is optional. However, if you don't specify the version, the project will be created with the version you set previously with tvm use or the latest version. If you specify the version, and the version isn't installed, it will be installed. 28 | 29 | 30 | Remove a Project Environment 31 | ---------------------------- 32 | 33 | .. code-block:: bash 34 | 35 | tvm project remove @ 36 | 37 | # For example: 38 | # tvm project remove v14.0.0@tvm-test 39 | 40 | 41 | .. note:: You can use the flag --prune to remove all the project folder. E.g. ``tvm project remove v14.0.0@tvm-test --prune`` 42 | 43 | 44 | Activate a Project Environment 45 | ------------------------------ 46 | 47 | .. code-block:: bash 48 | 49 | source .tvm/bin/activate 50 | 51 | 52 | Deactivate a Project Environment 53 | -------------------------------- 54 | 55 | .. code-block:: bash 56 | 57 | tvmoff 58 | 59 | 60 | .. warning:: If you also have another environment like a python virtual environment, you need to deactivate each virtual environment in order. For example, if you have ``(venv) [v12.2.0@project-name]``, you need to run ``deactivate`` and then ``tvmoff``. 61 | 62 | List Environments and Projects 63 | -------------------------------- 64 | 65 | .. code-block:: bash 66 | 67 | tvm list 68 | 69 | 70 | .. note:: You can use the flag -l or --limit and an integer to restrict the output. E.g. ``tvm list --limit 10`` 71 | 72 | Install Tutor Plugins 73 | ---------------------- 74 | 75 | There are two ways to install Tutor plugins in your project. 76 | 77 | TVM 78 | ^^^^ 79 | 80 | .. code-block:: bash 81 | 82 | tvm plugins install 83 | 84 | 85 | Pip 86 | ^^^^ 87 | 88 | .. code-block:: bash 89 | 90 | pip install 91 | 92 | 93 | .. note:: If you don't already have your project environment activated, you can activate it using ``source .tvm/bin/activate``, and then you will be able to use the pip command. 94 | 95 | 96 | Uninstall Tutor Plugins 97 | ------------------------ 98 | 99 | There are two ways to uninstall Tutor plugins in your project. 100 | 101 | 102 | TVM 103 | ^^^^ 104 | 105 | .. code-block:: bash 106 | 107 | tvm plugins uninstall 108 | 109 | 110 | Pip 111 | ^^^^ 112 | 113 | .. code-block:: bash 114 | 115 | pip uninstall 116 | 117 | 118 | .. note:: If you don't already have your project environment activated, you can activate it using ``source .tvm/bin/activate``, and then you will be able to use the pip command. 119 | 120 | 121 | Related 122 | -------- 123 | 124 | - :doc:`TVM as Tutor Manager `. 125 | -------------------------------------------------------------------------------- /docs/source/tvm_topic_guides/version_manager.rst: -------------------------------------------------------------------------------- 1 | TVM as Tutor Manager 2 | #################### 3 | 4 | Index 5 | ------ 6 | - `Install a Tutor version`_ 7 | - `Uninstall a Tutor version`_ 8 | - `Use a Tutor version`_ 9 | - `Configure the TUTOR_ROOT`_ 10 | - `Configure the TUTOR_PLUGINS_ROOT`_ 11 | - `Remove the TUTOR_ROOT and TUTOR_PLUGINS_ROOT variables`_ 12 | - `List Environments and Projects`_ 13 | - `Install Tutor Plugins`_ 14 | - `Uninstall Tutor Plugins`_ 15 | 16 | Install a Tutor version 17 | ------------------------ 18 | 19 | .. code-block:: bash 20 | 21 | tvm install 22 | 23 | # For example: 24 | # tvm install v14.0.0 25 | 26 | Uninstall a Tutor version 27 | ------------------------- 28 | 29 | .. code-block:: bash 30 | 31 | tvm uninstall 32 | 33 | # For example: 34 | # tvm uninstall v14.0.0 35 | 36 | Use a Tutor version 37 | -------------------- 38 | 39 | .. code-block:: bash 40 | 41 | tvm use 42 | 43 | # For example: 44 | # tvm use v14.0.0 45 | 46 | Configure the TUTOR_ROOT 47 | ------------------------- 48 | 49 | .. code-block:: bash 50 | 51 | tvm config save 52 | 53 | # For example: 54 | # tvm config save /home/user/tutor-test 55 | # or 56 | # tvm config save . 57 | 58 | Configure the TUTOR_PLUGINS_ROOT 59 | --------------------------------- 60 | 61 | .. code-block:: bash 62 | 63 | tvm config save --plugins-root="ABSOLUTE PATH" 64 | 65 | # For example: 66 | # tvm config save /home/user/tutor-test --plugins-root="/home/user/tutor-test/plugins" 67 | # or 68 | # tvm config save . --plugins-root="/home/user/tutor-test/plugins" 69 | 70 | 71 | Remove the TUTOR_ROOT and TUTOR_PLUGINS_ROOT variables 72 | ------------------------------------------------------- 73 | 74 | .. code-block:: bash 75 | 76 | tvm config clear 77 | 78 | 79 | List Environments and Projects 80 | -------------------------------- 81 | 82 | .. code-block:: bash 83 | 84 | tvm list 85 | 86 | 87 | .. note:: You can use the flag -l or --limit and an integer to restrict the output. E.g. ``tvm list --limit 10`` 88 | 89 | 90 | Install Tutor Plugins 91 | ---------------------- 92 | 93 | There are two ways to install Tutor plugins in your project. 94 | 95 | TVM 96 | ^^^^ 97 | 98 | .. code-block:: bash 99 | 100 | tvm plugins install 101 | 102 | 103 | Pip 104 | ^^^^ 105 | 106 | .. code-block:: bash 107 | 108 | pip install 109 | 110 | 111 | .. note:: If you don't already have your project environment activated, you can activate it using ``source .tvm/bin/activate``, and then you will be able to use the pip command. 112 | 113 | 114 | Uninstall Tutor Plugins 115 | ------------------------ 116 | 117 | There are two ways to uninstall Tutor plugins in your project. 118 | 119 | 120 | TVM 121 | ^^^^ 122 | 123 | .. code-block:: bash 124 | 125 | tvm plugins uninstall 126 | 127 | 128 | Pip 129 | ^^^^ 130 | 131 | .. code-block:: bash 132 | 133 | pip uninstall 134 | 135 | 136 | .. note:: If you don't already have your project environment activated, you can activate it using ``source .tvm/bin/activate``, and then you will be able to use the pip command. 137 | 138 | 139 | Related 140 | -------- 141 | 142 | - :doc:`TVM as Environment Manager `. 143 | -------------------------------------------------------------------------------- /pylintrc: -------------------------------------------------------------------------------- 1 | 2 | [MASTER] 3 | ignore = migrations, templates 4 | persistent = yes 5 | 6 | [MESSAGES CONTROL] 7 | disable = 8 | locally-disabled, 9 | locally-enabled, 10 | too-few-public-methods, 11 | bad-builtin, 12 | star-args, 13 | abstract-class-not-used, 14 | abstract-class-little-used, 15 | no-init, 16 | fixme, 17 | logging-format-interpolation, 18 | too-many-lines, 19 | no-self-use, 20 | too-many-ancestors, 21 | too-many-instance-attributes, 22 | too-few-public-methods, 23 | too-many-public-methods, 24 | too-many-return-statements, 25 | too-many-branches, 26 | too-many-arguments, 27 | too-many-locals, 28 | unused-wildcard-import 29 | 30 | [REPORTS] 31 | output-format = text 32 | files-output = no 33 | reports = no 34 | evaluation = 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) 35 | 36 | [BASIC] 37 | bad-functions = map,filter,apply,input 38 | module-rgx = (([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 39 | const-rgx = (([A-Z_][A-Z0-9_]*)|(__.*__)|log|urlpatterns)$ 40 | class-rgx = [A-Z_][a-zA-Z0-9]+$ 41 | function-rgx = ([a-z_][a-z0-9_]{2,40}|test_[a-z0-9_]+)$ 42 | method-rgx = ([a-z_][a-z0-9_]{2,40}|setUp|set[Uu]pClass|tearDown|tear[Dd]ownClass|assert[A-Z]\w*|maxDiff|test_[a-z0-9_]+)$ 43 | attr-rgx = [A-Za-z_][A-Za-z0-9_]{2,30}$ 44 | argument-rgx = [a-z_][a-z0-9_]{2,30}$ 45 | variable-rgx = [a-z_][a-z0-9_]{2,30}$ 46 | class-attribute-rgx = ([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ 47 | inlinevar-rgx = [A-Za-z_][A-Za-z0-9_]*$ 48 | good-names = f,i,j,k,db,ex,Run,_,__ 49 | bad-names = foo,bar,baz,toto,tutu,tata 50 | no-docstring-rgx = __.*__$|test_.+|setUp$|setUpClass$|tearDown$|tearDownClass$|Meta$ 51 | docstring-min-length = -1 52 | 53 | [FORMAT] 54 | max-line-length = 120 55 | ignore-long-lines = ^\s*(# )??$ 56 | single-line-if-stmt = no 57 | no-space-check = trailing-comma,dict-separator 58 | max-module-lines = 1000 59 | indent-string = ' ' 60 | 61 | [MISCELLANEOUS] 62 | notes = FIXME,XXX,TODO 63 | 64 | [SIMILARITIES] 65 | min-similarity-lines = 4 66 | ignore-comments = yes 67 | ignore-docstrings = yes 68 | ignore-imports = no 69 | 70 | [TYPECHECK] 71 | ignore-mixin-members = yes 72 | ignored-classes = SQLObject 73 | unsafe-load-any-extension = yes 74 | generated-members = 75 | REQUEST, 76 | acl_users, 77 | aq_parent, 78 | objects, 79 | DoesNotExist, 80 | can_read, 81 | can_write, 82 | get_url, 83 | size, 84 | content, 85 | status_code, 86 | create, 87 | build, 88 | fields, 89 | tag, 90 | org, 91 | course, 92 | category, 93 | name, 94 | revision, 95 | _meta, 96 | 97 | [VARIABLES] 98 | init-import = no 99 | dummy-variables-rgx = _|dummy|unused|.*_unused 100 | additional-builtins = 101 | 102 | [CLASSES] 103 | defining-attr-methods = __init__,__new__,setUp 104 | valid-classmethod-first-arg = cls 105 | valid-metaclass-classmethod-first-arg = mcs 106 | 107 | [DESIGN] 108 | max-args = 5 109 | ignored-argument-names = _.* 110 | max-locals = 15 111 | max-returns = 6 112 | max-branches = 12 113 | max-statements = 50 114 | max-parents = 7 115 | max-attributes = 7 116 | min-public-methods = 2 117 | max-public-methods = 20 118 | 119 | [IMPORTS] 120 | deprecated-modules = regsub,TERMIOS,Bastion,rexec 121 | import-graph = 122 | ext-import-graph = 123 | int-import-graph = 124 | 125 | [EXCEPTIONS] 126 | overgeneral-exceptions = Exception 127 | 128 | # 1a67033d4799199101eddf63b8ed0bef3e61bda7 129 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## v2.3.1 - 2024-05-15 9 | 10 | ### [2.3.1](https://github.com/eduNEXT/tvm/compare/v2.3.0...v2.3.1) (2024-05-15) 11 | 12 | ### Bug Fixes 13 | 14 | - tvm list command error ([#68](https://github.com/eduNEXT/tvm/issues/68)) ([53e9427](https://github.com/eduNEXT/tvm/commit/53e9427933c32399e4993db7c6298eff6ba5f25b)) 15 | 16 | ## v2.3.0 - 2024-04-11 17 | 18 | ### [2.3.0](https://github.com/eduNEXT/tvm/compare/v2.2.1...v2.3.0) (2024-04-11) 19 | 20 | #### Features 21 | 22 | - add workflow to add items to the Dedalo project DS-831 ([#71](https://github.com/eduNEXT/tvm/issues/71)) ([04e894b](https://github.com/eduNEXT/tvm/commit/04e894b9b29e409f0fab10fb9a07cee10130a627)) 23 | 24 | ## v2.2.1 - 2024-04-11 25 | 26 | ### [2.2.1](https://github.com/eduNEXT/tvm/compare/v2.2.0...v2.2.1) (2024-04-11) 27 | 28 | ### Bug Fixes 29 | 30 | - add build.os to RTD & install proper youtube sphinx dep ([#72](https://github.com/eduNEXT/tvm/issues/72)) ([134ed7f](https://github.com/eduNEXT/tvm/commit/134ed7f808e55fba69e6f4be4b00961ab15942eb)) 31 | 32 | ### Continuous Integration 33 | 34 | - adds mantainer group ([#62](https://github.com/eduNEXT/tvm/issues/62)) ([41b0145](https://github.com/eduNEXT/tvm/commit/41b0145ae561be6f765a5ed2899a4536f7582650)) 35 | - adds pr mantainer group ([#65](https://github.com/eduNEXT/tvm/issues/65)) ([2b5e5b1](https://github.com/eduNEXT/tvm/commit/2b5e5b1e39e262b54f28aa4d939ff75900e4676f)) 36 | 37 | ## v2.2.0 - 2022-12-22 38 | 39 | ### [2.2.0](https://github.com/eduNEXT/tvm/compare/v2.1.1...v2.2.0) (2022-12-22) 40 | 41 | #### Features 42 | 43 | - **DS-322:** add command for remove TVM project ([#60](https://github.com/eduNEXT/tvm/issues/60)) ([12439ff](https://github.com/eduNEXT/tvm/commit/12439ff774c299cbb8793f8e64a5da80b3020dd3)) 44 | 45 | #### Continuous Integration 46 | 47 | - update the changelog updater step in bumpversion ([#61](https://github.com/eduNEXT/tvm/issues/61)) ([c6fb805](https://github.com/eduNEXT/tvm/commit/c6fb805578adc1e322307ac937f4c3850eb1a435)) 48 | 49 | #### Documentation 50 | 51 | - update tvm doc release version to 2.1.1 and fix typo and grammar ([#59](https://github.com/eduNEXT/tvm/issues/59)) ([025f000](https://github.com/eduNEXT/tvm/commit/025f00026a955d6e93dcb3a360b7efe547f0a662)) 52 | 53 | ## v2.1.1 - 2022-10-25 54 | 55 | ### [2.1.1](https://github.com/eduNEXT/tvm/compare/v2.1.0...v2.1.1) (2022-10-25) 56 | 57 | ### Bug Fixes 58 | 59 | - **DS-291:** create a project with a version that is not install ([#58](https://github.com/eduNEXT/tvm/issues/58)) ([8adc08a](https://github.com/eduNEXT/tvm/commit/8adc08a209d9af6dcb3143d4d3f9d0f2808c4b68)) 60 | 61 | ### Documentation 62 | 63 | - **bumpversion:** v2.0.1 → 2.1.0 ([0d6494b](https://github.com/eduNEXT/tvm/commit/0d6494b278bdb7c9fb9965fe7bc6b61c114fefa7)) 64 | - add the base doc configuration ([631048c](https://github.com/eduNEXT/tvm/commit/631048c48bb2abfe71ce4a430f2e13c1564a9f61)) 65 | - add tvm documentation ([09cadc4](https://github.com/eduNEXT/tvm/commit/09cadc4fe01e50ddc4a98c8aba753cab18fbb082)) 66 | - update README with the new template and add links to docs ([#57](https://github.com/eduNEXT/tvm/issues/57)) ([7d880c5](https://github.com/eduNEXT/tvm/commit/7d880c5b91db87df2d3bf6e1d61ef12a9e4033d5)) 67 | 68 | ## v2.1.0 - 2022-09-22 69 | 70 | ### [2.1.0](https://github.com/eduNEXT/tvm/compare/v2.0.1...v2.1.0) (2022-09-22) 71 | 72 | #### Features 73 | 74 | - init command creates new project with global tvm or latest tvm if machine lacks of one ([0136699](https://github.com/eduNEXT/tvm/commit/01366993b88434ed36565bb02464b23e45e8c265)) 75 | 76 | #### Styles 77 | 78 | - solve styling issues ([5f14fe6](https://github.com/eduNEXT/tvm/commit/5f14fe61e5183bfc77ea5e266bcb5aadd5a734e6)) 79 | 80 | #### Code Refactoring 81 | 82 | - fixed logic style ([8d204d1](https://github.com/eduNEXT/tvm/commit/8d204d175c572cd5183362022017dbec9882eccd)) 83 | 84 | #### Documentation 85 | 86 | - correct quickstart command tvm project init ([c2b9545](https://github.com/eduNEXT/tvm/commit/c2b9545ac144b3c65d62a4c8eed06717b93cab38)) 87 | - making the default install the main branch ([7c2ef2a](https://github.com/eduNEXT/tvm/commit/7c2ef2a734a1f6bea4e9a1048115feb4b031265b)) 88 | 89 | ## [2.0.1] - 2022-08-25 90 | 91 | ### Changed 92 | 93 | - Add virtualenv to requirements 94 | 95 | ## [2.0.0] - 2022-08-10 96 | 97 | ### Changed 98 | 99 | - **BREAKING CHANGE:** Migrate environment manager project init command to clean architecture. 100 | - **BREAKING CHANGE:** Migrate version manager commands to clean architecture. 101 | -------------------------------------------------------------------------------- /tvm/environment_manager/infrastructure/environment_manager_git_repository.py: -------------------------------------------------------------------------------- 1 | """Actions to initialize a project.""" 2 | import json 3 | import os 4 | import pathlib 5 | import shutil 6 | import subprocess 7 | from distutils.dir_util import copy_tree # pylint: disable=W0402 8 | from typing import List 9 | 10 | import yaml 11 | 12 | from tvm.environment_manager.domain.environment_manager_repository import EnvironmentManagerRepository 13 | from tvm.environment_manager.domain.project_name import ProjectName 14 | from tvm.share.domain.client_logger_repository import ClientLoggerRepository 15 | from tvm.templates.tvm_activate import TVM_ACTIVATE_SCRIPT 16 | 17 | TVM_PATH = pathlib.Path.home() / ".tvm" 18 | 19 | 20 | class EnvironmentManagerGitRepository(EnvironmentManagerRepository): 21 | """Principals commands to manage TVM.""" 22 | 23 | def __init__(self, project_path: str, logger: ClientLoggerRepository) -> None: 24 | """Initialize usefull variables.""" 25 | self.logger = logger 26 | self.PROJECT_PATH = project_path 27 | self.TVM_ENVIRONMENT = f"{project_path}/.tvm" 28 | 29 | def project_creator(self, project_name: ProjectName) -> None: 30 | """Initialize tutor project.""" 31 | data = { 32 | "version": f"{project_name}", 33 | "tutor_root": f"{self.PROJECT_PATH}", 34 | "tutor_plugins_root": f"{self.PROJECT_PATH}/plugins", 35 | } 36 | 37 | self.create_config_json(data) 38 | self.create_active_script(data) 39 | self.create_project(project_name) 40 | 41 | def project_remover(self, prune: bool) -> None: 42 | """Remove tutor project.""" 43 | with open(f"{TVM_PATH}/{self.PROJECT_PATH}/config.yml", "r", encoding='utf-8') as f: 44 | data = yaml.load(f, Loader=yaml.FullLoader) 45 | 46 | deleted_dirs = [] 47 | for project in data['project_directories']: 48 | if os.path.exists(f"{project}"): 49 | if not prune: 50 | project = f"{project}/.tvm" 51 | deleted_dirs.append(project) 52 | self.remove_project(project) 53 | else: 54 | self.logger.echo(f"Project not found in {project}, if you moved it from the original path, you must remove it manually.\n") # pylint: disable=C0301 55 | 56 | self.remove_project(f"{TVM_PATH}/{self.PROJECT_PATH}") 57 | self.logger.echo(f"\nProject {self.PROJECT_PATH} removed from the following paths:") # pylint: disable=C0301 58 | for project in deleted_dirs: 59 | self.logger.echo(f"\t{project}") 60 | 61 | def remove_project(self, project_path: str): 62 | """Remove project.""" 63 | try: 64 | shutil.rmtree(f"{project_path}") 65 | except PermissionError: 66 | self.logger.echo( 67 | "Don't Worry, TVM just needs sudo permissions to delete your project files." 68 | ) 69 | subprocess.call( 70 | [ 71 | "sudo", 72 | "rm", 73 | "-r", 74 | f"{project_path}", 75 | ] 76 | ) 77 | 78 | def current_version(self) -> ProjectName: 79 | """Project name in current version.""" 80 | info_file_path = f"{self.TVM_ENVIRONMENT}/config.json" 81 | with open(info_file_path, "r", encoding="utf-8") as info_file: 82 | data = json.load(info_file) 83 | return ProjectName(data.get("version")) 84 | 85 | def create_config_json(self, data: dict) -> None: 86 | """Create configuration json file.""" 87 | tvm_project_config_file = f"{self.TVM_ENVIRONMENT}/config.json" 88 | with open(tvm_project_config_file, "w", encoding="utf-8") as info_file: 89 | json.dump(data, info_file, indent=4) 90 | 91 | def create_active_script(self, context: dict) -> None: 92 | """Create active script file.""" 93 | context.update({ 94 | "tvm_path": TVM_PATH 95 | }) 96 | activate_script = f"{self.TVM_ENVIRONMENT}/bin/activate" 97 | with open(activate_script, "w", encoding="utf-8") as activate_file: 98 | activate_file.write(TVM_ACTIVATE_SCRIPT.render(**context)) 99 | 100 | def create_project(self, project_name: ProjectName) -> None: 101 | """Duplicate the version directory and rename it.""" 102 | if not os.path.exists(f"{TVM_PATH}/{project_name}"): 103 | tutor_version = project_name.split("@")[0] 104 | tutor_version_folder = f"{TVM_PATH}/{tutor_version}" 105 | 106 | tvm_project = f"{TVM_PATH}/{project_name}" 107 | copy_tree(tutor_version_folder, tvm_project) 108 | with open(f"{tvm_project}/config.yml", "w", encoding='utf-8') as f: 109 | data = {'project_directories': [f"{self.PROJECT_PATH}"]} 110 | yaml.dump(data, f, default_flow_style=False) 111 | 112 | shutil.rmtree(f"{tvm_project}/venv") 113 | self.setup_version_virtualenv(project_name) 114 | else: 115 | with open(f"{TVM_PATH}/{project_name}/config.yml", "r+", encoding='utf-8') as f: 116 | data = yaml.load(f, Loader=yaml.FullLoader) 117 | data['project_directories'].append(f"{self.PROJECT_PATH}") 118 | f.truncate(0) 119 | f.seek(0) 120 | yaml.dump(data, f, default_flow_style=False) 121 | 122 | @staticmethod 123 | def setup_version_virtualenv(version=None) -> None: 124 | """Create virtualenv and install tutor cloned.""" 125 | # Create virtualenv 126 | subprocess.run( 127 | f"cd {TVM_PATH}/{version}; virtualenv --prompt {version} venv", 128 | shell=True, 129 | check=True, 130 | executable="/bin/bash", 131 | ) 132 | 133 | # Install tutor 134 | subprocess.run( 135 | f"source {TVM_PATH}/{version}/venv/bin/activate;" 136 | f"pip install -e {TVM_PATH}/{version}/overhangio-tutor-*/", 137 | shell=True, 138 | check=True, 139 | executable="/bin/bash", 140 | ) 141 | 142 | def run_command_in_virtualenv(self, options: List, name: ProjectName = None): 143 | """Use virtual environment to run command.""" 144 | if not name: 145 | name = self.current_version() 146 | 147 | try: 148 | subprocess.run( 149 | f"source {TVM_PATH}/{name}/venv/bin/activate;" 150 | f'pip {" ".join(options)}', 151 | # pylint: disable=duplicate-code 152 | shell=True, 153 | check=True, 154 | executable="/bin/bash", 155 | ) 156 | except subprocess.CalledProcessError as ex: 157 | raise Exception(f"Error running venv commands: {ex.output}") from ex 158 | 159 | def install_plugin(self, options: List) -> None: 160 | """Install a tutor version.""" 161 | self.run_command_in_virtualenv(options=options) 162 | 163 | def uninstall_plugin(self, options: List) -> None: 164 | """Uninstall a tutor version.""" 165 | self.run_command_in_virtualenv(options=options) 166 | -------------------------------------------------------------------------------- /docs/source/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap'); 2 | 3 | 4 | body { 5 | padding-top: 0!important; 6 | font-family: "Poppins", sans-serif; 7 | width: 112% !important; 8 | } 9 | 10 | #site-navigation div.bd-sidebar__top { 11 | padding-left: inherit; 12 | } 13 | 14 | nav#bd-docs-nav { 15 | padding-left: 10px; 16 | } 17 | 18 | .card.w-100.shadow.img-panel1.img-panels.card-hidde.docutils { 19 | display: none; 20 | } 21 | 22 | div.card { 23 | /* width: 25.188rem !important; 24 | box-shadow: none !important; */ 25 | 26 | position: relative; 27 | overflow: hidden; 28 | display: flex; 29 | 30 | width: 300px; 31 | height: 371px; 32 | align-content: stretch; 33 | justify-content: center; 34 | align-items: stretch; 35 | 36 | } 37 | 38 | nav.bd-links p.caption { 39 | text-transform: uppercase; 40 | font-weight: 700; 41 | position: relative; 42 | margin-top: 1.25em; 43 | margin-bottom: 0.5em; 44 | } 45 | 46 | div.img-panels { 47 | background-repeat: no-repeat; 48 | background-position: center center; 49 | background-size: cover; 50 | } 51 | 52 | div.img-backoffice { 53 | background-image: url("../../_static/_assets/internal_img/Backoffice_process.png"); 54 | } 55 | 56 | 57 | div.img-legal { 58 | background-image: url("../../_static/_assets/internal_img/panel_legal.png"); 59 | } 60 | 61 | 62 | div.img-bussines { 63 | background-image: url("../../_static/_assets/internal_img/Business_process.png"); 64 | } 65 | 66 | div.img-atlas { 67 | background-image: url("../../_static/_assets/internal_img/Atlas_team.png"); 68 | 69 | } 70 | 71 | div.img-dedalo { 72 | background-image: url("../../_static/_assets/internal_img/Dedalo_process.png"); 73 | } 74 | 75 | div.img-distro { 76 | background-image: url("../../_static/_assets/internal_img/distro_process.png"); 77 | } 78 | 79 | div.img-ECC { 80 | background-image: url("../../_static/_assets/internal_img/ECC_product.png"); 81 | } 82 | 83 | div.img-eox_core { 84 | background-image: url("../../_static/_assets/internal_img/eox-core.png"); 85 | } 86 | 87 | div.img-eox_core_product { 88 | background-image: url("../../_static/_assets/internal_img/eox-core_product.png"); 89 | } 90 | 91 | div.img-eox_support_product { 92 | background-image: url("../../_static/_assets/internal_img/eox-support_product.png"); 93 | } 94 | 95 | div.img-eox_support_product_features { 96 | background-image: url("../../_static/_assets/internal_img/eox-support_product_features.png"); 97 | } 98 | 99 | div.img-eox_tenatn_product { 100 | background-image: url("../../_static/_assets/internal_img/eox-tenatn_product.png"); 101 | } 102 | 103 | div.img-eox_theming_product { 104 | background-image: url("../../_static/_assets/internal_img/exo-theming_product.png"); 105 | } 106 | 107 | div.img-general_documentation_process { 108 | background-image: url("../../_static/_assets/internal_img/general_documentation_process.png"); 109 | } 110 | 111 | div.img-general_documentation_process_knowledge { 112 | background-image: url("../../_static/_assets/internal_img/general_documentation_process_knowledge.png"); 113 | } 114 | 115 | div.img-infosecurity_process { 116 | background-image: url("../../_static/_assets/internal_img/Infosecurity_process.png"); 117 | } 118 | 119 | div.img-data_privacy { 120 | background-image: url("../../_static/_assets/internal_img/Data_privacy_process.png"); 121 | } 122 | 123 | div.img-MandS_team { 124 | background-image: url("../../_static/_assets/internal_img/MandS_team.png"); 125 | } 126 | 127 | div.img-Marketing_process { 128 | background-image: url("../../_static/_assets/internal_img/Marketing_process.png"); 129 | } 130 | 131 | div.img-pearson { 132 | background-image: url("../../_static/_assets/internal_img/Pearson_team.png"); 133 | } 134 | 135 | div.img-proversity { 136 | background-image: url("../../_static/_assets/internal_img/Proversity_team.png"); 137 | } 138 | 139 | div.img-saas { 140 | background-image: url("../../_static/_assets/internal_img/SaaS_team.png"); 141 | } 142 | 143 | 144 | div.img-sales_process { 145 | background-image: url("../../_static/_assets/internal_img/Sales_process.png"); 146 | } 147 | 148 | div.img-sd_process { 149 | background-image: url("../../_static/_assets/internal_img/SD_Process.png"); 150 | } 151 | 152 | div.img-shipyard_process { 153 | background-image: url("../../_static/_assets/internal_img/shipyard_process.png"); 154 | } 155 | 156 | div.img-talent_HR { 157 | background-image: url("../../_static/_assets/internal_img/TalentHR_team.png"); 158 | } 159 | 160 | div.img-tecnology_process { 161 | background-image: url("../../_static/_assets/internal_img/Technology_process.png"); 162 | } 163 | 164 | 165 | /*img.card-img-top {*/ 166 | /* position: absolute;*/ 167 | /* top: 0;*/ 168 | /* max-width: 100%;*/ 169 | /* height: auto;*/ 170 | /* !* display:none; *!*/ 171 | /*}*/ 172 | 173 | /*div.card:hover img.card-img-top {*/ 174 | /* display: block;*/ 175 | /* background-repeat: no-repeat;*/ 176 | /* background-position: center center;*/ 177 | /* background-size: cover;*/ 178 | /* !* opacity: 0.3; *!*/ 179 | /*}*/ 180 | 181 | /* div.card-body { 182 | z-index: 9999; 183 | display: flex; 184 | flex-wrap: wrap; 185 | flex-direction: column; 186 | justify-content: space-around; 187 | font-size: 18px; 188 | }*/ 189 | 190 | /*div.card-body { 191 | z-index: 9999; 192 | display: flex; 193 | flex-wrap: wrap; 194 | flex-direction: column; 195 | font-size: 18px; 196 | justify-content: flex-end; 197 | }*/ 198 | 199 | 200 | 201 | div.card-body { 202 | z-index: 9999; 203 | display: flex; 204 | flex-direction: column; 205 | font-size: 18px; 206 | justify-content: space-between; 207 | flex-wrap: wrap; 208 | } 209 | 210 | /*div.toctree-wrapper.compound { 211 | padding-bottom: 108px; 212 | }*/ 213 | .toctree-wrapper.compound { 214 | padding-top: inherit; 215 | } 216 | 217 | div.toctree-wrapper p.caption { 218 | font-weight: 900; 219 | font-size: 1.2em; 220 | /*display: none;*/ 221 | visibility: hidden; 222 | } 223 | 224 | div.toctree-wrapper li { 225 | font-weight: 400; 226 | text-decoration: none; 227 | } 228 | 229 | div.toctree-wrapper li a { 230 | font-weight: 400; 231 | color: rgb(0, 0, 0) !important; 232 | text-decoration: none; 233 | font-size: 17px; 234 | line-height: 28px; 235 | --head-indent: 1.7; 236 | } 237 | div.toctree-wrapper>ul { 238 | padding-left: 1.5em; 239 | /*height: 170px;*/ 240 | } 241 | 242 | /* This fixes the text alignment style, only for the Arabic language*/ 243 | html[lang="ar"] body, 244 | html[lang="ar"] #site-navigation div.navbar_extra_footer { 245 | text-align: inherit; 246 | } 247 | 248 | 249 | /* Button styles */ 250 | 251 | .button-modify { 252 | border: 2px solid black; 253 | /* background-color: #05093b !important; */ 254 | /* padding: 14px 28px; */ 255 | /* font-size: 16px; */ 256 | /* cursor: pointer; */ 257 | color: #05093b !important; 258 | } 259 | 260 | /* Gray */ 261 | .default { 262 | border-color: black; 263 | color: black; 264 | } 265 | 266 | .default:hover { 267 | background: gray !important; 268 | } 269 | 270 | 271 | /* Lateral nav styles */ 272 | 273 | /*nav.bd-links {*/ 274 | /* background: #efefef;*/ 275 | /*}*/ 276 | 277 | a.reference[href="#"]{ 278 | font-weight: 700; 279 | } 280 | a.reference[href="../index.html"]{ 281 | font-weight: 700; 282 | } 283 | a.reference[href="../../index.html"]{ 284 | font-weight: 700; 285 | } 286 | 287 | .sidebar p { 288 | text-align: center; 289 | } 290 | 291 | p.sidebar-title { 292 | font-size: 1em !important; 293 | } 294 | 295 | .sidebar a img { 296 | display: block; 297 | margin-left: auto; 298 | margin-right: auto; 299 | margin-top: 10px; 300 | } 301 | 302 | div.sidebar:not(.margin) { 303 | width: 35%; 304 | margin-left: 1.5em; 305 | margin-right: -38%; 306 | border-top-color: rgb(164, 166, 167); 307 | } 308 | 309 | 310 | 311 | .section .arabic li { 312 | 313 | margin-bottom: 1.2em; 314 | } 315 | 316 | 317 | .section .arabic li p { 318 | 319 | margin-top: 1.2em; 320 | } 321 | 322 | 323 | a.external:after{ 324 | 325 | font-family: 'FontAwesome'; 326 | content: " \f08e"; 327 | } 328 | 329 | 330 | li ol.arabic { 331 | list-style-type: lower-alpha; 332 | } 333 | 334 | 335 | .sidebar a:after{ 336 | font-family: 'FontAwesome'; 337 | content: " \f002"; 338 | text-align: right; 339 | } 340 | 341 | 342 | #site-navigation div.navbar_extra_footer { 343 | text-align: left; 344 | } 345 | 346 | div.contents p.topic-title { 347 | 348 | margin-bottom: 20px; 349 | } 350 | 351 | 352 | div.contents ul li p a { 353 | font-size: 1em; 354 | } 355 | 356 | div.contents ul li p a:after { 357 | font-weight: 200; 358 | font-size: 0.8em; 359 | font-family: 'FontAwesome'; 360 | content: " \f061"; 361 | 362 | } 363 | 364 | div.contents ul li { 365 | margin-bottom: 0.6em; 366 | } 367 | 368 | 369 | 370 | .contents { 371 | width: 100%; 372 | } 373 | 374 | .no-bullets ul { 375 | list-style-type: none; 376 | } 377 | 378 | 379 | #site-navigation .bd-sidebar__bottom { 380 | margin-bottom: 1em; 381 | } 382 | 383 | 384 | p.feedback a.reference .std-ref{ 385 | border: 1px solid #7fbbe3; 386 | background: #e7f2fa; 387 | font-size: 80%; 388 | font-weight: 700; 389 | border-radius: 4px; 390 | padding: 2.4px 6px; 391 | margin: auto 2px; 392 | } 393 | 394 | details summary { 395 | font-weight: 700; 396 | margin-bottom: 0.6em; 397 | } -------------------------------------------------------------------------------- /tvm/version_manager/infrastructure/version_manager_git_repository.py: -------------------------------------------------------------------------------- 1 | """Actions to get tutor versions.""" 2 | import json 3 | import os 4 | import pathlib 5 | import shutil 6 | import stat 7 | import subprocess 8 | import zipfile 9 | from typing import List, Optional 10 | 11 | import requests 12 | from packaging.version import parse 13 | 14 | from tvm.share.domain.client_logger_repository import ClientLoggerRepository 15 | from tvm.version_manager.domain.tutor_version import TutorVersion 16 | from tvm.version_manager.domain.tutor_version_is_not_installed import TutorVersionIsNotInstalled 17 | from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository 18 | from tvm.version_manager.templates.tutor_switcher import TUTOR_SWITCHER_TEMPLATE 19 | 20 | 21 | class VersionManagerGitRepository(VersionManagerRepository): 22 | """Principals commands to manage TVM.""" 23 | 24 | VERSIONS_URL = "https://api.github.com/repos/overhangio/tutor/tags" 25 | GET_TAG_URL = "https://api.github.com/repos/overhangio/tutor/git/ref/tags/" 26 | ZIPPBALL_URL = "https://api.github.com/repos/overhangio/tutor/zipball/refs/tags/" 27 | TVM_PATH = pathlib.Path.home() / ".tvm" 28 | 29 | def __init__(self, logger: ClientLoggerRepository) -> None: 30 | """init.""" 31 | self.logger = logger 32 | self.setup() 33 | 34 | def setup(self): 35 | """Set data.""" 36 | try: 37 | os.mkdir(self.TVM_PATH) 38 | except FileExistsError: 39 | pass 40 | 41 | data = { 42 | "version": None, 43 | "tutor_root": None, 44 | "tutor_plugins_root": None, 45 | } 46 | 47 | self.set_current_info(data=data, update=False) 48 | self.set_switcher() 49 | 50 | try: 51 | os.symlink(f"{self.TVM_PATH}/tutor_switcher", "/usr/local/bin/tutor") 52 | except PermissionError: 53 | self.logger.echo( 54 | "Don't Worry, TVM just needs sudo permissions to create the tutor_switcher's symlink" 55 | "in /usr/local/bin/tutor.\n" 56 | "You can find more information about it in our docs." 57 | ) 58 | subprocess.call( 59 | [ 60 | "sudo", 61 | "ln", 62 | "-s", 63 | f"{self.TVM_PATH}/tutor_switcher", 64 | "/usr/local/bin/tutor", 65 | ] 66 | ) 67 | except FileExistsError: 68 | pass 69 | 70 | def set_current_info(self, data: dict, update: bool = True) -> None: 71 | """Set current information.""" 72 | try: 73 | info_file_path = f"{self.TVM_PATH}/current_bin.json" 74 | if os.path.exists(info_file_path) and not update: 75 | raise FileExistsError 76 | 77 | with open(info_file_path, "w", encoding="utf-8") as info_file: 78 | json.dump(data, info_file, indent=4) 79 | except FileExistsError: 80 | pass 81 | 82 | def get_current_info(self) -> dict: 83 | """Get current information data from the json.""" 84 | info_file_path = f"{self.TVM_PATH}/current_bin.json" 85 | with open(info_file_path, "r", encoding="utf-8") as info_file: 86 | data = json.load(info_file) 87 | return data 88 | 89 | def set_switcher(self) -> None: 90 | """Set the active version from the json into the switcher.""" 91 | data = self.get_current_info() 92 | 93 | context = { 94 | "version": data.get("version", None), 95 | "tutor_root": data.get("tutor_root", None), 96 | "tutor_plugins_root": data.get("tutor_plugins_root", None), 97 | "tvm": f"{self.TVM_PATH}", 98 | } 99 | 100 | switcher_file = f"{self.TVM_PATH}/tutor_switcher" 101 | with open(switcher_file, mode="w", encoding="utf-8") as of_text: 102 | of_text.write(TUTOR_SWITCHER_TEMPLATE.render(**context)) 103 | 104 | # set execute permissions 105 | os.chmod( 106 | switcher_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH 107 | ) 108 | 109 | def get_version_from_api(self, limit: int = 100): 110 | """Return api information form request.""" 111 | api_info = requests.get(f"{self.VERSIONS_URL}?per_page={limit}").json() 112 | return api_info 113 | 114 | def list_versions(self, limit: int) -> List[TutorVersion]: 115 | """List tutor version from API.""" 116 | api_info = self.get_version_from_api(limit=limit) 117 | return [TutorVersion(x.get("name")) for x in api_info] 118 | 119 | @staticmethod 120 | def local_versions(tvm_path: str) -> List[TutorVersion]: 121 | """Return a list of strings with the local version installed. If None, returns empty array.""" 122 | if os.path.exists(f"{tvm_path}"): 123 | return [ 124 | x for x in os.listdir(f"{tvm_path}") if os.path.isdir(f"{tvm_path}/{x}") 125 | ] 126 | return [] 127 | 128 | @staticmethod 129 | def current_version(tvm_path: str) -> Optional[TutorVersion]: 130 | """Read the current active version from the json/bash switcher.""" 131 | info_file_path = f"{tvm_path}/current_bin.json" 132 | if not os.path.exists(info_file_path): 133 | return None 134 | 135 | with open(info_file_path, "r", encoding="utf-8") as info_file: 136 | data = json.load(info_file) 137 | return TutorVersion(data.get("version")) if data.get("version") else None 138 | 139 | def install_version(self, version: TutorVersion) -> None: 140 | """Install version for a tutor version.""" 141 | # Get the code in zip format 142 | filename = f"{self.TVM_PATH}/{version}.zip" 143 | file_url = f"{self.ZIPPBALL_URL}{version}" 144 | stream = requests.get(file_url, stream=True) 145 | with open(filename, "wb") as target_file: 146 | for chunk in stream.iter_content(chunk_size=256): 147 | target_file.write(chunk) 148 | 149 | # Unzip it 150 | with zipfile.ZipFile(filename, "r") as ziped: 151 | ziped.extractall(f"{self.TVM_PATH}/{version}") 152 | 153 | # Delete artifact 154 | os.remove(filename) 155 | 156 | self.create_virtualenv(version) 157 | self.install_tutor(version) 158 | 159 | def find_version(self, version: TutorVersion) -> Optional[TutorVersion]: 160 | """Find version for requests.""" 161 | response = requests.get(f"{self.GET_TAG_URL}{version}") 162 | if response.status_code == 404: 163 | return None 164 | 165 | return TutorVersion(version) 166 | 167 | def create_virtualenv(self, version: TutorVersion) -> None: 168 | """Create a virtual environment.""" 169 | subprocess.run( 170 | f"cd {self.TVM_PATH}/{version}; virtualenv --prompt {version} venv", 171 | shell=True, 172 | check=True, 173 | executable="/bin/bash", 174 | ) 175 | 176 | def run_command_in_virtualenv(self, options: List, version: TutorVersion = None): 177 | """Use virtual environment to run command.""" 178 | if not version: 179 | version = self.current_version(self.TVM_PATH) 180 | 181 | try: 182 | subprocess.run( 183 | f"source {self.TVM_PATH}/{version}/venv/bin/activate;" f'pip {" ".join(options)}', 184 | # pylint: disable=duplicate-code 185 | shell=True, 186 | check=True, 187 | executable="/bin/bash", 188 | ) 189 | except subprocess.CalledProcessError as ex: 190 | raise Exception(f"Error running venv commands: {ex.output}") from ex 191 | 192 | def install_plugin(self, options: List, version: TutorVersion = None) -> None: 193 | """Install plugin for virtual environment.""" 194 | self.run_command_in_virtualenv(options) 195 | 196 | def uninstall_plugin(self, options: List, version: TutorVersion = None) -> None: 197 | """Uninstall plugin for virtual environment.""" 198 | self.run_command_in_virtualenv(options) 199 | 200 | def install_tutor(self, version: TutorVersion) -> None: 201 | """Install a tutor version.""" 202 | subprocess.run( 203 | f"source {self.TVM_PATH}/{version}/venv/bin/activate;" 204 | f"pip install -e {self.TVM_PATH}/{version}/overhangio-tutor-*/", 205 | shell=True, 206 | check=True, 207 | executable="/bin/bash", 208 | ) 209 | 210 | def uninstall_version(self, version: TutorVersion) -> None: 211 | """Uninstall a tutor version.""" 212 | try: 213 | shutil.rmtree(f"{self.TVM_PATH}/{version}") 214 | except FileNotFoundError as v_not_exist: 215 | raise TutorVersionIsNotInstalled( 216 | f"The version {version} is not installed" 217 | ) from v_not_exist 218 | 219 | def use_version(self, version: TutorVersion) -> None: 220 | """Use a tutor version selected.""" 221 | data = self.get_current_info() 222 | 223 | data.update({"version": version}) 224 | 225 | self.set_current_info(data=data) 226 | self.set_switcher() 227 | 228 | def __valid_version_comparer(self, version_name: str): 229 | """ 230 | Turn version name to a valid version object. 231 | 232 | Uses '+' symbol to define local version labels instead "@" 233 | https://peps.python.org/pep-0440/#local-version-identifiers 234 | """ 235 | valid_version_name = version_name.replace("@", "+") 236 | return parse(valid_version_name) 237 | 238 | def sort_tutor_versions(self, versions: List[TutorVersion]): 239 | """Sort tutor versions in ascending order.""" 240 | return sorted(versions, reverse=False, key=self.__valid_version_comparer) 241 | 242 | @staticmethod 243 | def version_is_installed(version: str) -> bool: 244 | """Validate if tutor version is installed.""" 245 | version = TutorVersion(version) 246 | if not os.path.exists(f"{VersionManagerGitRepository.TVM_PATH}/{version}"): 247 | return False 248 | return True 249 | -------------------------------------------------------------------------------- /tvm/cli.py: -------------------------------------------------------------------------------- 1 | """Entry point for all the `tvm *` commands.""" 2 | import json 3 | import os 4 | import pathlib 5 | import re 6 | import stat 7 | import subprocess 8 | import sys 9 | from typing import Optional 10 | 11 | import click 12 | import yaml 13 | from click.shell_completion import CompletionItem 14 | 15 | from tvm import __version__ 16 | from tvm.environment_manager.application.plugin_installer import PluginInstaller 17 | from tvm.environment_manager.application.plugin_uninstaller import PluginUninstaller 18 | from tvm.environment_manager.application.tutor_project_creator import TutorProjectCreator 19 | from tvm.environment_manager.application.tutor_project_remover import TutorProjectRemover 20 | from tvm.environment_manager.domain.project_name import ProjectName 21 | from tvm.settings import environment_manager, version_manager 22 | from tvm.templates.tutor_switcher import TUTOR_SWITCHER_TEMPLATE 23 | from tvm.version_manager.application.tutor_plugin_installer import TutorPluginInstaller 24 | from tvm.version_manager.application.tutor_plugin_uninstaller import TutorPluginUninstaller 25 | from tvm.version_manager.application.tutor_version_enabler import TutorVersionEnabler 26 | from tvm.version_manager.application.tutor_version_finder import TutorVersionFinder 27 | from tvm.version_manager.application.tutor_version_installer import TutorVersionInstaller 28 | from tvm.version_manager.application.tutor_version_uninstaller import TutorVersionUninstaller 29 | from tvm.version_manager.application.tutor_vesion_lister import TutorVersionLister 30 | from tvm.version_manager.domain.tutor_version_format_error import TutorVersionFormatError 31 | from tvm.version_manager.domain.tutor_version_is_not_installed import TutorVersionIsNotInstalled 32 | 33 | VERSIONS_URL = "https://api.github.com/repos/overhangio/tutor/tags" 34 | TVM_PATH = pathlib.Path.home() / '.tvm' 35 | 36 | 37 | def main() -> None: 38 | """Hold all the commands in a group.""" 39 | cli() 40 | 41 | 42 | @click.group( 43 | name="tvm", 44 | short_help="Tutor Version Manager", 45 | context_settings={"help_option_names": ["--help", "-h", "help"]} 46 | ) 47 | @click.version_option(version=__version__) 48 | def cli() -> None: 49 | """Define the main `tvm` group.""" 50 | 51 | 52 | class TutorVersionType(click.ParamType): 53 | """Provide autocomplete functionability for tutor versions.""" 54 | 55 | def shell_complete(self, ctx, param, incomplete): 56 | """Provide autocomplete for shell.""" 57 | return [ 58 | CompletionItem(name) 59 | for name in get_local_versions() if name.startswith(incomplete) 60 | ] 61 | 62 | 63 | def version_is_valid(value): 64 | """Raise BadParameter if the value is not a tutor version.""" 65 | result = re.match(r'^v([0-9]+)\.([0-9]+)\.([0-9]+)$', value) 66 | if not result: 67 | raise click.BadParameter("format must be 'vX.Y.Z'") 68 | 69 | return value 70 | 71 | 72 | def validate_version(ctx, param, value): # pylint: disable=unused-argument 73 | """Raise BadParameter if the value is not a tutor version.""" 74 | return version_is_valid(value) 75 | 76 | 77 | def get_local_versions(): 78 | """Return a list of strings with the local version installed. If None, returns empty array.""" 79 | if os.path.exists(f'{TVM_PATH}'): 80 | return [x for x in os.listdir(f'{TVM_PATH}') if os.path.isdir(f'{TVM_PATH}/{x}')] 81 | return [] 82 | 83 | 84 | def version_is_installed(value) -> bool: 85 | """Return false if the value is not installed.""" 86 | version_is_valid(value) 87 | local_versions = get_local_versions() 88 | return value in local_versions 89 | 90 | 91 | def validate_version_installed(ctx, param, value): # pylint: disable=unused-argument 92 | """Raise BadParameter if the value is not a tutor version.""" 93 | is_installed = version_is_installed(value) 94 | if not is_installed: 95 | raise click.BadParameter("You must install the version before using it.\n\n" 96 | "Use `tvm list` for available versions.") 97 | return value 98 | 99 | 100 | def setup_tvm(): 101 | """ 102 | Initialize the directory for all tutor versions. 103 | 104 | Can be called at any time, since it should not damage anything. 105 | """ 106 | try: 107 | os.mkdir(TVM_PATH) 108 | except FileExistsError: 109 | pass 110 | 111 | info_file_path = f'{TVM_PATH}/current_bin.json' 112 | if not os.path.exists(info_file_path): 113 | data = { 114 | "version": None, 115 | "tutor_root": None, 116 | "tutor_plugins_root": None, 117 | } 118 | with open(info_file_path, 'w', encoding='utf-8') as info_file: 119 | json.dump(data, info_file, indent=4) 120 | 121 | set_switch_from_file(file=info_file_path) 122 | 123 | tutor_switcher = f'{TVM_PATH}/tutor_switcher' 124 | try: 125 | os.symlink(tutor_switcher, '/usr/local/bin/tutor') 126 | except PermissionError: 127 | subprocess.call(['sudo', 'ln', '-s', tutor_switcher, '/usr/local/bin/tutor']) 128 | except FileExistsError: 129 | pass 130 | 131 | 132 | @click.command(name="list") 133 | @click.option("-l", "--limit", default=100, help="number of `latest versions` to list") 134 | def list_versions(limit: int): 135 | """ 136 | Get all the versions from github. 137 | 138 | Print and mark the both the installed ones and the current. 139 | """ 140 | lister = TutorVersionLister(repository=version_manager) 141 | version_names = lister(limit=limit) 142 | local_versions = version_manager.local_versions(f"{TVM_PATH}") 143 | version_names = list(set(version_names + local_versions)) 144 | version_names = version_manager.sort_tutor_versions(version_names) 145 | global_active = version_manager.current_version(f"{TVM_PATH}") 146 | project_version = None 147 | 148 | if "TVM_PROJECT_ENV" in os.environ: 149 | repository = environment_manager(project_path=os.environ.get("TVM_PROJECT_ENV")) 150 | project_version = repository.current_version() 151 | for name in version_names: 152 | color = "white" 153 | if name in local_versions: 154 | color = "green" 155 | if name == global_active and not project_version: 156 | name = f"{name} (active)" 157 | if project_version and project_version == name: 158 | name = f"{name} (active)" 159 | click.echo(click.style(name, fg=color)) 160 | 161 | 162 | def install_tutor_version(version: str) -> None: 163 | """Install the given VERSION of tutor in the .tvm directory.""" 164 | finder = TutorVersionFinder(repository=version_manager) 165 | tutor_version = finder(version=version) 166 | try: 167 | if not tutor_version: 168 | raise Exception 169 | except TutorVersionFormatError as format_err: 170 | raise click.UsageError(f'{format_err}') 171 | except Exception as err: 172 | raise click.UsageError(f'Could not find target: {version}') from err 173 | 174 | installer = TutorVersionInstaller(repository=version_manager) 175 | installer(version=tutor_version) 176 | 177 | 178 | @click.command(name="install") 179 | @click.argument('version', required=True) 180 | def install(version: str): 181 | """Install the given VERSION of tutor in the .tvm directory.""" 182 | install_tutor_version(version=version) 183 | 184 | 185 | @click.command(name="uninstall") 186 | @click.argument('version', required=True) 187 | def uninstall(version: str): 188 | """Uninstall the given VERSION of tutor in the .tvm directory.""" 189 | uninstaller = TutorVersionUninstaller(repository=version_manager) 190 | try: 191 | uninstaller(version=version) 192 | click.echo(click.style( 193 | f"The {version} has been uninstalled.", 194 | fg='green', 195 | )) 196 | except TutorVersionFormatError as format_err: 197 | raise click.UsageError(f'{format_err}') 198 | except TutorVersionIsNotInstalled as not_installed_err: 199 | raise click.exceptions.ClickException(f"{not_installed_err}") 200 | 201 | 202 | def get_active_version() -> str: 203 | """Read the current active version from the json/bash switcher.""" 204 | info_file_path = f'{TVM_PATH}/current_bin.json' 205 | if os.path.exists(info_file_path): 206 | with open(info_file_path, 'r', encoding='utf-8') as info_file: 207 | data = json.load(info_file) 208 | return data.get('version', 'Invalid active version') 209 | return 'No active version installed' 210 | 211 | 212 | def get_current_info(file: str = None) -> Optional[dict]: 213 | """Get the JSON data from the config file.""" 214 | if not file: 215 | if "TVM_PROJECT_ENV" in os.environ: 216 | project = os.environ.get("TVM_PROJECT_ENV") 217 | file = f"{project}/config.json" 218 | else: 219 | file = f'{TVM_PATH}/current_bin.json' 220 | 221 | data = None 222 | if os.path.exists(file): 223 | with open(file, 'r', encoding='utf-8') as info_file: 224 | data = json.load(info_file) 225 | return data 226 | 227 | 228 | def put_current_info(data: dict, file: str = None) -> None: 229 | """Update JSON data in the config file.""" 230 | if not file: 231 | if "TVM_PROJECT_ENV" in os.environ: 232 | project = os.environ.get("TVM_PROJECT_ENV") 233 | file = f"{project}/config.json" 234 | else: 235 | file = f'{TVM_PATH}/current_bin.json' 236 | 237 | if os.path.exists(file): 238 | with open(file, 'w', encoding='utf-8') as info_file: 239 | json.dump(data, info_file, indent=4) 240 | 241 | 242 | def set_active_version(version) -> None: 243 | """Set the active version in the json to VERSION.""" 244 | info_file_path = f'{TVM_PATH}/current_bin.json' 245 | 246 | data = get_current_info(file=info_file_path) 247 | data['version'] = version 248 | 249 | put_current_info(data=data, file=info_file_path) 250 | 251 | 252 | def set_switch_from_file(file: str = None) -> None: 253 | """Set the active version from the json into the switcher.""" 254 | data = get_current_info(file=file) 255 | 256 | context = { 257 | 'version': data.get('version', None), 258 | 'tutor_root': data.get('tutor_root', None), 259 | 'tutor_plugins_root': data.get('tutor_plugins_root', None), 260 | 'tvm': TVM_PATH, 261 | } 262 | 263 | switcher_file = f'{TVM_PATH}/tutor_switcher' 264 | with open(switcher_file, mode='w', encoding='utf-8') as of_text: 265 | of_text.write(TUTOR_SWITCHER_TEMPLATE.render(**context)) 266 | 267 | # set execute permissions 268 | os.chmod(switcher_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH) 269 | 270 | 271 | def use_version(version: str) -> None: 272 | """Configure the path to use VERSION.""" 273 | enabler = TutorVersionEnabler(repository=version_manager) 274 | try: 275 | if not version_manager.version_is_installed(version=version): 276 | raise Exception 277 | enabler(version=version) 278 | except TutorVersionFormatError as format_err: 279 | raise click.UsageError(f"{format_err}") 280 | except Exception as exc: 281 | raise click.ClickException(f'The version {version} is not installed you should install it before using it.\n' 282 | f'You could run the command `tvm install {version}` to install it.') from exc 283 | 284 | 285 | @click.command(name="use") 286 | @click.argument('version', required=True) 287 | def use(version: str): 288 | """Configure the path to use VERSION.""" 289 | use_version(version=version) 290 | 291 | 292 | def get_env_by_tutor_version(version): 293 | """Get virtual environment by tutor version.""" 294 | return f'{TVM_PATH}/{version}/venv' 295 | 296 | 297 | def run_on_tutor_switcher(options, capture_output=True): 298 | """Run commands through the current tutor + config file.""" 299 | options = " ".join(options) 300 | result = subprocess.run(f'{TVM_PATH}/tutor_switcher {options}', 301 | shell=True, check=True, 302 | executable='/bin/bash', 303 | capture_output=capture_output) 304 | return result.stdout 305 | 306 | 307 | def run_on_tutor_venv(cmd, options, version=None): 308 | """Run commands on the virtualenv where this tutor is installed.""" 309 | if not version: 310 | version = get_active_version() 311 | target_venv = get_env_by_tutor_version(version) 312 | options = " ".join(options) 313 | try: 314 | result = subprocess.run(f'source {target_venv}/bin/activate &&' 315 | f'{cmd} {options} && deactivate', 316 | shell=True, check=True, 317 | executable='/bin/bash', 318 | stdout=subprocess.PIPE, 319 | stderr=subprocess.STDOUT) 320 | return result.stdout 321 | except subprocess.CalledProcessError as ex: 322 | click.echo(click.style( 323 | f'Error running venv commands: {ex.output}', 324 | fg='red', 325 | )) 326 | click.echo(ex) 327 | sys.exit(1) 328 | 329 | 330 | @click.group(name="plugins") 331 | def plugins() -> None: 332 | """Use plugins commands.""" 333 | 334 | 335 | @click.command(name="list") 336 | def list_plugins(): 337 | """List installed plugins by tutor version.""" 338 | project_version = None 339 | if "TVM_PROJECT_ENV" in os.environ: 340 | repository = environment_manager(project_path=os.environ.get("TVM_PROJECT_ENV")) 341 | project_version = repository.current_version() 342 | 343 | global_active = get_active_version() 344 | 345 | local_versions = get_local_versions() 346 | for version in local_versions: 347 | version = str(version) 348 | 349 | if version == global_active and not project_version: 350 | click.echo(click.style(f"{version} (active)", fg='green')) 351 | elif project_version and version == project_version: 352 | click.echo(click.style(f"{version} (active)", fg='green')) 353 | else: 354 | click.echo(click.style(version, fg='green')) 355 | 356 | click.echo(run_on_tutor_venv('tutor', ['plugins', 'list'], version=version)) 357 | 358 | click.echo('Note: the disabled notice depends on the active tutor configuration.') 359 | 360 | 361 | @click.group( 362 | name="project", 363 | short_help="Tutor Environment Manager", 364 | context_settings={"help_option_names": ["--help", "-h", "help"]} 365 | ) 366 | @click.version_option(version=__version__) 367 | def projects() -> None: 368 | """Hold the main wrapper for the `tvm project` command.""" 369 | 370 | 371 | @click.command(name="init") 372 | @click.argument('name', required=False) 373 | @click.argument('version', required=False) 374 | def init(name: str = None, version: str = None): 375 | """Configure a new tvm project in the current path.""" 376 | current_version = version_manager.current_version(f"{TVM_PATH}") 377 | local_versions = get_local_versions() 378 | 379 | if not version: 380 | version = current_version 381 | 382 | if not current_version and not version: 383 | lister = TutorVersionLister(repository=version_manager) 384 | version = lister(limit=1)[0] 385 | 386 | if not current_version: 387 | install_tutor_version(version=version) 388 | use_version(version=version) 389 | 390 | if version not in local_versions: 391 | install_tutor_version(version=version) 392 | use_version(version=version) 393 | 394 | if name: 395 | tvm_project_folder = pathlib.Path().resolve() / name 396 | else: 397 | name = f"{pathlib.Path().resolve()}".split("/")[-1] 398 | tvm_project_folder = pathlib.Path().resolve() 399 | 400 | version = f"{version}@{name}" 401 | tvm_environment = tvm_project_folder / '.tvm' 402 | 403 | if not os.path.exists(tvm_environment): 404 | pathlib.Path(f"{tvm_environment}/bin").mkdir(parents=True, exist_ok=True) 405 | 406 | repository = environment_manager(project_path=f"{tvm_project_folder}") 407 | initialize = TutorProjectCreator(repository=repository) 408 | initialize(version) 409 | else: 410 | raise click.UsageError('There is already a project initiated.') from IndexError 411 | 412 | 413 | @click.command(name="remove") 414 | @click.argument('project-name', required=True) 415 | @click.option('--prune', is_flag=True, help="Remove all files in project folder.") 416 | def remove(project_name: ProjectName, prune: bool): 417 | """Remove TVM project. 418 | 419 | PROJECT-NAME: {VERSION}@{NAME} E.g. v1.0.0@my-project 420 | """ 421 | tvm_project_folder = TVM_PATH / project_name 422 | 423 | if not os.path.exists(tvm_project_folder): 424 | raise click.UsageError('There is no project initiated with this name and version.') from IndexError 425 | 426 | if not os.path.exists(tvm_project_folder / 'config.yml'): 427 | raise click.UsageError('This project was created in older version or have corrupted files.') from IndexError 428 | 429 | with open(tvm_project_folder / 'config.yml', "r", encoding='utf-8') as f: 430 | data = yaml.load(f, Loader=yaml.FullLoader) 431 | click.echo(click.style("You are trying to remove the following paths and all its containing files:\n", fg='yellow')) # pylint: disable=line-too-long 432 | 433 | for path in data['project_directories']: 434 | if not prune: 435 | path = f"{path}/.tvm" 436 | click.echo(click.style(f"\t{path}", fg='yellow')) 437 | 438 | click.confirm(text=f"\nAre you sure you want to remove the project {project_name}?", abort=True) 439 | 440 | repository = environment_manager(project_path=f"{project_name}") 441 | remover = TutorProjectRemover(repository=repository) 442 | remover(prune=prune) 443 | 444 | 445 | @click.command(name="install", context_settings={"ignore_unknown_options": True}) 446 | @click.argument('options', nargs=-1, type=click.UNPROCESSED) 447 | def install_plugin(options): 448 | """Use the package installer pip in current tutor version.""" 449 | options = list(options) 450 | options.insert(0, "install") 451 | 452 | if "TVM_PROJECT_ENV" in os.environ: 453 | repository = environment_manager(os.environ.get("TVM_PROJECT_ENV")) 454 | installer = PluginInstaller(repository=repository) 455 | else: 456 | installer = TutorPluginInstaller(repository=version_manager) 457 | installer(options) 458 | 459 | 460 | @click.command(name="uninstall", context_settings={"ignore_unknown_options": True}) 461 | @click.argument('options', nargs=-1, type=click.UNPROCESSED) 462 | def uninstall_plugin(options): 463 | """Use the package uninstaller pip in current tutor version.""" 464 | options = list(options) 465 | options.insert(0, "uninstall") 466 | options.append("-y") 467 | if "TVM_PROJECT_ENV" in os.environ: 468 | repository = environment_manager(os.environ.get("TVM_PROJECT_ENV")) 469 | uninstaller = PluginUninstaller(repository=repository) 470 | else: 471 | uninstaller = TutorPluginUninstaller(repository=version_manager) 472 | uninstaller(options) 473 | 474 | 475 | @click.group( 476 | name="config", 477 | short_help="TVM config variables", 478 | context_settings={"help_option_names": ["--help", "-h", "help"]} 479 | ) 480 | @click.version_option(version=__version__) 481 | def config() -> None: 482 | """Hold the main wrapper for the `tvm config` command.""" 483 | 484 | 485 | @click.command(name="save", context_settings={"ignore_unknown_options": True}) 486 | @click.option('--plugins-root', nargs=1, required=False, type=str) 487 | @click.argument('root', required=True, type=str) 488 | def save(root, plugins_root): 489 | """ 490 | Set TUTOR_ROOT and TUTOR_PLUGINS_ROOT variables. 491 | 492 | You should write "." to set up the Current Working Directory as TUTOR_ROOT. 493 | 494 | TUTOR_PLUGINS_ROOT default is the TUTOR_ROOT/plugins. 495 | """ 496 | if root == ".": 497 | root = os.getcwd() 498 | root = root.rstrip('/') 499 | 500 | if not plugins_root: 501 | plugins_root = f"{root}/plugins" 502 | plugins_root = plugins_root.rstrip('/') 503 | 504 | info_file_path = f'{TVM_PATH}/current_bin.json' 505 | data = get_current_info(file=info_file_path) 506 | data.update({ 507 | "tutor_root": root, 508 | "tutor_plugins_root": plugins_root 509 | }) 510 | put_current_info(data=data, file=info_file_path) 511 | set_switch_from_file(file=info_file_path) 512 | 513 | 514 | @click.command(name="clear", context_settings={"ignore_unknown_options": True}) 515 | def clear(): 516 | """Remove TUTOR_ROOT and TUTOR_PLUGINS_ROOT variables.""" 517 | info_file_path = f'{TVM_PATH}/current_bin.json' 518 | data = get_current_info(file=info_file_path) 519 | data.update({ 520 | "tutor_root": None, 521 | "tutor_plugins_root": None 522 | }) 523 | put_current_info(data=data, file=info_file_path) 524 | set_switch_from_file(file=info_file_path) 525 | 526 | 527 | if __name__ == "__main__": 528 | main() 529 | 530 | cli.add_command(list_versions) 531 | cli.add_command(install) 532 | cli.add_command(uninstall) 533 | cli.add_command(use) 534 | cli.add_command(projects) 535 | projects.add_command(init) 536 | projects.add_command(remove) 537 | cli.add_command(plugins) 538 | plugins.add_command(install_plugin) 539 | plugins.add_command(uninstall_plugin) 540 | cli.add_command(config) 541 | config.add_command(save) 542 | config.add_command(clear) 543 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------