Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move shims to another package #6

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
cache: true
- name: Install Dependencies
run: |
pdm sync -dGtest
pdm sync
- name: Run Tests
run: |
pdm run pytest -v tests
pdm run test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# onepm

Picks the right package manager for you
Picks the right package manager for you.

Don't make me think about which package manager to use when I clone a project from other people. OnePM will pick the right package manager by searching for the lock files and/or the project settings in `pyproject.toml`.

Expand Down
162 changes: 162 additions & 0 deletions packages/onepm-shims/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm-project.org/#use-with-ide
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
1 change: 1 addition & 0 deletions packages/onepm-shims/LICENSE
1 change: 1 addition & 0 deletions packages/onepm-shims/README.md
39 changes: 39 additions & 0 deletions packages/onepm-shims/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[project]
name = "onepm-shims"
description = "The shims package for onepm"
authors = [
{name = "Frost Ming", email = "[email protected]"},
]
requires-python = ">=3.10"
dependencies = ["unearth>=0.14.0"]
readme = "README.md"
license = {text = "MIT"}
dynamic = ["version"]
classifiers = [
"Topic :: Software Development :: Build Tools",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.urls]
Homepage = "https://github.com/frostming/onepm"
Repository = "https://github.com/frostming/onepm"
Changelog = "https://github.com/frostming/onepm/releases"

[project.scripts]
pdm = "onepm_shims.shims:pdm"
pipenv = "onepm_shims.shims:pipenv"
poetry = "onepm_shims.shims:poetry"

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.pdm]
distribution = true

[tool.pdm.version]
source = "scm"
File renamed without changes.
19 changes: 19 additions & 0 deletions packages/onepm-shims/src/onepm_shims/shims.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from __future__ import annotations

import sys
from functools import partial
from typing import NoReturn

from onepm.core import OneManager


def shim(package_manager: str, args: list[str] | None = None) -> NoReturn:
if args is None:
args = sys.argv[1:]
pm = OneManager().get_package_manager(package_manager)
pm.execute(*args)


pdm = partial(shim, "pdm")
pipenv = partial(shim, "pipenv")
poetry = partial(shim, "poetry")
1 change: 1 addition & 0 deletions packages/onepm/LICENSE
1 change: 1 addition & 0 deletions packages/onepm/README.md
48 changes: 48 additions & 0 deletions packages/onepm/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[project]
name = "onepm"
description = "Picks the right package manager for you."
authors = [
{name = "Frost Ming", email = "[email protected]"},
]
dependencies = [
"packaging>=22.1",
"tomlkit>=0.12.3",
]
requires-python = ">=3.10"
readme = "README.md"
license = {text = "MIT"}
dynamic = ["version"]
classifiers = [
"Topic :: Software Development :: Build Tools",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.optional-dependencies]
shims = ["onepm-shims"]

[project.urls]
Homepage = "https://github.com/frostming/onepm"
Repository = "https://github.com/frostming/onepm"
Changelog = "https://github.com/frostming/onepm/releases"

[project.scripts]
pi = "onepm:pi"
pu = "onepm:pu"
pr = "onepm:pr"
pun = "onepm:pun"
pa = "onepm:pa"
onepm = "onepm.cli:main"

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.pdm]
distribution = true

[tool.pdm.version]
source = "scm"
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
from onepm.core import OneManager


def make_shortcut(
method_name: str, specified: str | None = None
) -> Callable[[list[str] | None], NoReturn]:
def make_shortcut(method_name: str) -> Callable[[list[str] | None], NoReturn]:
def main(args: list[str] | None = None) -> NoReturn: # type: ignore[misc]
if args is None:
args = sys.argv[1:]
package_manager = OneManager().get_package_manager(specified)
package_manager = OneManager().get_package_manager()
getattr(package_manager, method_name)(*args)

return main
Expand All @@ -23,6 +21,3 @@ def main(args: list[str] | None = None) -> NoReturn: # type: ignore[misc]
pun = make_shortcut("uninstall")
pr = make_shortcut("run")
pa = make_shortcut("execute")
pdm = make_shortcut("execute", "pdm")
poetry = make_shortcut("execute", "poetry")
pipenv = make_shortcut("execute", "pipenv")
File renamed without changes.
20 changes: 17 additions & 3 deletions src/onepm/core.py → packages/onepm/src/onepm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any

import tomlkit
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name
from packaging.version import Version
Expand All @@ -24,7 +25,6 @@
if TYPE_CHECKING:
from unearth import PackageFinder

import tomlkit

PACKAGE_MANAGERS: dict[str, type[PackageManager]] = {
p.name: p # type: ignore[type-abstract]
Expand All @@ -50,8 +50,20 @@ def __init__(

self._tool_dir = Path.home() / ".onepm"

def shim_enabled(self) -> bool:
try:
import unearth
except ModuleNotFoundError:
return False
return True

@cached_property
def package_finder(self) -> PackageFinder:
if not self.shim_enabled():
raise ImportError(
"Package manager shims are disabled, please re-install onepm with '[shims]' extra."
)

import unearth

index_urls = [self.index_url] if self.index_url else []
Expand Down Expand Up @@ -99,7 +111,7 @@ def get_installations(self, name: str) -> list[Installation]:
venvs = self.package_dir(name)
if not venvs.exists():
return []
versions: list[Version] = []
versions: list[Installation] = []
for venv in venvs.iterdir():
candidate = next(
venv.glob(f"lib/**/site-packages/{name}-*.dist-info"), None
Expand All @@ -124,7 +136,9 @@ def install_tool(self, name: str, requirement: Requirement) -> Installation:
version = Version(best_match.version or "")
installed_versions = self.get_installations(name)
if (
installed := next((i.version == version for i in installed_versions), None)
installed := next(
(i for i in installed_versions if i.version == version), None
)
) is not None:
return installed

Expand Down
File renamed without changes.
Loading
Loading