Skip to content

Commit

Permalink
Merge pull request #269 from GEOS-ESM/feature/pchakrab/py-project-pip…
Browse files Browse the repository at this point in the history
…-installable

Make mepo a pip-installable Python project
  • Loading branch information
tclune authored Mar 23, 2024
2 parents 64df27f + 5027609 commit 6b1cad4
Show file tree
Hide file tree
Showing 78 changed files with 289 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mepo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
timeout-minutes: 5

- name: Run unit tests
run: python3 mepo.d/utest/test_mepo_commands.py -v
run: python3 tests/test_mepo_commands.py -v
timeout-minutes: 5
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*~
*.pyc
*.egg-info
dist
venv
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `pyproject.toml` to aid with `pip` installation.

### Changed

### Removed
- Converted `mepo` to a Python project via the following renaming
-- `mepo.d` -> `src/mepo`
-- `mepo.d/utest` -> `tests`
-- `doc` --> `docs`
- Helper script `mepo`, used for development, moved to the `bin` directory.

## [1.52.0] - 2024-01-10

Expand Down
17 changes: 17 additions & 0 deletions bin/mepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

import os
import sys
import traceback

# Version check
if sys.version_info < (3, 9, 0):
sys.exit('ERROR: Python version needs to be >= 3.6.0')

# Add direactory containing mepo to path
SRC_D = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'src')
sys.path.insert(0, SRC_D)

if __name__ == '__main__':
from mepo.main import main
main()
File renamed without changes.
15 changes: 7 additions & 8 deletions doc/make_md_docs.py → docs/make_md_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
doc_dir_path = os.path.dirname(os.path.realpath(__file__))
# Then we need to get to the mepo/mepo.d/command directory. First the "main" dir
main_dir_path = os.path.dirname(doc_dir_path)
# Now add 'mepo.d'
mepod_dir_path = os.path.join(main_dir_path,'mepo.d')
# Now add 'src/mepo'
mepod_dir_path = os.path.join(main_dir_path, 'src', 'mepo')
# And then 'command'
command_dir_path = os.path.join(mepod_dir_path,'command')
command_dir_path = os.path.join(mepod_dir_path, 'command')

mepo_command_path = os.path.join(main_dir_path,'mepo')
mepo_command_path = os.path.join(main_dir_path, 'bin', 'mepo')

def get_command_list(directory):
# Walk the tree
Expand Down Expand Up @@ -50,12 +50,12 @@ def get_command_list(directory):
return sorted(all_useful_commands)

def create_markdown_from_usage(command, mdFile):
cmd = [mepo_command_path,command,'--help']
cmd = [mepo_command_path, command, '--help']

# Some commands have spaces, so we need to break it up again
cmd = ' '.join(cmd).split()

result = sp.run(cmd,capture_output=True,universal_newlines=True,env={'COLUMNS':'256'})
result = sp.run(cmd, capture_output=True, universal_newlines=True, env={'COLUMNS':'256'})
output = result.stdout

output_list = output.split("\n")
Expand Down Expand Up @@ -84,7 +84,7 @@ def create_markdown_from_usage(command, mdFile):

if __name__ == "__main__":

doc_file='Mepo-Commands.md'
doc_file = 'Mepo-Commands.md'
mdFile = MdUtils(file_name=doc_file)

mdFile.new_header(level=1, title="Overview")
Expand All @@ -99,4 +99,3 @@ def create_markdown_from_usage(command, mdFile):
mdFile.new_table_of_contents(table_title='Table of Contents', depth=2)
mdFile.create_md_file()
print(f'Generated {doc_file}.')

17 changes: 0 additions & 17 deletions mepo

This file was deleted.

15 changes: 0 additions & 15 deletions mepo.d/command/branch/branch.py

This file was deleted.

17 changes: 0 additions & 17 deletions mepo.d/command/config/config.py

This file was deleted.

19 changes: 0 additions & 19 deletions mepo.d/command/stash/stash.py

This file was deleted.

17 changes: 0 additions & 17 deletions mepo.d/command/tag/tag.py

This file was deleted.

6 changes: 0 additions & 6 deletions mepo.d/main.py

This file was deleted.

26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "mepo"
version = "v2.0.0"
authors = [
{name = "GMAO SI Team", email = "[email protected]"},
]
description = "Tool to manage (m)ultiple r(epo)sitories"
requires-python = ">= 3.9"
license = {file = "LICENSE"}
readme = "README.md"
dependencies = [
"pyyaml>=6.0.1",
]

[project.urls]
Homepage = "https://github.com/GEOS-ESM/mepo"

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

[tool.setuptools]
include-package-data = true
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions mepo.d/cmdline/parser.py → src/mepo/cmdline/parser.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import argparse

from cmdline.branch_parser import MepoBranchArgParser
from cmdline.stash_parser import MepoStashArgParser
from cmdline.tag_parser import MepoTagArgParser
from cmdline.config_parser import MepoConfigArgParser
from utilities import mepoconfig
from mepo.cmdline.branch_parser import MepoBranchArgParser
from mepo.cmdline.stash_parser import MepoStashArgParser
from mepo.cmdline.tag_parser import MepoTagArgParser
from mepo.cmdline.config_parser import MepoConfigArgParser
from mepo.utilities import mepoconfig

class MepoArgParser(object):

Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions src/mepo/command/branch/branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import subprocess as sp

from mepo.state.state import MepoState

from mepo.command.branch.list import list
from mepo.command.branch.create import create
from mepo.command.branch.delete import delete

def run(args):
d = {
'list': list,
'create': create,
'delete': delete,
}
d[args.mepo_branch_cmd].run(args)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from state.state import MepoState
from utilities import verify
from repository.git import GitRepository
from mepo.state.state import MepoState
from mepo.utilities import verify
from mepo.repository.git import GitRepository

def run(args):
allcomps = MepoState.read_state()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from state.state import MepoState
from utilities import verify
from repository.git import GitRepository
from mepo.state.state import MepoState
from mepo.utilities import verify
from mepo.repository.git import GitRepository

def run(args):
allcomps = MepoState.read_state()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from state.state import MepoState
from utilities import verify
from repository.git import GitRepository
from mepo.state.state import MepoState
from mepo.utilities import verify
from mepo.repository.git import GitRepository

def run(args):
allcomps = MepoState.read_state()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from state.state import MepoState
from utilities import colors
from utilities import verify
from utilities.version import version_to_string, sanitize_version_string
from repository.git import GitRepository
from shutil import get_terminal_size
from state.component import MepoVersion
import os
from shutil import get_terminal_size

from mepo.state.state import MepoState
from mepo.state.component import MepoVersion
from mepo.utilities import colors
from mepo.utilities import verify
from mepo.utilities.version import version_to_string, sanitize_version_string
from mepo.repository.git import GitRepository

VER_LEN = 30

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from state.state import MepoState
from utilities import verify
from repository.git import GitRepository
from utilities import colors
from mepo.state.state import MepoState
from mepo.utilities import verify
from mepo.repository.git import GitRepository
from mepo.utilities import colors

def run(args):
allcomps = MepoState.read_state()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from state.state import MepoState
from utilities import verify
from repository.git import GitRepository
from utilities import colors
from mepo.state.state import MepoState
from mepo.utilities import verify
from mepo.repository.git import GitRepository
from mepo.utilities import colors

def run(args):
allcomps = MepoState.read_state()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from state.state import MepoState, StateDoesNotExistError
from repository.git import GitRepository
from command.init import init as mepo_init
from utilities import shellcmd, colors, mepoconfig
from urllib.parse import urlparse

import os
import pathlib
import shutil
import shlex
from urllib.parse import urlparse

from mepo.state.state import MepoState, StateDoesNotExistError
from mepo.repository.git import GitRepository
from mepo.command.init import init as mepo_init
from mepo.utilities import shellcmd, colors, mepoconfig

def run(args):

Expand Down
4 changes: 2 additions & 2 deletions mepo.d/command/command.py → src/mepo/command/command.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from importlib import import_module
from utilities import mepoconfig
from mepo.utilities import mepoconfig

def run(args):
mepo_cmd = mepoconfig.get_alias_command(args.mepo_cmd)

# Load the module containing the 'run' method of specified mepo command
cmd_module = import_module('command.{}.{}'.format(mepo_cmd, mepo_cmd))
cmd_module = import_module('mepo.command.{}.{}'.format(mepo_cmd, mepo_cmd))

# Execute 'run' method of the specified mepo command
cmd_module.run(args)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from state.state import MepoState
from utilities import verify
from repository.git import GitRepository
from command.stage.stage import stage_files
from mepo.state.state import MepoState
from mepo.utilities import verify
from mepo.repository.git import GitRepository
from mepo.command.stage.stage import stage_files

# Popping up an EDITOR is based on https://stackoverflow.com/a/39989442
import os, tempfile, subprocess
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from state.state import MepoState
from utilities import colors
from utilities.version import version_to_string, sanitize_version_string
from repository.git import GitRepository
from shutil import get_terminal_size

from mepo.state.state import MepoState
from mepo.utilities import colors
from mepo.utilities.version import version_to_string, sanitize_version_string
from mepo.repository.git import GitRepository

VER_LEN = 30

def run(args):
Expand Down
Loading

0 comments on commit 6b1cad4

Please sign in to comment.