Skip to content

Commit

Permalink
Progress 1 (#14)
Browse files Browse the repository at this point in the history
* V1 progress

* Missing lock

* Lock in progress

* Test implemented

* Ready for realease

* Pyrgo ready
  • Loading branch information
Tomperez98 authored Aug 18, 2023
1 parent 94ce4bd commit 1a6ffd5
Show file tree
Hide file tree
Showing 82 changed files with 978 additions and 1,991 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest] # [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python 3.7.16
python 3.9
44 changes: 36 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,42 @@
// https://github.com/microsoft/vscode-python/issues/693#issuecomment-367856613
"--no-cov"
],
"python.testing.pytestEnabled": true,
"[python]": {
"diffEditor.ignoreTrimWhitespace": false,
"editor.formatOnType": false,
"editor.wordBasedSuggestions": false
},
"python.analysis.autoImportCompletions": true,
"python.analysis.completeFunctionParens": true,
"python.analysis.inlayHints.callArgumentNames": true,
"python.analysis.inlayHints.variableTypes": true,
"python.analysis.extraCommitChars": false,
"python.analysis.inlayHints.callArgumentNames": false,
"python.analysis.inlayHints.pytestParameters": false,
"python.analysis.inlayHints.functionReturnTypes": false,
"python.analysis.inlayHints.variableTypes": false,
"python.analysis.typeCheckingMode": "basic",
"python.analysis.userFileIndexingLimit": -1,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
"python.analysis.userFileIndexingLimit": 200,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.diagnosticMode": "workspace",
"[toml]": {
"editor.formatOnSave": true
},
"json.format.enable": true,
"[json]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace",
"editor.formatOnSave": true
},
"python.analysis.enablePytestSupport": false,
"yaml.schemas": {
"https://squidfunk.github.io/mkdocs-material/schema.json": "mkdocs.yml"
},
"yaml.customTags": [
"!ENV scalar",
"!ENV sequence",
"tag:yaml.org,2002:python/name:materialx.emoji.to_svg",
"tag:yaml.org,2002:python/name:materialx.emoji.twemoji",
"tag:yaml.org,2002:python/name:pymdownx.superfences.fence_code_format"
]
}
40 changes: 13 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,33 @@ build-backend = "hatchling.build"
name = "pyrgo"
version = "0.4.1"
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
authors = [
{ name = "Tomas Perez Alvarez", email = "[email protected]"}
{ name = "Tomas Perez Alvarez", email = "[email protected]" },
]
dependencies = [
"click",
"ruff",
"mypy",
"black",
"pip-tools",
"pip-tools>=7.0.0",
"pytest",
"mkdocs-material",
"result==0.10.0",
"result",
"build",
"loguru",
"pip-audit>=2.5.5",
]

[project.optional-dependencies]
dev = [
"pytest-cov"
]
dev = ["pytest-cov"]

[project.scripts]
pyrgo = "pyrgo.cli.pyrgo_core.cli:root"
pyrgo-new = "pyrgo.cli.pyrgo_new.cli:new"
pyrgo = "pyrgo.cli.main:cli"

[project.urls]
Documentation = "https://github.com/Tomperez98/pyrgo#readme"
Expand All @@ -45,11 +41,7 @@ Source = "https://github.com/Tomperez98/pyrgo"

[tool.ruff]
line-length = 88
ignore = [
"ANN101",
"D203",
"D212",
]
ignore = ["ANN101", "D203", "D212"]
select = ["ALL"]
fix = false
exclude = [
Expand Down Expand Up @@ -77,7 +69,7 @@ exclude = [
[tool.ruff.per-file-ignores]
"scripts/*.py" = ["INP001"]
"__init__.py" = ["D104"]
"tests/*.py" = ["INP001", "S101"]
"tests/*.py" = ["INP001", "S101", "D"]

[tool.ruff.isort]
known-first-party = ["pyrgo"]
Expand All @@ -91,7 +83,6 @@ ban-relative-imports = "all"
[tool.ruff.flake8-quotes]
inline-quotes = "double"


[tool.black]
line-length = 88
include = '\.pyi?$'
Expand All @@ -102,24 +93,15 @@ xfail_strict = true
addopts = [
"--import-mode=importlib",
"--strict-markers",
"--cov-fail-under=5",
"--cov-report=term-missing:skip-covered",
"--cov-config=pyproject.toml",
"--cov=pyrgo",
]
markers = [
"integration: mark integration tests.",
"unit: mark unittest.",
]
markers = ["integration: mark integration tests.", "unit: mark unittest."]

[tool.coverage.run]
branch = true
parallel = true
omit = [
"pyrgo/logging.py",
"pyrgo/cli/**",
"pyrgo/**/__init__.py"
]
relative_files = true

[tool.coverage.report]
Expand Down Expand Up @@ -147,3 +129,7 @@ disallow_untyped_decorators = true
disallow_untyped_calls = true
disallow_untyped_defs = true
explicit_package_bases = true

[tool.pyrgo]
extra-paths = ["scripts"]
extra-caches = [".coverage"]
1 change: 1 addition & 0 deletions pyrgo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Pyrgo. Python package manager."""
1 change: 1 addition & 0 deletions pyrgo/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Pyrgo cli module."""
14 changes: 14 additions & 0 deletions pyrgo/cli/cmds/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""CLI commands."""
from __future__ import annotations

from pyrgo.cli.cmds._audit import audit
from pyrgo.cli.cmds._build import build
from pyrgo.cli.cmds._check import check
from pyrgo.cli.cmds._clean import clean
from pyrgo.cli.cmds._fmt import fmt
from pyrgo.cli.cmds._lock import lock
from pyrgo.cli.cmds._new import new
from pyrgo.cli.cmds._sync import sync
from pyrgo.cli.cmds._test import test

__all__ = ["lock", "fmt", "check", "sync", "build", "clean", "test", "audit", "new"]
48 changes: 48 additions & 0 deletions pyrgo/cli/cmds/_audit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Audit command."""
from __future__ import annotations

import sys

import click
from result import Ok

from pyrgo.cli.cmds._utils import ensure_env_exist_in_lock_file, inform_and_run_program
from pyrgo.command_exec import PythonCommandExec
from pyrgo.conf import PyrgoConf


@click.command("audit")
@click.option(
"-e",
"--env",
"env",
type=click.STRING,
required=True,
)
@click.option(
"--fix/--no-fix",
"fix",
type=click.BOOL,
default=False,
show_default=True,
)
def audit(env: str, *, fix: bool) -> None:
config = PyrgoConf.new()
ensure_env_exist_in_lock_file(env=env, config=config)

pip_audit_cmd = PythonCommandExec.new(program="pip_audit").add_args(
args=[
"-r",
config.requirements.joinpath(f"{env}.txt")
.relative_to(config.cwd)
.as_posix(),
],
)
if fix:
pip_audit_cmd.add_args(args=["--fix"])

program_execution = inform_and_run_program(commands=[pip_audit_cmd])
if not isinstance(program_execution, Ok):
sys.exit(1)

sys.exit(0)
27 changes: 27 additions & 0 deletions pyrgo/cli/cmds/_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Build command."""
from __future__ import annotations

import sys

import click
from result import Ok

from pyrgo.cli.cmds._utils import inform_and_run_program
from pyrgo.command_exec import PythonCommandExec
from pyrgo.conf import PyrgoConf


@click.command("build")
def build() -> None:
"""Build project with `build`."""
program_execution = inform_and_run_program(
commands=[
PythonCommandExec.new(program="build").add_args(
[PyrgoConf.new().cwd.as_posix()],
),
],
)
if not isinstance(program_execution, Ok):
sys.exit(1)

sys.exit(0)
58 changes: 58 additions & 0 deletions pyrgo/cli/cmds/_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Check command."""
from __future__ import annotations

import sys

import click
from result import Ok

from pyrgo.cli.cmds._utils import inform_and_run_program
from pyrgo.command_exec import PythonCommandExec
from pyrgo.conf import PyrgoConf


@click.command("check")
@click.option(
"-t",
"--timeout",
"timeout",
default=360,
type=click.IntRange(min=60),
)
@click.option(
"--add-noqa",
"add_noqa",
is_flag=True,
default=False,
show_default=True,
type=click.BOOL,
)
@click.option(
"--ignore-noqa",
"ignore_noqa",
is_flag=True,
default=False,
show_default=True,
type=click.BOOL,
)
def check(*, timeout: int, add_noqa: bool, ignore_noqa: bool) -> None:
"""Check code with `mypy` and `ruff`."""
configuration = PyrgoConf.new()
ruff_command = PythonCommandExec.new(program="ruff")
mypy_command = PythonCommandExec.new(program="mypy.dmypy").add_args(
args=["run", "--timeout", str(timeout), "--"],
)

if add_noqa:
ruff_command.add_args(args=["--add-noqa"])
if ignore_noqa:
ruff_command.add_args(args=["--ignore-noqa"])

for command in [ruff_command, mypy_command]:
command.add_args(args=configuration.relevant_paths)

program_execution = inform_and_run_program(commands=[ruff_command, mypy_command])
if not isinstance(program_execution, Ok):
sys.exit(1)

sys.exit(0)
39 changes: 39 additions & 0 deletions pyrgo/cli/cmds/_clean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Clean command."""
from __future__ import annotations

import itertools
import shutil
import sys

import click
from result import Ok

from pyrgo.cli.cmds._utils import inform_and_run_program
from pyrgo.command_exec import PythonCommandExec
from pyrgo.conf import PyrgoConf


@click.command("clean")
def clean() -> None:
"""Clean project repository."""
config = PyrgoConf.new()
for folder in itertools.chain(config.artifacts, config.caches):
if folder.exists():
if folder.is_dir():
shutil.rmtree(path=folder)
else:
folder.unlink()

for path in config.relevant_paths:
for pycache in config.cwd.joinpath(path).rglob(pattern="__pycache__"):
shutil.rmtree(pycache)

for outdated_file in config.locked_envs().difference(config.env_groups):
config.requirements.joinpath(f"{outdated_file}.txt").unlink()

program_execution = inform_and_run_program(
commands=[PythonCommandExec.new(program="mypy.dmypy").add_args(args=["stop"])],
)
if not isinstance(program_execution, Ok):
sys.exit(1)
sys.exit(0)
27 changes: 27 additions & 0 deletions pyrgo/cli/cmds/_fmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Format command."""
from __future__ import annotations

import sys

import click
from result import Ok

from pyrgo.cli.cmds._utils import inform_and_run_program
from pyrgo.command_exec import PythonCommandExec
from pyrgo.conf import PyrgoConf


@click.command("fmt")
def fmt() -> None:
"""Format code with `ruff` and `black`."""
configuration = PyrgoConf.new()
ruff_command = PythonCommandExec.new(program="ruff").add_args(args=["--fix-only"])
black_command = PythonCommandExec.new(program="black")

for command in [ruff_command, black_command]:
command.add_args(args=configuration.relevant_paths)

program_execution = inform_and_run_program(commands=[ruff_command, black_command])
if not isinstance(program_execution, Ok):
sys.exit(1)
sys.exit(0)
Loading

0 comments on commit 1a6ffd5

Please sign in to comment.