0

This is my file structure:

requirements.txt
Procfile
Chess/
      -- lichess-bot/
                     -- lichess-bot.py
                     -- config.yml
                     -- (many other files related to lichess-bot.py)

The part responsible to open the YAML in config.py:

def load_config(config_file):
    with open(config_file) as stream:
        try:
            CONFIG = yaml.load(stream)
        except Exception as e:
            print("There appears to be a syntax problem with your config.yml")
            raise e

And in lichess-bot.py here is the call for the config.yml:

CONFIG = load_config(args.config or "./config.yml")

The commands I need to execute are

  1. chmod +x ./engines/stockfish_10_x64
  2. python lichess-bot.py -u

I tried this in Heroku bash: python ./chess/lichess-bot/lichess-bot.py -u but it returns

FileNotFoundError: [Errno 2] No such file or directory: './config.yml'

I tried this Procfile:

worker: cd chess
worker: cd lichess-bot
worker: chmod +x ./engines/stockfish_10_x64
worker: python lichess-bot.py -u

but Heroku couldn't recognize it.

If I do this manually:

~ $ cd chess
~/chess cd lichess-bot
~/chess/lichess-bot python lichess-bot.py -u

it work perfectly

How to access directories from Procfile and then execute the file without errors?

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
Moha369
  • 815
  • 7
  • 16
  • The problem isn't what you think it is. How are you trying to use `config.yml`? Please [edit] your question and show that part of your code. – ChrisGPT was on strike Jun 16 '19 at 23:19
  • (Also, note that `Chess` ≠ `chess`. But I think the one with the capital in your question is a typo, and this is unrelated to your problem.) – ChrisGPT was on strike Jun 16 '19 at 23:19
  • Check this repo, github.com/careless25/lichess-bot its the repo i forked, the config.yml.default we should copy and put it in config.yml just. – Moha369 Jun 16 '19 at 23:22
  • I will edit the question with the config now – Moha369 Jun 16 '19 at 23:22
  • Questions on SO should be self-contained. We're not going to go off-site to understand this. Please do edit your question as you say you will. – ChrisGPT was on strike Jun 17 '19 at 00:30
  • Well sorry i am on phone, i cant copy the code from github. But will try to do so right now – Moha369 Jun 17 '19 at 00:31
  • Provided the config.yml @Chris – Moha369 Jun 17 '19 at 00:33
  • I'm not asking for your `config.yml`. I'm asking for the code that _uses_ it. How are you opening it? I'm guessing that code assumes the file is in your working directory. – ChrisGPT was on strike Jun 17 '19 at 00:35
  • 1
    And looking at the repo you mentioned it looks like you've added two extra levels of directory nesting. Why did you do that? – ChrisGPT was on strike Jun 17 '19 at 00:37
  • Well its required in the README.md – Moha369 Jun 17 '19 at 00:37
  • What does "Well its required in the README.md" mean? What does that have to do with anything? Please take a moment to read [ask]. The clearer you are, the better your chance of getting a helpful answer. – ChrisGPT was on strike Jun 17 '19 at 00:38
  • If you saw lichess-bot.py its required to make in inside a folder called chess if not i have to track every line in the programs and change it. Thats why we use this, i followed the README.md, and about the question, i asked a clear question, how to get inside a directory from a Procfile so no need to know what is the code when i tell you it works manually but not from Procfile – Moha369 Jun 17 '19 at 00:42
  • Again, "how to get inside a directory from a Procfile" _is **not the problem**_. Also again, I'm not going to dig through a bunch of off-site source code but when I looked I didn't see anything requiring you to add directories. I'm pretty sure you're wrong about that, too. I'm pretty sure the problem is that whatever you're doing with `config.yml` can't find _that_ file. That's what I'm asking to see. Your code file is being found just fine. _Please_ cooperate with people trying to help you. Being stubborn doesn't help anybody. – ChrisGPT was on strike Jun 17 '19 at 00:46
  • Also, I don't think you understand what the `Procfile` does. It's not a script. Trying to `cd`, `chmod`, and run your script doesn't make any sense there. This file should _just_ define process types. Probably `web` and / or `worker`. This is quite clear in the documentation. – ChrisGPT was on strike Jun 17 '19 at 00:47
  • And thats why i asked, i tried to do this and i saw i failed so i came to the devs like you to seek help. And about the lichess-bot.py, mine is the same as in the repo, and i want ask you a question, will a copy of a `config.yml` in the root directory help ? With slight editing in navigation inside `config.yml` like the engine directory and book directory ? – Moha369 Jun 17 '19 at 00:50
  • For the _third (and **last**)_ time, **we're not going to go off-site to read through code**. Please add the relevant part (not the whole file) _**here in your question**_. We want to see a [mcve]. Moving the config to the root of the repo might help, but if you refuse to show us the code we can't answer for sure. You almost certainly created this problem yourself by unnecessarily adding extra directories. – ChrisGPT was on strike Jun 17 '19 at 00:51
  • And how should i show you the code, keep editing this post ?? Or what ? It will not be an organised question if i add things because there is no errors in the codes please understand me – Moha369 Jun 17 '19 at 00:58
  • Yes, by editing the question. You can take things out, too. I don't think the contents of `config.yml` are relevant, for example. – ChrisGPT was on strike Jun 17 '19 at 01:00
  • Edited, hope its better now – Moha369 Jun 17 '19 at 01:05

1 Answers1

1

The code defaults to a configuration file in the current directory named config.yml:

CONFIG = load_config(args.config or "./config.yml")

You can move your config.yml to the root of your repository, or you can provide args.config. It looks like that can be done with --config.

Your Procfile should just define process types. They're not scripts, and they shouldn't contain many "steps". Something like

worker: python lichess-bot.py --config chess/lichess-bot/config.yml -u

should work (assuming your directory is actually called chess/ and not Chess/). If you need to make the engine executable, consider doing that locally and committing it as an executable file.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257