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

Python package with expanded testing #278

Merged
merged 71 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
ea53381
Code reorganization to address #273
pchakraborty Apr 11, 2024
c7be668
Fixed issues with renaming config_file as registry
pchakraborty Apr 11, 2024
5f4257a
Removed a print statement left in by mistake
pchakraborty Apr 11, 2024
232376c
On our way to more robust testing
pchakraborty Apr 12, 2024
213f8a3
Added nocolor option to 'git branch list'
pchakraborty Apr 12, 2024
2e58df5
It's enough to chdir to the fixture dir at the beginning of a test
pchakraborty Apr 12, 2024
76a08c6
Added 'mepo branch' tests
pchakraborty Apr 12, 2024
2c5d346
Added tests for mepo tag, fetch, pull, pull-all
pchakraborty Apr 12, 2024
3412ad7
multiprocessing library supports the context management protocol
pchakraborty Apr 12, 2024
f3f521e
Added tests for mepo push, diff, whereis and reset
pchakraborty Apr 13, 2024
ad71e17
component.py - using Python3's relative import
pchakraborty Apr 13, 2024
84e0708
Suppressing test outputs to terminal
pchakraborty Apr 13, 2024
15156a5
Turning off testing 'mepo reset' and checking why 'mepo diff' is failing
pchakraborty Apr 15, 2024
1bbe14d
For testing 'mepo diff', ignore the last line '---'
pchakraborty Apr 15, 2024
1a358e5
Ignore the last line of both stdout and saved outputs
pchakraborty Apr 15, 2024
0068ecd
Escaping the string message of 'git tag create'
pchakraborty Apr 15, 2024
be94bcb
Create regular (non-annotated) tag instead
pchakraborty Apr 15, 2024
54f68bb
Testing 'mepo reset' is back on - this was not the issue
pchakraborty Apr 15, 2024
c90136c
Code from src/mepo/command/command.py included in src/mepo/__main__.py
pchakraborty Apr 15, 2024
0d2ad87
Small edits
pchakraborty Apr 15, 2024
dd23a82
Updated GEOSfvdycore version for testing
pchakraborty Apr 16, 2024
443b636
Minor quote changes
pchakraborty Apr 16, 2024
ce62590
Using SimpleNamespace to construct arguments to mepo commands
pchakraborty Apr 16, 2024
376baf2
Multiprocessing lib supports context manager protocol
pchakraborty Apr 16, 2024
1c946c9
Removed tests/input/args.py - using SimpleNamespace now
pchakraborty Apr 16, 2024
2bf3212
Updated README and CHANGELOG
pchakraborty Apr 16, 2024
2b01e93
Moved duplicate code to get GIT_EDITOR, in commit.py and tag_create.p…
pchakraborty Apr 18, 2024
d28d4d3
Lint code as part of GitHub actions workflow
pchakraborty Apr 18, 2024
73675c4
Added __init__.py in cmdline, command and utilities directories
pchakraborty Apr 18, 2024
39a4d5a
Linting updates
pchakraborty Apr 18, 2024
3539878
Hardcoding Python version
pchakraborty Apr 18, 2024
dab118d
Renaming
pchakraborty Apr 18, 2024
acdd32a
Adding ability to create a mepo binary that can uploaded as an artifa…
pchakraborty Apr 25, 2024
13febd8
Added fix for reading mepo1 state
pchakraborty Apr 30, 2024
04218f0
Added a mepo command, update-state, to permanently update mepo1 state…
pchakraborty May 1, 2024
d5d57b1
Formatting changes to update-state.py
pchakraborty May 1, 2024
f056578
Slightly different printable representation of component
pchakraborty May 2, 2024
92bce58
Added an optional argument one-per-line for 'list'
pchakraborty May 2, 2024
71591c4
component.py::MepoComponent - renamed to_dict to to_registry_format. …
pchakraborty May 2, 2024
adc24a6
Fixed test test_list
pchakraborty May 2, 2024
c8582c5
Merge remote-tracking branch 'origin/develop' into feature/pchakrab/m…
pchakraborty May 2, 2024
fcbe936
Fixed a bug in update-state - need to switch to the fixture dir first
pchakraborty May 3, 2024
df62e83
Implemented a context manager for os.chdir
pchakraborty May 3, 2024
195e714
Reformatted using black
pchakraborty May 7, 2024
a962e29
Separate GitHub workflows for running linter and formatter
pchakraborty May 7, 2024
5f8f152
Added black to requirements
pchakraborty May 7, 2024
d65021b
Using poetry to manage dependencies and packaging
pchakraborty May 7, 2024
c37ad23
Added creation of a top level script to build
pchakraborty May 7, 2024
6d75a6a
Added pylint as (poetry) dependency
pchakraborty May 7, 2024
932df95
Added pylint to requirements.txt
pchakraborty May 7, 2024
8ae1e3e
Updated pyproject.toml
pchakraborty May 8, 2024
974ed81
Small changes to the test script for consistency in mepo commands
pchakraborty May 8, 2024
569c336
Enabled previously disabled Pylint (C)onvention and (E)rror codes
pchakraborty May 8, 2024
8d6b315
Added directory containing mepo to PYTHONPATH
pchakraborty May 8, 2024
e45f71d
Using contextlib.redirect_stdout instead
pchakraborty May 8, 2024
6cee2d9
Can't switch to contextlib.chdir as this exists only in 3.11+
pchakraborty May 8, 2024
7c9acc2
Run 'black --check' instead. Non-zero return code indicates that some…
pchakraborty May 8, 2024
dce8395
Formatted using black
pchakraborty May 8, 2024
637919b
Config file is now called registry
pchakraborty May 9, 2024
558d41a
Moved fixture/component validation from MepoComponent to Registry
pchakraborty May 9, 2024
f9c2f47
Reformat using black
pchakraborty May 9, 2024
e655829
Switched from pkl state file to json
pchakraborty May 9, 2024
f3f30ae
print() has a flush argument
pchakraborty May 10, 2024
c930b76
Trivial changes
pchakraborty May 11, 2024
fd2c473
If mepo1 style state, print warning to run 'mepo update-state'. Updat…
pchakraborty May 11, 2024
116c6fa
Removing hashes from requirements.txt
pchakraborty May 11, 2024
29dbda7
Fixed bug in string formatting
pchakraborty May 13, 2024
595dcc7
Update comment in registry.py
pchakraborty May 13, 2024
1bc8330
Store full path to the fixture dir in state file
pchakraborty May 13, 2024
8917834
Revert "Store full path to the fixture dir in state file". We want re…
pchakraborty May 14, 2024
64a5ade
Local path saved to state file is relative to fixture directory
pchakraborty May 14, 2024
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
23 changes: 23 additions & 0 deletions .github/workflows/run-formatter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run formatter

on: [push]

jobs:
format:
runs-on: ubuntu-latest
name: Format code
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
timeout-minutes: 5
- name: Run black
run: black --check .
timeout-minutes: 5
23 changes: 23 additions & 0 deletions .github/workflows/run-linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run linter

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
name: Lint code
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
timeout-minutes: 5
- name: Run pylint
run: pylint --exit-zero src/mepo
timeout-minutes: 5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit testing of mepo
name: Run tests

on: [push]

Expand Down Expand Up @@ -26,6 +26,8 @@ jobs:
pip install -r requirements.txt
timeout-minutes: 5

- name: Run unit tests
run: python3 tests/test_mepo_commands.py -v
- name: Run tests
run: |
export PYTHONPATH=$(pwd)/src:$PYTHONPATH
python tests/test_mepo_commands.py -v
timeout-minutes: 5
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Converted `mepo` to a Python project via the following renaming
-- `mepo.d` -> `src/mepo`
-- `mepo.d/utest` -> `tests`
-- `doc` --> `docs`
-- Added `src/mepo/__init__.py`
-- Renamed `mepo.d` -> `src/mepo`
-- Renamed `mepo.d/utest` -> `tests`
-- Renamed `doc` --> `docs`
-- A `mepo` config file is now called a `mepo` registry
-- More code reorganization

- Helper script `mepo`, used for development, moved to the `bin` directory.

- Expanded testing to cover more `mepo` commands

## [1.52.0] - 2024-01-10

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mepo [![Actions Status](https://github.com/pchakraborty/mepo/workflows/Unit%20testing%20of%20mepo/badge.svg)](https://github.com/pchakraborty/mepo/actions) [![DOI](https://zenodo.org/badge/215067850.svg)](https://zenodo.org/badge/latestdoi/215067850)

`mepo` is a tool, written in Python3 (3.6.0+), to manage (m)ultiple git r(epo)sitories, by attempting to create an illusion of a 'single repository' for multi-repository projects. Please see the [Wiki](../../wiki) for examples of `mepo` workflows.
`mepo` is a tool, written in Python3 (3.9.0+), to manage (m)ultiple git r(epo)sitories, by attempting to create an illusion of a 'single repository' for multi-repository projects. Please see the [Wiki](../../wiki) for examples of `mepo` workflows.

## Commands

Expand Down
6 changes: 3 additions & 3 deletions bin/mepo
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import traceback
if sys.version_info < (3, 9, 0):
sys.exit('ERROR: Python version needs to be >= 3.9.0')

# Add direactory containing mepo to path
SRC_D = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'src')
# Add directory 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
from mepo.__main__ import main
main()
82 changes: 41 additions & 41 deletions docs/make_md_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,52 @@

import os
import io
import glob
from mdutils.mdutils import MdUtils
import subprocess as sp

preamble='''
preamble = """
mepo provides many different commands for working with a multi-repository fixture.
'''
"""

# Assume this script is in mepo/doc. Then we need to get to the mepo/mepo.d/command directory
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 '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')
# 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")

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

def get_command_list(directory):
# Walk the tree
roots = [x[0] for x in os.walk(directory)]

# Now remove "." from the list
roots = roots[1:]

# Just get the relative paths
rel_roots = [os.path.relpath(x,directory) for x in roots]

# Now exclude __pycache__
command_dirs = [x for x in rel_roots if '__pycache__' not in x]

# Convert slashes to spaces
all_commands = [x.replace('/',' ') for x in command_dirs]
def get_command_list(directory):
# Get all commands
all_commands_py = glob.glob(os.path.join(directory, "*.py"))
all_commands = [os.path.basename(x).replace(".py", "") for x in all_commands_py]
all_commands.remove("command") # manually remove

# Now let's find the commands that have subcommands
## First we get commands with spaces
commands_with_spaces = [x for x in all_commands if ' ' in x]
## Now let's just get the first elements
temp = [x.split()[0] for x in commands_with_spaces]
## Get the uniques
commands_with_subcommands = list(set(temp))

# Now remove those from our list
all_useful_commands = [x for x in all_commands if x not in commands_with_subcommands]
## First we get commands with underscore
## Then replace underscore with a space
commands_with_underscore = [x for x in all_commands if "_" in x]
commands_with_subcommands = [x.replace("_", " ") for x in commands_with_underscore]
all_useful_commands = [x for x in all_commands if x not in commands_with_underscore]
all_useful_commands += commands_with_subcommands

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()
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 All @@ -66,25 +58,32 @@ def create_markdown_from_usage(command, mdFile):

# Usage
usage = output_list[0]
usage = usage.replace('usage: ','')
usage = usage.replace("usage: ", "")
mdFile.new_header(level=3, title="Usage")
mdFile.insert_code(usage)

positional_arguments = output.partition('positional arguments:\n')[2].partition('\n\n')[0]
positional_arguments = output.partition("positional arguments:\n")[2].partition(
"\n\n"
)[0]
if positional_arguments:
mdFile.new_header(level=3, title="Positional Arguments")
mdFile.insert_code(positional_arguments)

optional_arguments = output.partition('optional arguments:\n')[2].partition('\n\n')[0]
optional_arguments = output.partition("optional arguments:\n")[2].partition("\n\n")[
0
]
# Remove extra blank lines
optional_arguments = os.linesep.join([s for s in optional_arguments.splitlines() if s])
optional_arguments = os.linesep.join(
[s for s in optional_arguments.splitlines() if s]
)
if optional_arguments:
mdFile.new_header(level=3, title="Optional Arguments")
mdFile.insert_code(optional_arguments)


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 @@ -94,8 +93,9 @@ def create_markdown_from_usage(command, mdFile):
command_list = get_command_list(command_dir_path)
for command in command_list:
mdFile.new_header(level=2, title=command)
create_markdown_from_usage(command,mdFile)
print(f"mepo command: {command}")
create_markdown_from_usage(command, mdFile)

mdFile.new_table_of_contents(table_title='Table of Contents', depth=2)
mdFile.new_table_of_contents(table_title="Table of Contents", depth=2)
mdFile.create_md_file()
print(f'Generated {doc_file}.')
print(f"Generated {doc_file}.")
51 changes: 51 additions & 0 deletions mepo.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- mode: python ; coding: utf-8 -*-

import os
import glob

cmd_dir = os.path.join(SPECPATH, 'src/mepo/command')
cmd_list = [os.path.basename(x).split('.')[0] for x in glob.glob(os.path.join(cmd_dir, '*.py'))]
hidden_imports = [f'mepo.command.{x}' for x in cmd_list if '_' not in x] # exclude subcommands
print(f'hidden_imports: {hidden_imports}')

a = Analysis(
['src/mepo/__main__.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=hidden_imports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='mepo',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='mepo',
)
Loading
Loading