Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 3 [4] 5

Author Topic: PyDwarf 1.1.4: Werebeast  (Read 36373 times)

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf 1.1.0: Chalcedony
« Reply #45 on: January 22, 2016, 03:48:20 pm »

One question though, or suggestion for the documentation. I'm a definitely Python newbie, I've dabbled enough to know the syntax but I've never developed anything serious with it. I understand how to call scripts through manager.py well enough, so I think the documentation is great there, btw :)

Thanks so much for your interest!

Developing the scripts that come with PyDwarf was a lot of trial and error for me, too, though I like to think I usually got things right the first time. (I didn't.)

To test scripts, in a console located at PyDwarf's root directory I ran python, then import raws, pydwarf; df = pydwarf.df(raws) - that pydwarf.df command should load your settings from your configuration files, though you can also manually specify settings by passing them as arguments to that function. Then I'd call one of my scripts using syntax like this: print pydwarf.scripts.pineapple.noexotic(df), or maybe I'd just step through some code manually. (You can pass named arguments to your script when you run it that way, I should mention.) And then I'd print information to the console that ought to have been changed by the script so I could check up on how things were working. I could also run df.reset() and then run it all over again, perhaps after making some manual changes to the raws to see how the script contended with them. (But you'll have to restart the python console and start over again if you make changes to your script. As inconvenient as this is, I couldn't find another reliable way to reload modified scripts!)

For example, on one occasion that I was testing a script this way, my console looked something like this:

Code: [Select]
>>> import raws, pydwarf; df = pydwarf.df(raws)
>>> print df.getobj('CREATURE:TIGER').list(range=12, skip=False)
[CREATURE:TIGER]
    [DESCRIPTION:A huge, striped predator.  It is found in almost any climate on a lone hunt for its prey.]
    [NAME:tiger:tigers:tiger]
    [CASTE_NAME:tiger:tigers:tiger]
    [CHILD:3][GENERAL_CHILD_NAME:tiger cub:tiger cubs]
    [CREATURE_TILE:'T'][COLOR:6:0:1]
    [PETVALUE:200]
    [PET_EXOTIC]
    [MOUNT_EXOTIC]
    [TRAINABLE]
>>> print pydwarf.scripts.pineapple.noexotic(df)
SUCCESS: Replaced 303 PET_EXOTIC and 150 MOUNT_EXOTIC tokens.
>>> print len(df.all(value_in=['PET_EXOTIC', 'MOUNT_EXOTIC']))
0
>>> print df.getobj('CREATURE:TIGER').list(range=12, skip=False)
[CREATURE:TIGER]
    [DESCRIPTION:A huge, striped predator.  It is found in almost any climate on a lone hunt for its prey.]
    [NAME:tiger:tigers:tiger]
    [CASTE_NAME:tiger:tigers:tiger]
    [CHILD:3][GENERAL_CHILD_NAME:tiger cub:tiger cubs]
    [CREATURE_TILE:'T'][COLOR:6:0:1]
    [PETVALUE:200]
    [PET]
    [MOUNT]
    [TRAINABLE]

I turned this into a unit test. You can find that exact snippet, except for the top line with the imports and such, in docs/examples/scripts.pineapple.txt. You can make your own file in that directory containing unit tests for your own scripts, and then run all the tests in that directory using docs/bin/verify.py. I'm not sure whether I actually documented anywhere how this works, but I can summarize:

I copied that console text wholesale, save for the topmost line, and pasted it into that unit test file. Violà, it became an actual unit test where the commands are run and the output I verified here is compared to the output given after, say, I made some changes to the code or to the script. The verify.py script will helpfully let you know whether the test passed or failed and, if it failed, it will tell you where and why. I used this to do some test-driven development, as well as testing code that was already written.

There's some special formatting going on mainly so that the code snippets in these unit test files can also be used in the HTML documentation, but you won't need to worry about that much. It's the three lines you see above every unit test in those files. Your three lines will probably look like this - sans the comments.

Code: [Select]
# The name of the script you're testing goes here
pydwarf.scripts.pineapple.noexotic
# For thoroughness' sake I listed all the API commands I called here in case it was useful in the generated docs, but you can leave this line blank
raws.queryableobj.getobj raws.queryable.all raws.tokenlist.__len__ pydwarf.registrar.__getattr__
# Putting "reset" here, as opposed to a blank line, means the DF directory is reloaded so that the following test has a clean slate to work with. You probably want to do this for every test.
reset

I last worked with this code months ago and my memory is fuzzy and I can almost guarantee I've made some mistakes and terribly mislead you regarding how to best test your scripts. But I hope I've helped answer your question and put you on the right track, and I am more than happy to work with you if you run into any more obstacles.

« Last Edit: January 22, 2016, 03:56:28 pm by madk »
Logged

Xinael

  • Bay Watcher
    • View Profile
Re: PyDwarf 1.1.0: Chalcedony
« Reply #46 on: January 26, 2016, 03:22:55 pm »

Should be really useful, thanks :)
Logged

Eagleon

  • Bay Watcher
    • View Profile
    • Soundcloud
Re: PyDwarf 1.1.0: Chalcedony
« Reply #47 on: February 01, 2016, 08:59:23 am »

This will finally realize my lifelong dream of recursively feeding the description, name, etc. tags through a Markov chain chatbot like pyborg! So that's something. Will let you know how it goes if I don't get randomly distracted by some other project like usual.
« Last Edit: February 01, 2016, 09:02:39 am by Eagleon »
Logged
Agora: open-source, next-gen online discussions with formal outcomes!
Music, Ballpoint
Support 100% Emigration, Everyone Walking Around Confused Forever 2044

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf 1.1.0: Chalcedony
« Reply #48 on: February 01, 2016, 09:23:29 am »

This will finally realize my lifelong dream of recursively feeding the description, name, etc. tags through a Markov chain chatbot like pyborg! So that's something. Will let you know how it goes if I don't get randomly distracted by some other project like usual.

I look forward to seeing what you make!

Fetching a list of all the description tags, for example, could hardly be easier, using the raws package included with PyDwarf:

Code: [Select]
import raws
df = raws.dir('df_path/raw/objects')
descriptions = [token.args[0] for token in df.all('DESCRIPTION')]
« Last Edit: February 01, 2016, 09:32:39 am by madk »
Logged

Xinael

  • Bay Watcher
    • View Profile
Re: PyDwarf 1.1.0: Chalcedony
« Reply #49 on: February 01, 2016, 03:31:55 pm »

Just got round to playing around with this: import pydwarf fails because as __init__.py runs, it imports quick, which imports session, which imports config, which finally imports yaml - but this fails because it can't find the yaml library. I had to move it from /libs/ into /pydwarf/ and then it'd run. Maybe this is a weirdness about my setup, but that's what I had to do so I thought I'd let you know :)
Logged

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf 1.1.0: Chalcedony
« Reply #50 on: February 01, 2016, 03:44:02 pm »

Oh, shame on me for not having caught that. Copying the lib/yaml/ dir into the pydwarf/ dir will work perfectly well, but you can also run pip install pyyaml or add PyDwarf's lib/yaml/ directory to your PYTHONPATH.

edit: Actually, I pushed a cleaner fix to the PyDwarf repository's develop branch as to avoid this problem in the future. Thank you for pointing it out!
« Last Edit: February 01, 2016, 03:57:40 pm by madk »
Logged

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf 1.1.0: Chalcedony
« Reply #51 on: May 11, 2016, 05:16:53 pm »

Just letting everyone know that with the DF update PyDwarf should continue to function as expected, and off the top of my head none of the recent changes should break any of the scripts packaged with PyDwarf.

I've been thinking about ways to make PyDwarf more accessible by creating a UI for configuring and running it for people who are scared of a CLI, and maybe I'll get to that soonish. (But I'm not making any promises.) Keep an eye out!

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf 1.1.1: Goblins
« Reply #52 on: May 05, 2017, 07:22:59 am »

Here's a surprise: PyDwarf has just received a new minor release.

I'm getting back into playing DF after a long hiatus. I went to install my customary mods, and was very pleased to find that PyDwarf was still working as intended! ...With the notable exception of an issue arising from how PyDwarf determined script compatibility with Dwarf Fortress versions. This release isn't a very elegant fix, but it will suffice, and it makes PyDwarf less clunky to use for 0.40+ DF versions.

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf 1.1.1: Goblins
« Reply #53 on: May 21, 2017, 06:03:25 am »

Extended Agriculture is now part of PyDwarf! You can view the mod online here, converted to work with a broad range of DF versions and to be more compatible with other plant-modifying mods.

With this and some other additions and improvements, a new v1.1.2 release of PyDwarf is now available for download!

The next step is probably to add some kind of a graphical interface to make PyDwarf easier for players to install mods, since the current CLI interface might be a bit intimidating for newcomers. Is there anyone who might be interested in working with me to make something like that?
« Last Edit: May 21, 2017, 06:23:12 am by madk »
Logged

Bearskie

  • Bay Watcher
  • Nyam nyam
    • View Profile
Re: PyDwarf 1.1.3: Flux Stone
« Reply #54 on: September 18, 2017, 01:45:21 am »

I've tried many times, but I just can't seem to get the pineapple.diff script to work. For starters, I'm not even sure whether I'm passing the right args. It would be nice if there was a usage case example somewhere for what is probably the most interesting script in the bunch... (diff-based mod merging)

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf 1.1.3: Flux Stone
« Reply #55 on: September 18, 2017, 07:11:55 am »

I've tried many times, but I just can't seem to get the pineapple.diff script to work. For starters, I'm not even sure whether I'm passing the right args. It would be nice if there was a usage case example somewhere for what is probably the most interesting script in the bunch... (diff-based mod merging)

Hi, I'm busy as heck this week but I will see if I can't put a proper tutorial together when I get the chance.

pineapple.diff isn't more spectacularly presented because it's so limited. Diff-based merging of mods is also a lot more failure-prone than PyDwarf's normal mod tools. So some things to keep in mind:

- pineapple.diff absolutely must be the first mod in your list. It cannot be run after any other mod, or be run multiple times and still function correctly. (You can pass more than one mod path to merge, though.)

- The mods you input must have been made for the same version of Dwarf Fortress that you're playing, otherwise the raws differences from one version to another will screw up the merging.

- Looking at the script I can't immediately remember whether the paths to mods should be paths to raws directories or paths to directories like "df_osx_40_23/" with the mod's raw directory inside. If you've got the other things right and it's still not working, try messing around with the mod paths.

- Also if all of that isn't enough to figure it out, give me more information about how it's failing and I'll do what I can to help. e.g. is PyDwarf giving you an error? Is it making the wrong changes to your DF install? Is it making no changes at all?



Bearskie

  • Bay Watcher
  • Nyam nyam
    • View Profile
Re: PyDwarf 1.1.3: Flux Stone
« Reply #56 on: September 19, 2017, 04:36:33 am »

Oh hi, didn't expect such a quick response. To clarify,  it's the only script I'm running, with args: {'paths':['C:\<yadda yadda yadda>\mod_folder']}. The mod folder contains a small set of raws, conflicting and non-conflicting. The console claims to have 'Merged 1 mod successfully with no conflicts', but none of the files are found in the df-output directory. Nothing seems to have happened at all.

No rush needed, I suspect its my args at fault, but I've tried many different alterations and am still stumped.
« Last Edit: September 19, 2017, 04:53:30 am by Bearskie »
Logged

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf 1.1.3: Flux Stone
« Reply #57 on: September 19, 2017, 09:01:13 am »

Could you give me a link to download your mod_folder?

Bearskie

  • Bay Watcher
  • Nyam nyam
    • View Profile
Re: PyDwarf 1.1.3: Flux Stone
« Reply #58 on: September 19, 2017, 09:13:46 am »

Sure, check your PM.

CharlesDorf

  • Escaped Lunatic
    • View Profile
Re: PyDwarf 1.1.3: Flux Stone
« Reply #59 on: October 01, 2017, 05:46:18 pm »

I believe I have done everything but when I go to run the python manager.py it just flickers and turns off. Did I miss anything?
Logged
Pages: 1 2 3 [4] 5