Browse Source

WIP: setup.py + updated README

pull/1/head
Michaël Costa 7 months ago
parent
commit
c86ae517db
10 changed files with 131 additions and 60 deletions
  1. +0
    -0
      LICENSE
  2. +28
    -0
      Makefile
  3. +49
    -29
      README.md
  4. +3
    -0
      ants.yml
  5. +6
    -9
      ants/__init__.py
  6. +1
    -2
      objects/ant.py
  7. +3
    -0
      requirements.txt
  8. +37
    -0
      setup.cfg
  9. +4
    -0
      setup.py
  10. +0
    -20
      tests/tmp.py

LICENSE.TXT → LICENSE View File


+ 28
- 0
Makefile View File

@ -0,0 +1,28 @@
BUILD_PATH=./build
DIST_PATH=./dist
EGG_INFO_PATH=./ants.egg-info
SETUPCFG=./setup.cfg
VERSION=$(shell grep version ${SETUPCFG} | awk '{print $$3}')
.RECIPEPREFIX +=
.PHONY: distclean install uninstall update dist
distclean:
sudo rm -Rf ${BUILD_PATH}
sudo rm -Rf ${DIST_PATH}
sudo rm -Rf ${EGG_INFO_PATH}
find ./ -type d -name "*__pycache__" -exec rm {} \;
find ./ -type f -name "*.pyc" -exec rm {} \;
dist:
sudo python3 ./setup.py bdist_wheel
update: | distclean uninstall install
install:
sudo python3 ./setup.py install bdist_wheel
mkdir -p "${HOME}/.config/.ants"
if [ ! -f "${HOME}/.config/.ants/ants.yml" ]; then cp -v ./ants.yml "${HOME}/.config/.ants"; fi
uninstall:
sudo python3 -m pip uninstall -y ants

+ 49
- 29
README.md View File

@ -7,11 +7,11 @@
## Disclaimer
This module is intended to run as a python3 module and is provided AS IS under the WTFPL (See LICENSE.TXT).
This module is intended to run as a _Python3_ module and is provided AS IS under the WTFPL (See LICENSE).
This module has been tested on Linux and OpenBSD systems **ONLY**.
However it uses python3 standard modules only and it may run on Windows or MacOS.
However it may run on all platforms supported by both _Python3_ and _SDL2_
Your Mileage May Vary.
@ -20,73 +20,93 @@ Your Mileage May Vary.
This programm is a pure **C**omputer **A**ssisted **B**ullshiting project trying to demonstrate that ants **may** have a life based on random and basic reflexes only.
It also provides a way to understand python multi-thread programming and inter-process communications.
It also provides a way to understand the _Python3 SDL2_ library.
This project is **NOT** science, it's **CAB**.
## TODO
* ~~A convenient way to close the application and all its threads (See 'Run the application') !~~
* Multiple farms on same map
* War between different ant factions
* Ant subclasses (worker, warrior, ...)
* Allow swarming when farm reach a number of individuals
* SDL2 implementation
## Install from file:
* Copy the module directory in any directory of your home dir.
## Requirements
This program requires the _Python3_ `setuptools` module to be installed.
You may install the module using `pip`
```bash
$ sudo python3 -m pip install setuptools
```
## Install from github
Clone the Github repository with the followning command
```
```bash
$ git clone https://github.com/doug-letough/ants.git ants
```
Use provided `Makefile` to install _ants_ and all its requirements (needs the _setuptools_ python module and _sudo_ permissions)
## Configuration
```bash
$ cd ants
$ make install
```
You'll find a bunch of parameters to play with in the application configuration file `config.py`.
## Uninstall
Default values will do fine.
If _ants_ has been installed with the provided `Makefile`, you should use the following command
```bash
$ cd ants
$ make uninstall
```
## Run the Ants application
## Update
Run the following commands
Keep your _ants_ installation up to date using the following set of commands
```bash
$ cd ants
$ python -m ants
$ git pull origin master
$ make update
```
**This application is a massively multi-threaded program**.
Note that some updates may provides breaking changes, you may have to adjust your existing configuration file.
Closing the main window SHOULD exit the application.
In case the application does not quit properly, run the following command to ensure that all remaining processes are killed:
## Configuration
```bash
$ kill -15 $(ps aux | grep "python -m ants" | grep -v grep | awk -F ' ' '{print $2}')
```
You'll find a bunch of parameters to play with in the application configuration file `ants.yml`.
## Logging
This file can be found in the `${HOME}/.config/ants` directory and, if the `Makefile` was used, it shoud have been
copied there at install time.
This application logs many things to stderr.
In most case, default values will do fine and mostly have _self explainatory_ names.
If you want to keep the logs of your runs, start the application with the following command:
If you're experiencing problems with the `DejaVuSansMono.ttf` like
```
$ python -m ants 2>&1 | tee -a ants.log
```bash
OSError: Cannot find /usr/share/fonts/TTF/DejaVuSansMono.ttf
```
This will still display the log to stderr and log this output to the ants.log file.
Please adjust your configuration according to your setup (the `sdl::font::filename` configuration parameter be a valid
full path to a _True Type Font_).
```yaml
sdl:
font:
filename: /usr/share/fonts/TTF/DejaVuSansMono.ttf
```
## Uninstall
## Run the Ants application
Once installed, run the application by executing the following command in any terminal
Simply remove the module directory.
```bash
$ python -m ants
```

+ 3
- 0
ants.yml View File

@ -26,6 +26,9 @@ coloredlogs:
color: cyan
message:
color: white
# ----------------------------------------------------------------------------------------------------------------------
# -- Do not touch any parameters above this line if you don't know what you are doing ----------------------------------
# ----------------------------------------------------------------------------------------------------------------------
sdl:
font:
filename: /usr/share/fonts/TTF/DejaVuSansMono.ttf


ants_sdl.py → ants/__init__.py View File

@ -1,11 +1,10 @@
#!/bin/env python3
import os
import sys
import sdl2
import sdl2.ext
import sdl2.sdlgfx
import logging
import log
import conf
import renderer
@ -16,14 +15,11 @@ from applicators import CollisionSystem
def run(config):
logging.info("Starting...")
sdl2.ext.init()
window = sdl2.ext.Window("Ants: A Computer Assisted Bullshit for random based life form research",
size=(config["sdl"]["playground"]["width"], config["sdl"]["playground"]["height"]))
window.show()
world = sdl2.ext.World()
movement_sys = MovementSystem(0,
config["sdl"]["dashboard"]["height"],
@ -95,7 +91,8 @@ def run(config):
sdl2.SDL_Delay(delay)
if __name__ == "__main__":
config = conf.load_config("ants.yml")
logger = log.logger_config(config)
sys.exit(run(config))
USER_HOME_DIR = os.environ["HOME"]
config_filename = os.path.join(USER_HOME_DIR, ".config", ".ants", "ants.yml")
config = conf.load_config(config_filename)
logger = log.logger_config(config)
sys.exit(run(config))

+ 1
- 2
objects/ant.py View File

@ -1,4 +1,3 @@
import logging
from objects import BaseObject, Velocity, Direction, History, Life, Size, Food, Status
SIZE = Size(3, 3)
@ -57,7 +56,7 @@ class Ant(BaseObject):
def hail(self, other):
if isinstance(other, self.__class__):
hail_status = "{}: {} / {}: {}".format(self.uuid, self.get_status(), other.uuid, other.get_status())
# hail_status = "{}: {} / {}: {}".format(self.uuid, self.get_status(), other.uuid, other.get_status())
return True
return False


+ 3
- 0
requirements.txt View File

@ -0,0 +1,3 @@
PySDL2 >= 0.9.7
PyYAML >= 5.3.1
coloredlogs >= 10.0

+ 37
- 0
setup.cfg View File

@ -0,0 +1,37 @@
[metadata]
version = 1.0.2
license = WTFPL
classifiers =
Programming Language :: Python :: 3
License :: WTFPL
Operating System :: POSIX :: Linux
license_files = LICENSE
url = https://git.mcos.nc/python/ants
description = "A Computer Assisted Bullshit for random based life form research"
name = ants
long_description = file: README.md
long_description_content_type = text/markdown
author = Michaël Costa
author_email = michael.costa@mcos.nc
[bdist_wheel]
universal=1
[options]
packages = find:
include_package_data = True
zip_safe = False
install_requires=
PySDL2>=0.9.7
PyYAML>=5.3.1
coloredlogs>=10.0
[flake8]
ignore =
W0703,
W1202,
E111,
E501,
C0103,
E114
max-complexity = 10

+ 4
- 0
setup.py View File

@ -0,0 +1,4 @@
#!/bin/env python3
from setuptools import setup
setup()

+ 0
- 20
tests/tmp.py View File

@ -1,20 +0,0 @@
LOST = {True: '1', False: '0'}
LOADED = {True: '1', False: '0'}
OTWB = {True: '1', False: '0'}
for lost in LOST:
for loaded in LOADED:
for otwb in OTWB:
# result = int(LOST[lost], 2) + int(LOADED[loaded], 2) + int(OTWB[otwb], 2)
result = "{}{}{}".format(int(otwb), int(loaded), int(lost))
print("OTWB: {} / Loaded: {} / lost: {} / Status: {}".format(otwb, loaded, lost, int(result, 2)))
# OTWB: True / Loaded: True / lost: True / Status: 7
# OTWB: True / Loaded: True / lost: False / Status: 6
# OTWB: True / Loaded: False / lost: True / Status: 5
# OTWB: True / Loaded: False / lost: False / Status: 4
# OTWB: False / Loaded: True / lost: True / Status: 3
# OTWB: False / Loaded: True / lost: False / Status: 2
# OTWB: False / Loaded: False / lost: True / Status: 1
# OTWB: False / Loaded: False / lost: False / Status: 0

Loading…
Cancel
Save