Skip to content

Commit

Permalink
Merge branch 'main' into michael/with-temp-file
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou authored May 15, 2024
2 parents 7e6c994 + ed34e15 commit 81786a4
Show file tree
Hide file tree
Showing 38 changed files with 2,205 additions and 1,028 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Format the codebase for the first time
b049841d5707d5bd87be516d8cda7be2a7585eae

# Reformatted test code
e437d63c40713e0645a4895bbe5a0fc565cd56db

28 changes: 16 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest]
java-version: [8, 17]
include:
- os: macos-latest
java-version: 17
- os: macos-latest
java-version: 11

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}

- name: Fetch millw launcher (Windows)
run: curl -Lo mill.bat "https://raw.githubusercontent.com/lefou/millw/main/millw.bat"
if: matrix.os == 'windows-latest'
Expand All @@ -38,11 +42,11 @@ jobs:
check-bin-compat:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 8
Expand All @@ -52,16 +56,16 @@ jobs:
check-formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 8
java-version: 17

- run: ./mill -i -k __.checkFormat
- run: ./mill -i mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources

publish-sonatype:
if: github.repository == 'com-lihaoyi/os-lib' && contains(github.ref, 'refs/tags/')
Expand All @@ -76,8 +80,8 @@ jobs:
LC_MESSAGES: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 8
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dependency-graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: coursier/cache-action@v6

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ target/
.project
.cache
.sbtserver
.scala-build/
.bsp/
project/.sbtserver
tags
nohup.out
Expand Down
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.12
0.11.7-29-f2e220
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.5.8"
version = "3.8.1"

align.preset = none
align.openParenCallSite = false
Expand Down
113 changes: 105 additions & 8 deletions Readme.adoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
= OS-Lib
:version: 0.9.1
:toc-placement: preamble
:toclevels: 3
:toc:
:version: 0.10.0
:link-geny: https://github.com/com-lihaoyi/geny
:link-oslib: https://github.com/com-lihaoyi/os-lib
:link-oslib-gitter: https://gitter.im/lihaoyi/os-lib
Expand All @@ -14,6 +11,7 @@
image:{link-oslib}/actions/workflows/build.yml/badge.svg[Build Status,link={link-oslib}/actions]
image:https://badges.gitter.im/Join%20Chat.svg[Gitter Chat,link={link-oslib-gitter}]
image:https://img.shields.io/badge/patreon-sponsor-ff69b4.svg[Patreon,link=https://www.patreon.com/lihaoyi]
image:https://javadoc.io/badge2/com.lihaoyi/os-lib_3/scaladoc.svg[API Docs (Scala 3),link=https://javadoc.io/doc/com.lihaoyi/os-lib_3]

[source,scala]
----
Expand Down Expand Up @@ -86,6 +84,8 @@ ivy"com.lihaoyi::os-lib:{version}"
"com.lihaoyi" %% "os-lib" % "{version}"
----

https://javadoc.io/doc/com.lihaoyi/os-lib_3[API Documentation (Scala 3)]

== Cookbook

Most operation in OS-Lib take place on <<os-path>>s, which are
Expand Down Expand Up @@ -1128,7 +1128,7 @@ os.readLink(wd / "misc" / "broken-abs-symlink") ==> os.root / "doesnt" / "exist"
----

Note that symbolic links can be either absolute ``os.Path``s or relative
``os.RelPath``s, represented by `os.FilePath`. You can also use `os.readLink.all`
``os.RelPath``s, represented by `os.FilePath`. You can also use `os.readLink.absolute`
to automatically resolve relative symbolic links to their absolute destination:

[source,scala]
Expand Down Expand Up @@ -1483,7 +1483,7 @@ the subprocess via `os.SubProcess#stdin`, and if used on its stdout it lets the
parent process read from the subprocess via `os.SubProcess#stdout`
and `os.SubProcess#stderr`.
* `os.Inherit`: inherits the stream from the parent process. This lets the
subprocess read directly from the paren process's standard input or write
subprocess read directly from the parent process's standard input or write
directly to the parent process's standard output or error
* `os.Path`: connects the subprocess's stream to the given filesystem
path, reading its standard input from a file or writing its standard
Expand Down Expand Up @@ -1691,6 +1691,48 @@ val sha = os.proc("shasum", "-a", "256").spawn(stdin = gzip.stdout)
sha.stdout.trim ==> "acc142175fa520a1cb2be5b97cbbe9bea092e8bba3fe2e95afa645615908229e -"
----

== Spawning Pipelines of Subprocesses

After constructing a subprocess with `os.proc`, you can use the `pipeTo` method
to pipe its output to another subprocess:

[source,scala]
----
val wc = os.proc("ls", "-l")
.pipeTo(os.proc("wc", "-l"))
.call()
.out.text()
----

This is equivalent to the shell command `ls -l | wc -l`. You can chain together
as many subprocesses as you like. Note that by using this API you can utilize
the broken pipe behaviour of Unix systems. For example, you can take 10 first elements
of output from the `yes` command, and after the `head` command terminates, the `yes`
command will be terminated as well:

[source,scala]
----
val yes10 = os.proc("yes")
.pipeTo(os.proc("head", "-n", "10"))
.call()
.out.text()
----

This feature is implemented inside the library and will terminate any process reading the
stdin of other process in pipeline on every IO error. This behavior can be disabled via the
`handleBrokenPipe` flag on `call` and `spawn` methods. Note that Windows does not support
broken pipe behaviour, so a command like`yes` would run forever. `handleBrokenPipe` is set
to false by default on Windows.

Both `call` and `spawn` correspond in their behavior to their counterparts in the `os.proc`,
but `spawn` returns the `os.ProcessPipeline` instance instead. It offers the same
`API` as `SubProcess`, but will operate on the set of processes instead of a single one.

`Pipefail` is enabled by default, so if any of the processes in the pipeline fails, the whole
pipeline will have a non-zero exit code. This behavior can be disabled via the `pipefail` flag
on `call` and `spawn` methods. Note that the pipefail does not kill the processes in the pipeline,
it just sets the exit code of the pipeline to the exit code of the failed process.

=== Watching for Changes

==== `os.watch.watch`
Expand Down Expand Up @@ -1752,8 +1794,6 @@ paths changed: /Users/lihaoyi/Github/Ammonite/out/i am,/Users/lihaoyi/Github/Amm
paths changed: /Users/lihaoyi/Github/Ammonite/out/version/log,/Users/lihaoyi/Github/Ammonite/out/version/meta.json,/Users/lihaoyi/Github/Ammonite/out/version
----

`watch` currently only supports Linux and Mac-OSX, and not Windows.

== Data Types

=== `os.Path`
Expand Down Expand Up @@ -2059,6 +2099,38 @@ Python, ...) do. Even in cases where it's uncertain, e.g. you're taking user
input as a String, you have to either handle both possibilities with BasePath or
explicitly choose to convert relative paths to absolute using some base.

==== Roots and filesystems

If you are using a system that supports different roots of paths, e.g. Windows,
you can use the argument of `os.root` to specify which root you want to use.
If not specified, the default root will be used (usually, C on Windows, / on Unix).

[source,scala]
----
val root = os.root('C:\') / "Users" / "me"
assert(root == os.Path("C:\Users\me"))
----

Additionally, custom filesystems can be specified by passing a `FileSystem` to
`os.root`. This allows you to use OS-Lib with non-standard filesystems, such as
jar filesystems or in-memory filesystems.

[source,scala]
----
val uri = new URI("jar", Paths.get("foo.jar").toURI().toString, null);
val env = new HashMap[String, String]();
env.put("create", "true");
val fs = FileSystems.newFileSystem(uri, env);
val path = os.root("/", fs) / "dir"
----

Note that the jar file system operations suchs as writing to a file are supported
only on JVM 11+. Depending on the filesystem, some operations may not be supported -
for example, running an `os.proc` with pwd in a jar file won't work. You may also
meet limitations imposed by the implementations - in jar file system, the files are
created only after the file system is closed. Until that, the ones created in your
program are kept in memory.

==== `os.ResourcePath`

In addition to manipulating paths on the filesystem, you can also manipulate
Expand Down Expand Up @@ -2186,6 +2258,31 @@ string, int or set representations of the `os.PermSet` via:

== Changelog

[#0-10-0]
=== 0.10.0

* Support for Scala-Native 0.5.0
* Dropped support for Scala 2.11.x
* Minimum version of Scala 3 increased to 3.3.1


[#0-9-3]
=== 0.9.3 - 2024-01-01

* Fix `os.watch` on Windows (#236)
* Fix propagateEnv = false to not propagate env (#238)
* Make os.home a def (#239)

=== 0.9.2 - 2023-11-05

* Added new convenience API to create pipes between processes with `.pipeTo`
* Fixed issue with leading `..` / `os.up` in path segments created from a `Seq`
* Fixed Windows-specific issues with relative paths with leading (back)slashes
* Removed some internal use of deprecated API
* ScalaDoc now maps some external references to their online sites
* Dependency updates: sourcecode 0.3.1
* Tooling updates: acyclic 0.3.9, Mill 0.11.5, mill-mima 0.0.24, mill-vcs-version 0.4.0, scalafmt 3.7.15

=== 0.9.1 - 2023-03-07

* Refined return types when constructing paths with `/` and get rid of long `ThisType#ThisType` cascades.
Expand Down
Loading

0 comments on commit 81786a4

Please sign in to comment.