Skip to content

Commit

Permalink
Merge pull request #1 from cav71/new-code
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
cav71 authored Jan 1, 2025
2 parents e382af8 + a22c72d commit c172907
Show file tree
Hide file tree
Showing 12 changed files with 551 additions and 111 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Pull-Request

on:
pull_request:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

env:
PACKAGE: mono2repo

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/[email protected]
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup Python toolchain
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Python dependencies
shell: bash
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
- name: Run Python checks (ruff)
shell: bash
env:
PYTHONPATH: src
run: |
ruff check src tests
- name: Run Python checks (mypy)
shell: bash
env:
PYTHONPATH: src
OUTDIR: build/qa-${{ matrix.python-version }}-${{ matrix.os}}
run: |
mypy src \
--no-incremental --xslt-html-report $OUTDIR/mypy
- name: Run Python checks
shell: bash
env:
PYTHONPATH: src
OUTDIR: build/qa-${{ matrix.python-version }}-${{ matrix.os}}
run: |
py.test \
--cov=${{ env.PACKAGE }} \
--cov-report=html:$OUTDIR/coverage --cov-report=xml:$OUTDIR/coverage.xml \
--junitxml=$OUTDIR/junit/junit.xml --html=$OUTDIR/junit/junit.html --self-contained-html \
tests
- name: Build wheel packages
if: ${{ ! contains(matrix.os, 'windows') }}
env:
GITHUB_DUMP: ${{ toJson(github) }}
run: |
python -m build
touch .keepme
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: qa-results-${{ matrix.python-version }}-${{ matrix.os }}
path: |
build/qa-${{ matrix.python-version }}-${{ matrix.os}}
dist
.keepme
# Use always() to always run this step to publish test results when there are test failures
if: always()

89 changes: 86 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,89 @@
[build-system]
requires = [ "setuptools", "setuptools-github", "wheel" ]
build-backend = 'setuptools.build_meta'
requires = ["setuptools>=68.0"]
build-backend = "setuptools.build_meta"

[tool.black]

[project]
name = "mono2repo"
version = "0.1.0"
description = "create a standalone repo from a monorepo subdir."
readme = "README.md"
license = { text = "MIT" }
requires-python = ">= 3.9"


authors = [
{ name = "Antonio Cavallo", email = "[email protected]" },
]

classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]

[project.urls]
Source = "https://github.com/cav71/mono2repo"
Issues = "https://github.com/cav71/mono2repo/issues"
Documentation = "https://github.com/cav71/mono2repo"

[project.scripts]
mono2repo = "mono2repo.mono2repo:main"

[tool.setuptools.packages.find]
where = ["src"]

[tool.ruff]
target-version = "py39"
line-length = 88
src = ["src/mono2repo"]

[tool.ruff.format]
quote-style = "double"

[tool.ruff.lint]
ignore = []
select = ["F", "E", "W", "Q", "I001"]

[tool.ruff.lint.isort]
known-first-party = ["mono2repo"]

[tool.mypy]
disallow_untyped_defs = false
follow_imports = "normal"
ignore_missing_imports = true
pretty = true
show_column_numbers = true
show_error_codes = true
warn_no_return = false
warn_unused_ignores = true
exclude = [
"^make\\.py",
"docs/conf\\.py",
"^docs/\\.*",
"^build/\\.*",
]

[tool.coverage.run]
branch = true

[tool.coverage.paths]
source = [
"src/",
]

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.pytest.ini_options]
markers = [
"manual: marks tests unsafe for auto-run (eg. better run them manually)",
]
36 changes: 0 additions & 36 deletions setup.py

This file was deleted.

Empty file added src/mono2repo/__init__.py
Empty file.
66 changes: 5 additions & 61 deletions mono2repo.py → src/mono2repo/mono2repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import tempfile


__version__ = "0.0.9"
__hash__ = "<invalid-hash>"
__version__ = ""
__hash__ = ""


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -282,65 +283,8 @@ def update(igit, ogit, subdir, migrate):
ogit.run(["remote", "remove", "legacy-repo"])


@contextlib.contextmanager
def universe(tmpdir, output, func, error, uri, migrate):
"""
(ogit) output/
(igit) <tmpdir>/legacy-repo
"""

ogit = Git(worktree=output.resolve())
log.debug("output client %s", ogit)

if func == init and ogit.good():
error(f"directory already initialized, {ogit}")

branch = ogit.branch
if func == update:
if not ogit.good():
error(f"directory not ready/present/initialized, {ogit}")
if ogit.run(["status", "-s", "--porcelain"]).strip():
error(f"directory not clean (eg. git status has modification) on {ogit}")
if branch != migrate:
ogit.branch = migrate
log.debug("switched from branch %s on %s", branch, ogit)

if uri:
source, subdir = split_source(uri)
else:
log.debug(f"getting source/subdir info from {ogit}")
txt = ogit.run(["config", "--local", "--get", "mono2repo.uri"])
source, subdir = split_source(txt)
log.debug("git repo source [%s]", source)
log.debug("repo subdir [%s]", subdir)

with tempdir(tmpdir) as tmp:
igit = Git.clone(source, tmp / "legacy-repo")
log.debug("input client %s", igit)
if not (igit.worktree / subdir).exists():
error(f"no subdir {subdir} under {igit}")

try:
yield ogit, igit, subdir
finally:
if branch == migrate:
ogit.branch = branch
log.debug("restoring to old branch %s, %s", branch, ogit)
if uri:
# finally we'll leave the configuration parameters for the update
log.debug("writing config uri in {ogit}")
ogit.run(
[
"config",
"--local",
"mono2repo.uri",
uri,
]
)


def main(options=None):
options = parse_args(options)
options = options or parse_args()
log.debug("found system %s", platform.uname().system.lower())
log.debug("git version [%s]", run(["git", "--version"]))

Expand All @@ -361,4 +305,4 @@ def main(options=None):


if __name__ == "__main__":
main(parse_args())
main()
2 changes: 2 additions & 0 deletions src/mono2repo/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = ""
__hash__ = ""
Loading

0 comments on commit c172907

Please sign in to comment.