Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create function to handle relative paths #1307

Merged
merged 5 commits into from
Apr 7, 2020

Conversation

gaffney2010
Copy link
Member

A lot of the file reads and writes are causing me problems because my IDE tries to run logic from the location where the file is located, and the code is written to only be run from the top-level directory. I could see a new user being thrown by this too.

This change makes paths a little more robust, by accounting for the path the user is actually in.

Copy link
Member

@drvinceknight drvinceknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, just the request for a test.

Out of curiosity any reason why you didn't use pathlib? (Not requesting you do, this works 👍)

axelrod/load_data_.py Outdated Show resolved Hide resolved
@marcharper
Copy link
Member

Although there's only really one or two places to use it here, +1 to pathlib in general. Check it out!

@gaffney2010
Copy link
Member Author

I've looked a bit at pathlib, and I'm not seeing a very clean way to do this.

I could do something like Path(file), then use other pathlib function to append "../" then axl_path. That doesn't seem cleaner though...

axelrod/load_data_.py Outdated Show resolved Hide resolved
@@ -45,7 +46,7 @@ def setUpClass(cls):
def test_big_tournaments(self, tournament):
"""A test to check that tournament runs with a sample of non-cheating
strategies."""
filename = "test_outputs/test_tournament.csv"
filename = axl_filename("test_outputs/test_tournament.csv")
Copy link
Member

@marcharper marcharper Apr 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also with pathlib, here you could do something like
filename = axl_filename() / "test_outputs" / "test_tournament.csv
assuming that axl_filename with no arguments just returns the right directory. This might be better for platform independence, since / and \ are used on different platforms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea to get it platform independent. But actually the cast to string needs to happen before applying the / operator. So this format wouldn't work.

What I did instead was take multiple arguments so that you could do:
axl_filename("test_outputs", "test_tournament.csv")
Then the function would apply the / operator inside.

@drvinceknight
Copy link
Member

This needs to be rebased on to master after #1308 got merged.

axelrod/load_data_.py Outdated Show resolved Hide resolved
Copy link
Member

@drvinceknight drvinceknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good, thanks for adding that test 👍

@marcharper
Copy link
Member

LGTM as well, please rebase so we can merge

@gaffney2010
Copy link
Member Author

LGTM as well, please rebase so we can merge

I merged recently. I'm seeing "This branch has no conflicts with the base branch". Is there something more I should do?

@drvinceknight
Copy link
Member

drvinceknight commented Apr 7, 2020

(Apologies if you know all this:) GitHub allows you to merge PRs in different ways. If we went for a merge commit, the icon looks like:

Screenshot 2020-04-07 at 10 36 30

If we wanted to rebase (which would be tidier), the icon looks like this:

Screenshot 2020-04-07 at 10 37 34

Usually that defaults to the last one you've used.

We don't really have a system/convention (I'd suggest mainly due to my poor knowledge of version control at the start of this project that means our history is pretty messy) but from @marcharper's comment I assumed he wanted a rebase merge :) (In which case if you rebase on master and force push we'll be able to click that.)

@marcharper
Copy link
Member

Either way is fine with me

@drvinceknight drvinceknight merged commit f7244e6 into Axelrod-Python:master Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants