Switch to proper setuptools-based structure.
This commit is contained in:
parent
2e1c7455e5
commit
6034a07901
138
.gitignore
vendored
Normal file
138
.gitignore
vendored
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__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/
|
19
README.md
19
README.md
@ -8,10 +8,21 @@ MapEdit is a command-line tool written in Python for relatively fast manipulatio
|
|||||||
|
|
||||||
MapEdit is currently in the beta stage, and like any code, it may have bugs. Use it at your own risk.
|
MapEdit is currently in the beta stage, and like any code, it may have bugs. Use it at your own risk.
|
||||||
|
|
||||||
## Requirements
|
## Installation
|
||||||
|
|
||||||
- Python 3 (If you don't already have it, download it from [python.org](https://www.python.org).)
|
MapEdit required Python 3.8 or higher. NumPy will also be installed if it isn't already.
|
||||||
- NumPy, which can be installed with `pip install numpy`.
|
|
||||||
|
First, download MapEdit from [here](https://github.com/random-geek/MapEdit/archive/master.zip) or by using `git clone`.
|
||||||
|
If you downloaded the zip file, unzip it into a new directory.
|
||||||
|
|
||||||
|
Then, open a terminal/command prompt/PowerShell window in the MapEdit directory and run:
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install --upgrade setuptools
|
||||||
|
python setup.py install
|
||||||
|
```
|
||||||
|
|
||||||
|
This will install MapEdit as a script/executable which can be run from anywhere.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -24,7 +35,7 @@ Most commands require mapblocks to be already generated to work. This can be ach
|
|||||||
|
|
||||||
#### General usage
|
#### General usage
|
||||||
|
|
||||||
`python mapedit.py [-h] -f <file> [--no-warnings] <command>`
|
`mapedit [-h] -f <file> [--no-warnings] <command>`
|
||||||
|
|
||||||
#### Arguments
|
#### Arguments
|
||||||
|
|
||||||
|
5
mapedit/__init__.py
Normal file
5
mapedit/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
"""Edit Minetest map database files."""
|
||||||
|
|
||||||
|
__version__ = "0.1.0-dev"
|
||||||
|
__author__ = "random-geek"
|
||||||
|
__license__ = "LGPL-3.0"
|
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import argparse
|
import argparse
|
||||||
from lib import commands
|
from . import commands, __version__
|
||||||
# TODO: Fix file structure, add setuptools?
|
|
||||||
|
|
||||||
|
|
||||||
|
# Define arguments.
|
||||||
ARGUMENT_DEFS = {
|
ARGUMENT_DEFS = {
|
||||||
"p1": {
|
"p1": {
|
||||||
"always_opt": True,
|
"always_opt": True,
|
||||||
@ -116,48 +116,53 @@ ARGUMENT_DEFS = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialize parsers.
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
def run_cmdline():
|
||||||
description="Edit Minetest map database files.",
|
"""Run MapEdit as a command-line script."""
|
||||||
epilog="Run `mapedit.py <command> -h` for command-specific help.")
|
|
||||||
|
|
||||||
parser.add_argument("-f",
|
# Initialize parsers.
|
||||||
required=True,
|
parser = argparse.ArgumentParser(
|
||||||
dest="file",
|
description="Edit Minetest map database files.",
|
||||||
metavar="<file>",
|
epilog="Run `mapedit.py <command> -h` for command-specific help.")
|
||||||
help="Path to primary map file")
|
|
||||||
parser.add_argument("--no-warnings",
|
|
||||||
dest="no_warnings",
|
|
||||||
action="store_true",
|
|
||||||
help="Don't show warnings or confirmation prompts.")
|
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(dest="command", required=True,
|
parser.add_argument("-f",
|
||||||
help="Command (see README.md for more information)")
|
required=True,
|
||||||
|
dest="file",
|
||||||
|
metavar="<file>",
|
||||||
|
help="Path to primary map file")
|
||||||
|
parser.add_argument("--no-warnings",
|
||||||
|
dest="no_warnings",
|
||||||
|
action="store_true",
|
||||||
|
help="Don't show warnings or confirmation prompts.")
|
||||||
|
parser.add_argument("--version",
|
||||||
|
action="version",
|
||||||
|
version="%(prog)s " + __version__)
|
||||||
|
|
||||||
for cmdName, cmdDef in commands.COMMAND_DEFS.items():
|
subparsers = parser.add_subparsers(dest="command", required=True,
|
||||||
subparser = subparsers.add_parser(cmdName, help=cmdDef["help"])
|
help="Command (see README.md for more information)")
|
||||||
|
|
||||||
for arg, required in cmdDef["args"].items():
|
for cmdName, cmdDef in commands.COMMAND_DEFS.items():
|
||||||
argsToAdd = ("p1", "p2") if arg == "area" else (arg,)
|
subparser = subparsers.add_parser(cmdName, help=cmdDef["help"])
|
||||||
|
|
||||||
for argToAdd in argsToAdd:
|
for arg, required in cmdDef["args"].items():
|
||||||
argDef = ARGUMENT_DEFS[argToAdd]
|
argsToAdd = ("p1", "p2") if arg == "area" else (arg,)
|
||||||
|
|
||||||
if "always_opt" in argDef and argDef["always_opt"]:
|
for argToAdd in argsToAdd:
|
||||||
# Always use an option flag, even if not required.
|
argDef = ARGUMENT_DEFS[argToAdd]
|
||||||
subparser.add_argument("--" + argToAdd, required=required,
|
|
||||||
**argDef["params"])
|
if "always_opt" in argDef and argDef["always_opt"]:
|
||||||
else:
|
# Always use an option flag, even if not required.
|
||||||
if required:
|
subparser.add_argument("--" + argToAdd, required=required,
|
||||||
subparser.add_argument(argToAdd, **argDef["params"])
|
|
||||||
else:
|
|
||||||
subparser.add_argument("--" + argToAdd, required=False,
|
|
||||||
**argDef["params"])
|
**argDef["params"])
|
||||||
|
else:
|
||||||
|
if required:
|
||||||
|
subparser.add_argument(argToAdd, **argDef["params"])
|
||||||
|
else:
|
||||||
|
subparser.add_argument("--" + argToAdd, required=False,
|
||||||
|
**argDef["params"])
|
||||||
|
|
||||||
# Handle the actual command.
|
# Handle the actual command.
|
||||||
|
args = commands.MapEditArgs()
|
||||||
args = commands.MapEditArgs()
|
parser.parse_args(namespace=args)
|
||||||
parser.parse_args(namespace=args)
|
inst = commands.MapEditInstance()
|
||||||
inst = commands.MapEditInstance()
|
inst.run(args)
|
||||||
inst.run(args)
|
|
28
setup.py
Normal file
28
setup.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import setuptools
|
||||||
|
import mapedit
|
||||||
|
|
||||||
|
|
||||||
|
def get_long_desc():
|
||||||
|
with open("README.md", "r") as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
name="mapedit",
|
||||||
|
version=mapedit.__version__,
|
||||||
|
description=mapedit.__doc__.strip(),
|
||||||
|
long_description=get_long_desc(),
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
author=mapedit.__author__,
|
||||||
|
url="https://github.com/random-geek/MapEdit",
|
||||||
|
license=mapedit.__license__,
|
||||||
|
|
||||||
|
packages=setuptools.find_packages(),
|
||||||
|
entry_points={
|
||||||
|
"console_scripts": [
|
||||||
|
"mapedit = mapedit.cmdline:run_cmdline"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
python_requires=">=3.8",
|
||||||
|
install_requires="numpy"
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user