Switch to proper setuptools-based structure.

This commit is contained in:
random-geek 2020-07-01 16:34:44 -07:00
parent 2e1c7455e5
commit 6034a07901
10 changed files with 230 additions and 43 deletions

138
.gitignore vendored Normal file
View 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/

View File

@ -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

View File

5
mapedit/__init__.py Normal file
View File

@ -0,0 +1,5 @@
"""Edit Minetest map database files."""
__version__ = "0.1.0-dev"
__author__ = "random-geek"
__license__ = "LGPL-3.0"

View File

@ -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,8 +116,11 @@ ARGUMENT_DEFS = {
}, },
} }
# Initialize parsers.
def run_cmdline():
"""Run MapEdit as a command-line script."""
# Initialize parsers.
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Edit Minetest map database files.", description="Edit Minetest map database files.",
epilog="Run `mapedit.py <command> -h` for command-specific help.") epilog="Run `mapedit.py <command> -h` for command-specific help.")
@ -131,6 +134,9 @@ parser.add_argument("--no-warnings",
dest="no_warnings", dest="no_warnings",
action="store_true", action="store_true",
help="Don't show warnings or confirmation prompts.") help="Don't show warnings or confirmation prompts.")
parser.add_argument("--version",
action="version",
version="%(prog)s " + __version__)
subparsers = parser.add_subparsers(dest="command", required=True, subparsers = parser.add_subparsers(dest="command", required=True,
help="Command (see README.md for more information)") help="Command (see README.md for more information)")
@ -156,7 +162,6 @@ for cmdName, cmdDef in commands.COMMAND_DEFS.items():
**argDef["params"]) **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()

28
setup.py Normal file
View 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"
)