JohnSundell / Marathon

[DEPRECATED] Marathon makes it easy to write, run and manage your Swift scripts 🏃
MIT License
1.86k stars 78 forks source link

latestMajorVersionForPackage fails if url has the form ~/Documents/somepath/Package #135

Open jazzbox opened 7 years ago

jazzbox commented 7 years ago

Marathon currently does not support local packages with a tilde in the path:

import HTMLParser // marathon:~/Documents/somepath/HTMLParser

I am not quite sure where the patch should land, in Marathon itself:

class PackageManager {
    private func latestMajorVersionForPackage(at url: URL) throws -> Int {
        ....
        let releases = try perform(Releases.versions(for: url.expandPath).withoutPreReleases(),
                                   orThrow: Error.failedToResolveLatestVersion(url))
        ....
    }
}

or in the Releases package:

class Releases {    
    private static func string(from url: URL) throws -> String {
        ....
        let path = url.absoluteString.replacingOccurrences(of: "file://", with: "").expandPath
        ....
    }
}

I tried both patches, both work for me.

extension String {

    fileprivate var _expandPath: String? {
        guard hasPrefix("~/"), let home = ProcessInfo.processInfo.environment["HOME"] else { return nil }
        return self.replacingOccurrences(of: "~/", with: home + "/")
    }

    var expandPath: String {
        return _expandPath ?? self
    }
}

extension URL {

    var expandPath: URL {
        guard let expanded = absoluteString._expandPath, let url = URL(string: expanded) else { return self }
        return url
    }
}
ghost commented 6 years ago

Hi @jazzbox this looks great.

I think it might need to be done with the Files API though, which is currently a dependency for marathon.

lf-araujo commented 6 years ago

@jazzbox , does it actually support local libraries without the tilde? In my tests it does not seem to work and I couldn't find documentation about it.

jazzbox commented 6 years ago

@lf-araujo yes, it works. You have to specify the full path like here

import HTMLParser // marathon:/Users/box/Documents/dev/myprojects/Marathon/HTMLParser

And you should test that your library can be imported in a small demo SwiftPM project. If you have made a mistake (for example you forgot to version tag your library) Marathon gives total misleading and unhelpful error messages.

That and the fact, that marathon is and will be always lagging behind SwiftPM, I think that it is not worth the effort. I am using Marathon for proof-of-concept and prototyping now, but when I'm finished, I'm moving to a SwiftPM project (and version control of course).

ghost commented 6 years ago

@jazzbox not worth the effort? a little respect goes a long way. Not everyone deserves respect but I think John has earned it don’t you think?

Marathon might not be as reliable as main stream services but it’s free of charge.

you was using marathon in your release/production workflow? I don’t recommend using relatively unpopular and experimental open source ideas like this in production. Just use this for a bit of scripting here or there.

lf-araujo commented 6 years ago

That and the fact, that marathon is and will be always lagging behind SwiftPM, I think that it is not worth the effort. I am using Marathon for proof-of-concept and prototyping now, but when I'm finished, I'm moving to a SwiftPM project (and version control of course).

I mean, marathon makes small scripts very easy to test and run, that is what I use it for. Perhaps you are using it to a too large of a project, where SPM may perform better.

@rob-nash In Linux the directory address is not working is it perhaps related to the fact that marathon tries to use -C, which is now deprecated?

warning: '--chdir/-C' option is deprecated; use '--package-path' instead

Thanks.

edit: I had to remove the library before using it through the local path, which means this works perfectly fine on Linux

jazzbox commented 6 years ago

@rob-nash Did we had a conversation? And who are you that you can tell me how I have to structure my work?

And wow "experimental idea", that is really disrespectful. Maybe you should not implying something that you are doing yourself!

ghost commented 6 years ago

Hi @lf-araujo not entirely sure about linux 🙄 sorry

@jazzbox relax. you have done some good work here. if you want to use marathon in a production environment, then go ahead.

orta commented 6 years ago

@rob-nash - please take note that this repo has a code of conduct, and the sort of message ( which you rightly deleted ) to @jazzbox is definitely not welcome here. Please don't do it again.

ghost commented 6 years ago

Get off your high horse @orta